11from pathlib import Path
22
3+ import packaging .version
34import yaml
45from copier .main import run_auto
56
1213REPO_ID = 149
1314
1415
16+ def read_and_parse_precommit_rev (tmp_path : Path , repo : str ):
17+ # Attempt to find the rev of a pre-commit repo.
18+ # If it found, return the actual version, if it's not return 0.0.0.
19+ config = yaml .safe_load ((tmp_path / ".pre-commit-config.yaml" ).read_text ())
20+ entry = next (
21+ filter (lambda r : r .get ("repo" , "" ) == repo , config .get ("repos" , [])), {}
22+ )
23+ return packaging .version .parse (entry .get ("rev" , "0.0.0" ))
24+
25+
1526def test_bootstrap (tmp_path : Path , odoo_version : float , cloned_template : Path ):
1627 """Test that a project is properly bootstrapped."""
1728 data = {
@@ -31,12 +42,20 @@ def test_bootstrap(tmp_path: Path, odoo_version: float, cloned_template: Path):
3142 pylintrc_mandatory = (tmp_path / ".pylintrc-mandatory" ).read_text ()
3243 assert "disable=all\n " in pylintrc_mandatory
3344 assert "enable=" in pylintrc_mandatory
34- assert f"valid_odoo_versions={ odoo_version } " in pylintrc_mandatory
45+ pylint_odoo_version = read_and_parse_precommit_rev (
46+ tmp_path , "https://github.com/OCA/pylint-odoo"
47+ )
48+ valid_odoo_versions = "valid_odoo_versions"
49+ if pylint_odoo_version >= packaging .version .parse ("v8.0.5" ):
50+ # versions of pylint-odoo >= 8.0.5 use dashes for keys, rather than
51+ # underscores
52+ valid_odoo_versions = "valid-odoo-versions"
53+ assert f"{ valid_odoo_versions } ={ odoo_version } " in pylintrc_mandatory
3554 assert SOME_PYLINT_OPTIONAL_CHECK not in pylintrc_mandatory
3655 pylintrc_optional = (tmp_path / ".pylintrc" ).read_text ()
3756 assert "disable=all\n " in pylintrc_optional
3857 assert "# This .pylintrc contains" in pylintrc_optional
39- assert f"valid_odoo_versions={ odoo_version } " in pylintrc_optional
58+ assert f"{ valid_odoo_versions } ={ odoo_version } " in pylintrc_optional
4059 assert SOME_PYLINT_OPTIONAL_CHECK in pylintrc_optional
4160 flake8 = (tmp_path / ".flake8" ).read_text ()
4261 assert "[flake8]" in flake8
0 commit comments