Skip to content

Commit

Permalink
[REF] freeze test repos
Browse files Browse the repository at this point in the history
Previously, faulty code which generated messages was distributed throught
multiple repositories. Tests based themselves on the total amount
of expected messages contained within the repositories.

This is not sustainable because adding new checks oftentime triggers
unintended messages on all repos, breaking tests and costing developer time.

This commit freezes test repos to keep backwards compatibility, however
all new checks must implement their own separate test sources, this
will speed up development and help organization.

Changes are as minimal as possible and nothing is broken, build-readme
continues to work since it works over all test resources and not
just the frozen ones.
  • Loading branch information
antonag32 committed Jun 2, 2023
1 parent c1335a0 commit 169685b
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
"website-manifest-key-not-valid-uri": 1,
}

# These form part of the original test repos. New messages should each have separate test sources, don't use these
FROZEN_TEST_REPOS = [
"broken_module",
"broken_module2",
"broken_module3",
"eleven_module",
"no_odoo_module",
"pylint_deprecated_modules",
"test_module",
"twelve_module",
"womanifest_module",
]
FROZEN_MESSAGES = ",".join(EXPECTED_ERRORS.keys())


class MainTest(unittest.TestCase):
def setUp(self):
Expand All @@ -75,11 +89,15 @@ def setUp(self):
"--msg-template={path}:{line} {msg} - [{symbol}]",
"--rcfile=%s" % os.devnull,
]
path_modules = os.path.join(
self.root_path_modules = os.path.join(
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "testing", "resources", "test_repo"
)
# Similar to pre-commit way
self.paths_modules = glob(os.path.join(path_modules, "**", "*.py"), recursive=True)
self.frozen_paths_modules = []
for path in FROZEN_TEST_REPOS:
self.frozen_paths_modules += glob(os.path.join(self.root_path_modules, path, "**", "*.py"), recursive=True)

self.test_sources = glob(os.path.join(self.root_path_modules, "**", "*.py"), recursive=True)
self.odoo_namespace_addons_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
"testing",
Expand All @@ -89,7 +107,7 @@ def setUp(self):
)
self.default_extra_params = [
"--disable=all",
"--enable=odoolint,pointless-statement,trailing-newlines",
f"--enable={FROZEN_MESSAGES},pointless-statement,trailing-newlines",
]
self.sys_path_origin = list(sys.path)
self.maxDiff = None
Expand Down Expand Up @@ -133,7 +151,7 @@ def test_10_path_dont_exist(self):

def test_20_expected_errors(self):
"""Expected vs found errors"""
pylint_res = self.run_pylint(self.paths_modules, verbose=True)
pylint_res = self.run_pylint(self.frozen_paths_modules, verbose=True)
real_errors = pylint_res.linter.stats.by_msg
self.assertEqual(self.expected_errors, real_errors)

Expand All @@ -149,7 +167,7 @@ def test_25_checks_excluding_by_odoo_version(self):
"translation-unsupported-format",
}
self.default_extra_params += ["--valid-odoo-versions=13.0"]
pylint_res = self.run_pylint(self.paths_modules)
pylint_res = self.run_pylint(self.frozen_paths_modules)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = self.expected_errors.copy()
for excluded_msg in excluded_msgs:
Expand All @@ -160,7 +178,7 @@ def test_25_checks_excluding_by_odoo_version(self):
def test_35_checks_emiting_by_odoo_version(self):
"""All odoolint errors vs found but see if were not excluded for valid odoo version"""
self.default_extra_params += ["--valid-odoo-versions=14.0"]
pylint_res = self.run_pylint(self.paths_modules)
pylint_res = self.run_pylint(self.frozen_paths_modules)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = self.expected_errors.copy()
expected_errors.update({"manifest-version-format": 6})
Expand All @@ -179,7 +197,7 @@ def test_85_valid_odoo_version_format(self):
"--disable=all",
"--enable=manifest-version-format",
]
pylint_res = self.run_pylint(self.paths_modules, extra_params)
pylint_res = self.run_pylint(self.frozen_paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = {
"manifest-version-format": 6,
Expand All @@ -188,7 +206,7 @@ def test_85_valid_odoo_version_format(self):

# Now for version 11.0
extra_params[0] = r'--manifest-version-format="11\.0\.\d+\.\d+.\d+$"'
pylint_res = self.run_pylint(self.paths_modules, extra_params)
pylint_res = self.run_pylint(self.frozen_paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = {
"manifest-version-format": 5,
Expand All @@ -203,7 +221,7 @@ def test_90_valid_odoo_versions(self):
"--disable=all",
"--enable=manifest-version-format",
]
pylint_res = self.run_pylint(self.paths_modules, extra_params)
pylint_res = self.run_pylint(self.frozen_paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = {
"manifest-version-format": 6,
Expand All @@ -212,7 +230,7 @@ def test_90_valid_odoo_versions(self):

# Now for version 11.0
extra_params[0] = "--valid-odoo-versions=11.0"
pylint_res = self.run_pylint(self.paths_modules, extra_params)
pylint_res = self.run_pylint(self.frozen_paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = {
"manifest-version-format": 5,
Expand All @@ -229,7 +247,7 @@ def test_110_manifest_required_authors(self):
"--disable=all",
"--enable=manifest-required-author",
]
pylint_res = self.run_pylint(self.paths_modules, extra_params)
pylint_res = self.run_pylint(self.frozen_paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = {
"manifest-required-author": 4,
Expand All @@ -238,14 +256,14 @@ def test_110_manifest_required_authors(self):

# Then, run it using multiple authors
extra_params[0] = "--manifest-required-authors=Vauxoo,Other"
pylint_res = self.run_pylint(self.paths_modules, extra_params)
pylint_res = self.run_pylint(self.frozen_paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors["manifest-required-author"] = 3
self.assertDictEqual(real_errors, expected_errors)

# Testing deprecated attribute
extra_params[0] = "--manifest-required-author=" "Odoo Community Association (OCA)"
pylint_res = self.run_pylint(self.paths_modules, extra_params)
pylint_res = self.run_pylint(self.frozen_paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors_deprecated = {
"manifest-required-author": (EXPECTED_ERRORS["manifest-required-author"]),
Expand Down Expand Up @@ -348,7 +366,7 @@ def test_150_check_only_enabled_one_check(self):
disable = "--disable=all"
for expected_error_name, expected_error_value in EXPECTED_ERRORS.items():
enable = "--enable=%s" % expected_error_name
pylint_res = self.run_pylint(self.paths_modules, [disable, enable])
pylint_res = self.run_pylint(self.frozen_paths_modules, [disable, enable])
real_errors = pylint_res.linter.stats.by_msg
expected_errors = {expected_error_name: expected_error_value}
self.assertDictEqual(real_errors, expected_errors)
Expand All @@ -358,7 +376,7 @@ def test_160_check_only_disabled_one_check(self):
for disable_error in EXPECTED_ERRORS:
expected_errors = self.expected_errors.copy()
enable = "--disable=%s" % disable_error
pylint_res = self.run_pylint(self.paths_modules, self.default_extra_params + [enable])
pylint_res = self.run_pylint(self.frozen_paths_modules, self.default_extra_params + [enable])
real_errors = pylint_res.linter.stats.by_msg
expected_errors.pop(disable_error)
self.assertDictEqual(real_errors, expected_errors)
Expand All @@ -383,7 +401,7 @@ def test_build_docstring(self):
"[//]: # (start-checks)", "[//]: # (end-checks)", messages_content, readme_content
)

pylint_res = self.run_pylint(self.paths_modules, verbose=True)
pylint_res = self.run_pylint(self.test_sources, verbose=True)
pylint_res.out.seek(0)
all_check_errors_merged = defaultdict(list)
for line in pylint_res.out:
Expand Down

0 comments on commit 169685b

Please sign in to comment.