diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 608eee5..c976863 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -34,7 +34,7 @@ jobs: strategy: fail-fast: false matrix: - python: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python: ['3.8', '3.9', '3.10', '3.11'] os: [ubuntu-latest, windows-latest, macos-latest] tox_env: ['py'] include: diff --git a/setup.cfg b/setup.cfg index 0bc97ee..8208128 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,6 @@ [bdist_wheel] universal = 1 -[flake8] -max-line-length = 140 -exclude = .tox,.eggs,ci/templates,build,dist,resources - [tool:isort] force_single_line = True line_length = 120 diff --git a/setup.py b/setup.py index 1f5e11b..137dba8 100755 --- a/setup.py +++ b/setup.py @@ -63,7 +63,6 @@ def read(*names, **kwargs): "Operating System :: Microsoft :: Windows", "Operating System :: MacOS", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -84,7 +83,7 @@ def read(*names, **kwargs): keywords=[ # eg: 'keyword1', 'keyword2', 'keyword3', ], - python_requires=">=3.7", + python_requires=">=3.8", install_requires=generate_dependencies(), extras_require={ # eg: diff --git a/src/pre_commit_vauxoo/cfg/.flake8 b/src/pre_commit_vauxoo/cfg/.flake8 index bd8cdb1..5df5fa3 100644 --- a/src/pre_commit_vauxoo/cfg/.flake8 +++ b/src/pre_commit_vauxoo/cfg/.flake8 @@ -5,10 +5,10 @@ # W503 changed by W504 and OCA prefers allow both # F401 is legal in odoo __init__.py files # E203 (whitespace before ':') is handled by black and it doesn't consider black syntax like: +# E741 do not use variables named ‘l’, ‘O’, or ‘I’ # chunk = records[index : index + chunk_size] -ignore = E123,E133,E203,E226,E241,E242,F811,F601,W503,W504 +ignore = E123,E133,E203,E226,E241,E242,E501,E741,F811,F601,W503,W504 max-line-length = 119 per-file-ignores= __init__.py:F401 -exclude = __unported__,__init__.py jobs = 0 diff --git a/src/pre_commit_vauxoo/cfg/.flake8-optional b/src/pre_commit_vauxoo/cfg/.flake8-optional index 66a6253..39eab33 100644 --- a/src/pre_commit_vauxoo/cfg/.flake8-optional +++ b/src/pre_commit_vauxoo/cfg/.flake8-optional @@ -4,17 +4,20 @@ jobs = 0 # B = bugbear # B9 = bugbear opinionated (incl line length +10% tolerance) select = C,E,F,W,B,B9 -ignore = - E203 # whitespace before ':' (black behaviour) - E501 # E501: flake8 line length (covered by bugbear B950) - W503 # W503: line break before binary operator (black behaviour) - W504 # W504: line break after binary operator (black behaviour?) - E241 # E241: E241 multiple spaces after ',' (Better autofixing) - B023 # B023: Function definition does not bind loop variable 'item'. (Odoo needs it [self.filtered(lambda l: l.item_id == item) for item in items]) - E226 # E226: missing whitespace around arithmetic operator (Better autofixing) - B904 # B904: Within an `except` clause, raise exceptions with `raise (It is valid for us) - E123 # E123: closing bracket does not match indentation of opening bracket's line (Better autofixing) - E275 # E275: missing whitespace after keyword (Better autofixing) +# E203 whitespace before ':' (black behaviour) +# E501: flake8 line length (covered by bugbear B950) +# W503: line break before binary operator (black behaviour) +# W504: line break after binary operator (black behaviour?) +# E241: E241 multiple spaces after ',' (Better autofixing) +# B023: Function definition does not bind loop variable 'item'. (Odoo needs it [self.filtered(lambda l: l.item_id == item) for item in items]) +# E226: missing whitespace around arithmetic operator (Better autofixing) +# B904: Within an `except` clause, raise exceptions with `raise (It is valid for us) +# E123: closing bracket does not match indentation of opening bracket's line (Better autofixing) +# E275: missing whitespace after keyword (Better autofixing) +# B905: zip(strict=True) only works in python >= 3.10 +# B907: We sometimes quote for stylistic purposes # F401: imported but unused (like __init__ already works) +ignore = E203,E501,W503,W504,E241,B023,E226,B904,B905,B907,E123,E275 per-file-ignores = __init__.py:F401 + __manifest__.py:B018 diff --git a/src/pre_commit_vauxoo/cfg/.isort.cfg b/src/pre_commit_vauxoo/cfg/.isort.cfg index 0ec187e..c9ce1b4 100644 --- a/src/pre_commit_vauxoo/cfg/.isort.cfg +++ b/src/pre_commit_vauxoo/cfg/.isort.cfg @@ -11,3 +11,4 @@ known_odoo_addons=odoo.addons sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER default_section=THIRDPARTY ensure_newline_before_comments = True +skip_glob=**/__init__.py diff --git a/src/pre_commit_vauxoo/cfg/.pre-commit-config-autofix.yaml b/src/pre_commit_vauxoo/cfg/.pre-commit-config-autofix.yaml index c1ef982..1e3c34c 100644 --- a/src/pre_commit_vauxoo/cfg/.pre-commit-config-autofix.yaml +++ b/src/pre_commit_vauxoo/cfg/.pre-commit-config-autofix.yaml @@ -29,12 +29,12 @@ default_language_version: python: python3 node: "14.13.0" repos: - - repo: https://github.com/psf/black + - repo: https://github.com/psf/black-pre-commit-mirror.git rev: 22.10.0 hooks: - id: black - repo: https://github.com/myint/autoflake - rev: v1.7.7 + rev: v2.2.1 hooks: - id: autoflake args: @@ -45,7 +45,7 @@ repos: - --remove-duplicate-keys - --remove-unused-variables - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.7.1 + rev: v3.0.3 hooks: - id: prettier name: prettier (with plugin-xml) @@ -56,7 +56,7 @@ repos: - --plugin=@prettier/plugin-xml files: \.(js|xml)$ - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.5.0 hooks: - id: trailing-whitespace # exclude autogenerated files @@ -69,25 +69,21 @@ repos: - id: mixed-line-ending args: ["--fix=lf"] - repo: https://github.com/asottile/pyupgrade - rev: v3.2.2 + rev: v3.15.0 hooks: - id: pyupgrade args: ["--keep-percent-format"] - repo: https://github.com/PyCQA/isort - rev: 5.11.5 + rev: 5.12.0 hooks: - id: isort - name: isort (except __init__.py) - args: - - --settings=. - exclude: /__init__\.py$ - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.3.1 + rev: v1.5.4 hooks: - id: remove-tabs exclude: (Makefile|debian/rules|.gitmodules|\.po|\.pot)(\.in)?$ - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.27.0 + rev: v8.51.0 hooks: - id: eslint name: javascript lints diff --git a/src/pre_commit_vauxoo/cfg/.pre-commit-config-optional.yaml b/src/pre_commit_vauxoo/cfg/.pre-commit-config-optional.yaml index 748e5c3..8e2163e 100644 --- a/src/pre_commit_vauxoo/cfg/.pre-commit-config-optional.yaml +++ b/src/pre_commit_vauxoo/cfg/.pre-commit-config-optional.yaml @@ -29,7 +29,7 @@ default_language_version: node: "14.13.0" repos: - repo: https://github.com/OCA/pylint-odoo - rev: v8.0.21 + rev: v9.0.4 hooks: - id: pylint_odoo name: pylint optional checks @@ -43,16 +43,16 @@ repos: - id: oca-checks-odoo-module - id: oca-checks-po - repo: https://github.com/PyCQA/doc8 - rev: v1.0.0 + rev: v1.1.1 hooks: - id: doc8 name: RST lint - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + rev: 6.1.0 hooks: - id: flake8 name: flake8 + bugbear optional checks - additional_dependencies: ["flake8-bugbear==22.7.1"] + additional_dependencies: ["flake8-bugbear==23.9.16"] args: - --config=.flake8-optional - repo: https://github.com/PyCQA/bandit diff --git a/src/pre_commit_vauxoo/cfg/.pre-commit-config.yaml b/src/pre_commit_vauxoo/cfg/.pre-commit-config.yaml index 1202f4d..026d002 100644 --- a/src/pre_commit_vauxoo/cfg/.pre-commit-config.yaml +++ b/src/pre_commit_vauxoo/cfg/.pre-commit-config.yaml @@ -29,12 +29,12 @@ default_language_version: node: "14.13.0" repos: - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 6.1.0 hooks: - id: flake8 name: flake8 mandatory checks - repo: https://github.com/OCA/pylint-odoo - rev: v8.0.21 + rev: v9.0.0 hooks: - id: pylint_odoo name: pylint mandatory checks @@ -42,7 +42,7 @@ repos: # External scripts - --disable=R0000 - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.13.0 + rev: v8.51.0 hooks: - id: eslint name: javascript mandatory checks @@ -61,7 +61,7 @@ repos: types: [jinja] files: ^deactivate\.jinja$ - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.5.0 hooks: - id: debug-statements - id: check-case-conflict diff --git a/src/pre_commit_vauxoo/cfg/.pylintrc b/src/pre_commit_vauxoo/cfg/.pylintrc index a101eb6..67f0880 100644 --- a/src/pre_commit_vauxoo/cfg/.pylintrc +++ b/src/pre_commit_vauxoo/cfg/.pylintrc @@ -23,12 +23,9 @@ disable=abstract-method, assignment-from-no-return, assignment-from-none, attribute-defined-outside-init, - bad-continuation, bad-docstring-quotes, - bad-option-value, - bad-whitespace, - basestring-builtin, - broad-except, + broad-exception-caught, + broad-exception-raised, c-extension-no-member, cell-var-from-loop, consider-using-dict-items, @@ -37,8 +34,6 @@ disable=abstract-method, consider-using-generator, cyclic-import, deprecated-pragma, - dict-keys-not-iterating, - dict-values-not-iterating, deprecated-method, docstring-first-line-empty, duplicate-code, @@ -51,23 +46,16 @@ disable=abstract-method, keyword-arg-before-vararg, line-too-long, locally-disabled, - long-builtin, - map-builtin-not-iterating, - missing-docstring, - missing-super-argument, - no-absolute-import, - no-init, + missing-module-docstring, + missing-class-docstring, + missing-function-docstring, no-member, no-name-in-module, - no-self-use, no-value-for-parameter, - nonstandard-exception, - old-division, odoo-exception-warning, protected-access, raise-missing-from, redundant-u-string-prefix, - round-builtin, self-cls-assignment, suppressed-message, too-complex, @@ -80,50 +68,32 @@ disable=abstract-method, try-except-raise, unexpected-keyword-arg, ungrouped-imports, - unicode-builtin, unspecified-encoding, unsubscriptable-object, unsupported-binary-operation, unused-argument, unused-private-member, + use-dict-literal, + use-implicit-booleaness-not-comparison-to-string, + use-implicit-booleaness-not-comparison-to-zero, + useless-option-value, + unknown-option-value, use-symbolic-message-instead, - useless-super-delegation, useless-suppression, wrong-import-order, wrong-import-position, - # odoolint disable all to be enabled from optional # Comment to enable - api-one-deprecated, - api-one-multi-together, attribute-deprecated, attribute-string-redundant, bad-builtin-groupby, - character-not-valid-in-resource-link, - class-camelcase, - consider-add-field-help, consider-merging-classes-inherited, context-overridden, - copy-wo-api-one, - create-user-wo-reset-password, - # dangerous-filter-wo-user, - # dangerous-qweb-replace-wo-priority, - # dangerous-view-replace-wo-priority, - # deprecated-data-xml-node, - # deprecated-openerp-xml-node, development-status-allowed, deprecated-odoo-model-method, - # duplicate-id-csv, - duplicate-po-message-definition, - duplicate-xml-fields, - # duplicate-xml-record-id, - eval-referenced, except-pass, external-request-timeout, - file-not-used, - incoherent-interpreter-exec-perm, # invalid-commit, - javascript-lint, license-allowed, no-wizard-in-models, manifest-author-string, @@ -137,25 +107,13 @@ disable=abstract-method, method-inverse, method-required-super, method-search, - missing-import-error, - missing-manifest-dependency, - missing-newline-extrafiles, missing-readme, missing-return, odoo-addons-relative-import, - old-api7-method-defined, - openerp-exception-warning, - po-lint, - po-msgstr-variables, - po-syntax-error, - prefer-other-formatting, print-used, - redundant-modulename-xml, renamed-field-parameter, resource-not-exist, - rst-syntax-error, sql-injection, - str-format-used, # test-folder-imported, translation-contains-variable, translation-field, @@ -165,25 +123,16 @@ disable=abstract-method, translation-format-interpolation, translation-format-truncated, translation-fstring-interpolation, - translation-not-lazy, translation-too-few-args, translation-too-many-args, translation-unsupported-format, - unnecessary-utf8-coding-comment, use-vim-comment, - website-manifest-key-not-valid-uri, - wrong-tabs-instead-of-spaces, - xml-attribute-translatable, - xml-deprecated-qweb-directive, - xml-deprecated-tree-attribute, - # xml-syntax-error, + website-manifest-key-not-valid-uri # odoolint disabled because this checks is available just in changed modules in PR conf. # import-error Because odoo use incompatible sys-modules https://bitbucket.org/logilab/pylint/issues/616/modules-renamed-with-sysmodules-are-unable -# nonstandard-exception disabled because we use follow custom exceptions: https://github.com/OCA/maintainer-tools/blob/master/template/module/exceptions.py#L8 # wrong-import-order: Disabled here but enabled in pr-conf # consider-merging-classes-inherited: Disabled here but enabled in pr-conf -# useless-super-delegation: Disabled here but enabled in pr-conf # unsubscriptable-object: TODO: Enabled after fix https://github.com/PyCQA/pylint/issues/811 # access-member-before-definition: Disable because odoo use decorator to asign variables # too-complex: Disabled here but enabled in pr-conf @@ -191,12 +140,7 @@ disable=abstract-method, # docstring-first-line-empty: Disabled here but enabled in pr-conf # consider-using-ternary: Disabled because I'm not sure of use even this way (and waiting PyCQA/pylint#1239) # inconsistent-return-statements: Disabled because all methods returns "None" by default if is not defined -# dict-keys-not-iterating: Disabled because we are sending dict.keys() like as valid parameters. -# dict-values-not-iterating: Disabled because we are checking if a value exists e.g. "value in dict.values()" # wrong-import-order: Disabled because this check requires a full installed environment, and MQT is not installing requirements for lints -# missing-super-argument: Disable because py3 now is supporting super without parameters. -# old-division: Disable because py3 doesn't require this parameter, but it is checked for this version. Maybe it is a temp bug but I prefer disable it -# broad-except: It is a valid case when you don't know all custom cases of exception # self-cls-assignment: Odoo uses this valid sentence self = self.with_context(...) # try-except-raise: Valid case when you want to raise a exception but not another one. # raise-missing-from: We are not using this style right now @@ -324,7 +268,6 @@ disable=abstract-method, # You can just use the new-style class instead. More info here: - http://stackoverflow.com/questions/54867/old-style-and-new-style-classes-in-python # Fix changing "class amount_to_text:" by "class amount_to_text(object):" . #W0640 - ("Cell variable defined in loop"). You must not define a local function inside a loop. You can either extract the local function outside the loop into a varaible and then use this variable inside the loop or modify the logic to do not use a local function using another tools like orm methods https://bitbucket.org/logilab/pylint/issue/271/spurious-warning-w0640-issued-for-loop -# W8201 - incoherent-interpreter-exec-perm: Execute chmod -x myfile.py or delete the interpreter comment #!/bin/BINPATH or if you really want a binary file use: chmod +x myfile.py and add the interpreter comment #!/bin/BINPATH. # R1260 - too-complex: To fix it use the following rules https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/The-Return-Early-Pattern #*** How to fix pylint-odoo*** @@ -349,13 +292,10 @@ disable=abstract-method, #W0212 (protected-access) - Odoo use many underscore methods #W0221 (arguments-differ) - Odoo 8.0 use decorator and rewrite original function and make this false error. #W0223 (abstract-method) - Odoo use abstract method without overriden. -#W0232 (no-init) - odoo use class without __init__ #W0511 (fixme) - Used when a warning note as FIXME or TODO is detected. This is not a error. #W0613 (unused-argument) odoo use many unused argument. Example cr, uid, name o super method. -#C0111 (missing-docstring) - Missing docstring http://pylint-messages.wikidot.com/messages:c0111. Too much work. WIP +#C0111 (missing-*-docstring) - Too much work. WIP #C0301 (line-too-long) - Enabled from flake8 -#C0326 (bad-whitespace) - Enabled from flake8 -#C0330 (bad-continuation) - Enabled from flake8 #R0201 (no-self-use) - Method could be a function http://pylint-messages.wikidot.com/messages:r0201. odoo use many method without decorator. #R0902 (too-many-instance-attributes) - Odoo use many initial attributes into __init__ of class myclass: myAttr1 #R0903 (too-few-public-methods) - odoo use many public methods in classes @@ -380,12 +320,6 @@ disable=abstract-method, # for more information see the following example bad case: https://gist.github.com/moylop260/ec534248e35ab193a84501b8fd96b1fd #R0915 (too-many-statements) - TODO: Enable if mccabe isn't detect this cases... Can be fixed split method in more mini-function. More info here: http://doc.openerp.co.id/contribute/15_guidelines/coding_guidelines_framework.html#keep-your-methods-short-simple-when-possible -# basestring-builtin For py27 is valid yet (py3 even use unicode string) -# unicode-builtin For py27 is valid yet (py3 even use unicode string) -# map-builtin-not-iterating For py27 map return a list (py3 return a generator) -# round-builtin For py27 the round is valid yet (py3 return a integer TODO: Enable if you use py3 to check that don't fails) -# long-builtin For py27 is long is valid yet (py3 merge long and integer TODO: Enable if you use py3 to check that don't fails) - [REPORTS] msg-template={path}:{line}:{column}: ({symbol}) {msg} diff --git a/src/pre_commit_vauxoo/cfg/.pylintrc-optional b/src/pre_commit_vauxoo/cfg/.pylintrc-optional index c79eda7..87b97a4 100644 --- a/src/pre_commit_vauxoo/cfg/.pylintrc-optional +++ b/src/pre_commit_vauxoo/cfg/.pylintrc-optional @@ -19,38 +19,22 @@ manifest-deprecated-keys=description,active [MESSAGES CONTROL] disable=all -enable=api-one-deprecated, - api-one-multi-together, - attribute-deprecated, +enable=attribute-deprecated, attribute-string-redundant, bad-builtin-groupby, bad-docstring-quotes, - character-not-valid-in-resource-link, - class-camelcase, consider-merging-classes-inherited, consider-using-generator, context-overridden, - create-user-wo-reset-password, - dangerous-filter-wo-user, - dangerous-qweb-replace-wo-priority, - dangerous-view-replace-wo-priority, - # deprecated-data-xml-node, - # deprecated-openerp-xml-node, deprecated-method, deprecated-odoo-model-method, deprecated-pragma, docstring-first-line-empty, - duplicate-id-csv, - duplicate-po-message-definition, - duplicate-xml-fields, - eval-referenced, + eval-used, except-pass, external-request-timeout, - # file-not-used, # can not be disabled implicit-str-concat, - incoherent-interpreter-exec-perm, invalid-commit, - # javascript-lint, # pre-commit is using eslint directly license-allowed, manifest-author-string, manifest-data-duplicated, @@ -63,26 +47,15 @@ enable=api-one-deprecated, method-inverse, method-required-super, method-search, - missing-import-error, - missing-manifest-dependency, - missing-newline-extrafiles, missing-readme, missing-return, - no-utf8-coding-comment, odoo-addons-relative-import, - openerp-exception-warning, odoo-exception-warning, - po-msgstr-variables, - po-syntax-error, - # prefer-other-formatting, # py3 doesn't have coding issues anymore print-used, - redundant-modulename-xml, redundant-u-string-prefix, renamed-field-parameter, resource-not-exist, - rst-syntax-error, sql-injection, - str-format-used, too-complex, translation-contains-variable, translation-field, @@ -91,20 +64,17 @@ enable=api-one-deprecated, translation-format-interpolation, translation-format-truncated, translation-fstring-interpolation, - translation-not-lazy, translation-too-few-args, translation-too-many-args, translation-unsupported-format, - unnecessary-utf8-coding-comment, + use-dict-literal, + use-implicit-booleaness-not-comparison-to-string, + use-implicit-booleaness-not-comparison-to-zero, use-symbolic-message-instead, use-vim-comment, - useless-super-delegation, - website-manifest-key-not-valid-uri, - wrong-tabs-instead-of-spaces, - xml-attribute-translatable, - xml-deprecated-qweb-directive, - xml-deprecated-tree-attribute, - xml-syntax-error, + useless-parent-delegation, + useless-option-value, + website-manifest-key-not-valid-uri [REPORTS] msg-template={path}:{line}:{column}: ({symbol}) {msg} diff --git a/src/pre_commit_vauxoo/pre_commit_vauxoo.py b/src/pre_commit_vauxoo/pre_commit_vauxoo.py index 26f3fd2..aaaaa81 100644 --- a/src/pre_commit_vauxoo/pre_commit_vauxoo.py +++ b/src/pre_commit_vauxoo/pre_commit_vauxoo.py @@ -259,7 +259,7 @@ def main( status += autofix_status test_name = "Autofix checks" all_status[test_name] = {"status": autofix_status} - if autofix_status != 0: + if autofix_status: _logger.error("%s reformatted", test_name) is_ci = get_is_ci() if is_ci[0]: @@ -319,7 +319,7 @@ def main( status += mandatory_status test_name = "Mandatory checks" all_status[test_name] = {"status": mandatory_status} - if mandatory_status != 0: + if mandatory_status: _logger.error("%s failed", test_name) all_status[test_name]["level"] = logging.ERROR all_status[test_name]["status_msg"] = "Failed" @@ -335,12 +335,12 @@ def main( status_optional = subprocess_call(cmd + ["-c", os.path.join(repo_dirname, pre_commit_cfg_optional)]) test_name = "Optional checks" all_status[test_name] = {"status": status_optional} - if status_optional != 0 and fail_optional: + if status_optional and fail_optional: _logger.error("Optional checks failed") all_status[test_name]["level"] = logging.ERROR all_status[test_name]["status_msg"] = "Failed" status += status_optional - elif status_optional != 0: + elif status_optional: _logger.warning("Optional checks failed") all_status[test_name]["level"] = logging.WARNING all_status[test_name]["status_msg"] = "Failed" @@ -352,7 +352,7 @@ def main( print_summary(all_status) if do_exit: - sys.exit(0 if status == 0 else 1) + sys.exit(status) def print_summary(all_status): @@ -362,7 +362,7 @@ def print_summary(all_status): for test_name, test_result in all_status.items(): outcome = ( logging_colored.colorized_msg(test_result["status_msg"], test_result["level"]) - if test_result["status"] != 0 + if test_result["status"] else logging_colored.colorized_msg(test_result["status_msg"], test_result["level"]) ) summary_msg.append("| {:<28}{}".format(test_name, outcome)) diff --git a/test-requirements.txt b/test-requirements.txt index 30a6e2f..f9fa7a0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -10,3 +10,4 @@ tox twine wheel pyyaml +pylint-odoo diff --git a/tests/test_pre_commit_vauxoo.py b/tests/test_pre_commit_vauxoo.py index 9f8de1a..e284313 100644 --- a/tests/test_pre_commit_vauxoo.py +++ b/tests/test_pre_commit_vauxoo.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging import os import posixpath @@ -7,10 +9,13 @@ import sys import tempfile import unittest -from contextlib import contextmanager +from configparser import ConfigParser +from contextlib import contextmanager, redirect_stdout from distutils.dir_util import copy_tree # pylint:disable=deprecated-module +from io import StringIO from click.testing import CliRunner +from pylint.lint import Run from yaml import Loader, load from pre_commit_vauxoo.cli import main @@ -70,6 +75,16 @@ def custom_assert_logs(self, module, level, expected_logs): # bypassing for dual compatibility with py<3.4 yield + def get_pylint_messages(self): + output = StringIO() + with self.assertRaises(SystemExit) as ex, redirect_stdout(output): + Run(["--load-plugins=pylint.extensions.docstyle,pylint.extensions.mccabe,pylint_odoo", "--list-msgs"]) + self.assertEqual(ex.exception.code, 0, "There was an error obtaining messages from pylint") + + output.seek(0) + output = output.read() + return set(re.findall(r"^:([a-z\-]+)", output, re.MULTILINE)) + def test_basic(self): os.environ["INCLUDE_LINT"] = os.path.join(self.tmp_dir, "module_example1") os.environ["PRECOMMIT_HOOKS_TYPE"] = "all" @@ -203,6 +218,29 @@ def test_disable_oca_hooks(self): "random-message was supposed to be disabled through the corresponding environment variable", ) + def test_valid_pylintrc_messages(self): + pylint_messages = self.get_pylint_messages() + rc_files = [ + os.path.abspath(os.path.join(__file__, "..", "..", "src", "pre_commit_vauxoo", "cfg", pylintrc)) + for pylintrc in [".pylintrc", ".pylintrc-optional"] + ] + for rc_file in rc_files: + config = ConfigParser() + config.read(rc_file) + for action in ["enable", "disable"]: + if config["MESSAGES CONTROL"][action] == "all": + continue + + messages = config["MESSAGES CONTROL"][action].split(",\n") + duplicates = set() + messages_set = set() + for message in messages: + self.assertIn(message, pylint_messages, f"{message} in {rc_file} is not a valid message") + self.assertNotIn(message, messages_set, f"Duplicate '{message}' in {rc_file}") + messages_set.add(message) + + self.assertFalse(duplicates, f"Duplicate messages found in {rc_file}") + if __name__ == "__main__": unittest.main()