From 5baba79ce467810b3b5ac447057beabf1f9c6e99 Mon Sep 17 00:00:00 2001 From: antonag32 Date: Thu, 1 Jun 2023 17:58:23 -0600 Subject: [PATCH] [REF] freeze test repos 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. --- tests/test_main.py | 52 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index c45566f3..60ac9e4f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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): @@ -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", @@ -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 @@ -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) @@ -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: @@ -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}) @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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"]), @@ -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) @@ -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) @@ -383,7 +401,9 @@ 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, extra_params=["--disable=all", "--enable=odoolint"], verbose=True + ) pylint_res.out.seek(0) all_check_errors_merged = defaultdict(list) for line in pylint_res.out: