Skip to content

Commit

Permalink
[REF] tests: Detecting duplicated lines occurrences (#504)
Browse files Browse the repository at this point in the history
* Add a missing clean for consider-merging-classes-inherited check
  • Loading branch information
moylop260 authored Dec 19, 2024
1 parent 207cd9e commit 789d027
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pylint_odoo/checkers/odoo_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ def __init__(self, linter: PyLinter):

def close(self):
"""Final process get all cached values and add messages"""
self.linter.config.deprecated_odoo_model_methods = set()
for (_manifest_path, odoo_class_inherit), inh_nodes in self._odoo_inherit_items.items():
# Skip _inherit='other.model' _name='model.name' because is valid
inh_nodes = {
Expand All @@ -597,6 +596,7 @@ def close(self):
self.add_message(
"consider-merging-classes-inherited", node=first_node, args=(odoo_class_inherit, ", ".join(path_nodes))
)
self._odoo_inherit_items = defaultdict(set)

def visit_module(self, node):
"""Initizalize the cache to save the original library name
Expand Down
9 changes: 7 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import unittest
import warnings
from collections import defaultdict
from collections import Counter, defaultdict
from glob import glob
from io import StringIO
from tempfile import NamedTemporaryFile
Expand Down Expand Up @@ -426,13 +426,18 @@ def test_175_prohibited_method_override(self):

def test_180_jobs(self):
"""Using jobs could raise new errors"""
self.default_extra_params += ["--jobs=4"]
self.default_extra_params += ["--jobs=2"]
pylint_res = self.run_pylint(self.paths_modules, verbose=True)
# pylint_res.linter.stats.by_msg has a issue generating the stats wrong with --jobs
res = self._get_messages_from_output(pylint_res)
real_errors = {key: len(set(lines)) for key, lines in res.items()}
self.assertEqual(self.expected_errors, real_errors)

for key, lines in res.items():
lines_counter = Counter(tuple(lines))
for line, count in lines_counter.items():
self.assertLessEqual(count, 2, "%s duplicated more than 2 times. Line %s" % (key, line))

@staticmethod
def re_replace(sub_start, sub_end, substitution, content):
re_sub = re.compile(rf"^{re.escape(sub_start)}$.*^{re.escape(sub_end)}$", re.M | re.S)
Expand Down

0 comments on commit 789d027

Please sign in to comment.