Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: [FIX] consider-merging-classes-inherited: Fix corner case using jobs #512

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Checks valid only for odoo <= 13.0

- https://github.com/OCA/pylint-odoo/blob/v9.3.2/testing/resources/test_repo/broken_module/models/model_inhe2.py#L11 Consider merging classes inherited to "res.company" from testing/resources/test_repo/broken_module/models/model_inhe1.py:8:4, testing/resources/test_repo/broken_module/models/model_inhe2.py:7:4.
- https://github.com/OCA/pylint-odoo/blob/v9.3.2/testing/resources/test_repo/broken_module/models/model_inhe2.py#L19 Consider merging classes inherited to "res.partner" from testing/resources/test_repo/broken_module/models/model_inhe2.py:15:4.
- https://github.com/OCA/pylint-odoo/blob/v9.3.2/testing/resources/test_repo/broken_module/models/model_inhe2.py#L56 Consider merging classes inherited to "stock.warehouse.orderpoint" from testing/resources/test_repo/broken_module/models/model_inhe1.py:19:4.

* context-overridden

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ def method(self):

class TestModel2(models.Model):
_inherit = 'model.no.duplicated'


class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ def method_1(self):
def method_2(self):
_inherit = 'not-class-attribute'
return _inherit


class Orderpoint(models.Model):
_inherit = "stock.warehouse.orderpoint"
39 changes: 37 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"attribute-deprecated": 3,
"attribute-string-redundant": 31,
"bad-builtin-groupby": 2,
"consider-merging-classes-inherited": 2,
"consider-merging-classes-inherited": 3,
"context-overridden": 3,
"development-status-allowed": 1,
"except-pass": 3,
Expand Down Expand Up @@ -382,6 +382,23 @@ def test_150_check_only_enabled_one_check(self):
expected_errors = {expected_error_name: expected_error_value}
self.assertDictEqual(real_errors, expected_errors)

def test_155_check_only_enabled_one_check_jobs(self):
"""Checking -d all -e ONLY-ONE-CHECK --jobs=0"""
# TODO: Check why using jobs it is slower than removing jobs
# Profiler https://gist.github.com/moylop260/1627cc4585ff790edebcb93bd68bdc08
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, "--jobs=0"])
# pylint_res.linter.stats.by_msg is duplicating the counter 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()}
expected_errors = {expected_error_name: expected_error_value}
if expected_error_name == "consider-merging-classes-inherited":
# TODO: Remove this section after fix https://github.com/OCA/pylint-odoo/pull/512
expected_errors[expected_error_name] -= 1
self.assertDictEqual(real_errors, expected_errors)

def test_160_check_only_disabled_one_check(self):
"""Checking -d all -e odoolint -d ONLY-ONE-CHECK"""
for disable_error in EXPECTED_ERRORS:
Expand All @@ -392,6 +409,24 @@ def test_160_check_only_disabled_one_check(self):
expected_errors.pop(disable_error)
self.assertDictEqual(real_errors, expected_errors)

def test_165_check_only_disabled_one_check_jobs(self):
"""Checking -d all -e odoolint -d ONLY-ONE-CHECK --jobs=0"""
# TODO: Check why using jobs it is slower than removing jobs
# Profiler https://gist.github.com/moylop260/1627cc4585ff790edebcb93bd68bdc08
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, "--jobs=0"])
# pylint_res.linter.stats.by_msg is duplicating the counter 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()}

# TODO: Remove this section after fix https://github.com/OCA/pylint-odoo/pull/512
expected_errors["consider-merging-classes-inherited"] -= 1

expected_errors.pop(disable_error)
self.assertDictEqual(real_errors, expected_errors)

def test_165_no_raises_unlink(self):
extra_params = ["--disable=all", "--enable=no-raise-unlink"]
test_repo = os.path.join(self.root_path_modules, "test_module")
Expand Down Expand Up @@ -451,7 +486,7 @@ def test_180_jobs(self):
"""Using jobs could raise new errors"""
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
# pylint_res.linter.stats.by_msg is duplicating the counter 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)
Expand Down
Loading