From 6fc8c9f78554d10637a97c24d4275b5e298e0c20 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sat, 28 Mar 2020 12:24:07 +0100 Subject: [PATCH] Update hacking for Python3 The repo is Python 3 now, so update hacking to version 2.0 which supports Python 3. Fix problems found. Change-Id: I4cebf81b32bdf285f0d412255984c176140329be --- muranopkgcheck/checkers/code_structure.py | 3 ++- muranopkgcheck/cmd/run.py | 1 + muranopkgcheck/error.py | 1 + muranopkgcheck/tests/functional/test_cases.py | 1 + muranopkgcheck/tests/test_muranopl_validator.py | 6 +++--- muranopkgcheck/tests/test_pkg_loader.py | 4 ++-- muranopkgcheck/validators/base.py | 4 ++-- muranopkgcheck/validators/muranopl.py | 2 +- muranopkgcheck/validators/ui.py | 2 +- muranopkgcheck/yaml_loader.py | 1 + test-requirements.txt | 2 +- tools/gen_errors.py | 1 + tox.ini | 2 +- 13 files changed, 18 insertions(+), 12 deletions(-) diff --git a/muranopkgcheck/checkers/code_structure.py b/muranopkgcheck/checkers/code_structure.py index ba1220b..7e842cf 100644 --- a/muranopkgcheck/checkers/code_structure.py +++ b/muranopkgcheck/checkers/code_structure.py @@ -19,12 +19,13 @@ from muranopkgcheck.checkers import yaql_checker from muranopkgcheck import error -ASSIGMENT_KEY = re.compile('^\$.?[\w]') +ASSIGMENT_KEY = re.compile(r'^\$.?[\w]') def check_req(check, required=True): return locals() + error.register.E203(description='Value should be string type') error.register.E200(description='No value should be here') error.register.E204(description='Wrong code structure/assigment') diff --git a/muranopkgcheck/cmd/run.py b/muranopkgcheck/cmd/run.py index c74175f..bea5900 100644 --- a/muranopkgcheck/cmd/run.py +++ b/muranopkgcheck/cmd/run.py @@ -142,5 +142,6 @@ def main(): else: print('No errors found!') + if __name__ == '__main__': sys.exit(main()) diff --git a/muranopkgcheck/error.py b/muranopkgcheck/error.py index fbb8567..74481cd 100644 --- a/muranopkgcheck/error.py +++ b/muranopkgcheck/error.py @@ -84,5 +84,6 @@ class Register(object): self.errors[code] = props return _register + report = Report(errors) register = Register(errors) diff --git a/muranopkgcheck/tests/functional/test_cases.py b/muranopkgcheck/tests/functional/test_cases.py index 46ce753..988a8de 100644 --- a/muranopkgcheck/tests/functional/test_cases.py +++ b/muranopkgcheck/tests/functional/test_cases.py @@ -79,6 +79,7 @@ def load_cases(): cases.extend(list(yaml.load_all(f))) return cases + cases = load_cases() diff --git a/muranopkgcheck/tests/test_muranopl_validator.py b/muranopkgcheck/tests/test_muranopl_validator.py index b2d51fb..78da43b 100644 --- a/muranopkgcheck/tests/test_muranopl_validator.py +++ b/muranopkgcheck/tests/test_muranopl_validator.py @@ -245,7 +245,7 @@ class MuranoPlTests(helpers.BaseValidatorTestClass): p_dict = deepcopy(MURANOPL_BASE['Properties']) p_dict['ports']['Contract'] = { '$.int()': '$.string()', - '$.string()': {'$.int()': '$.ports()', '$.int()': { + '$.string()': {'$.int()': { '$': [], '$.int()': '$.string()'}} } self.g = self.mpl_validator._valid_properties(p_dict) @@ -254,7 +254,7 @@ class MuranoPlTests(helpers.BaseValidatorTestClass): p_dict = deepcopy(MURANOPL_BASE['Properties']) p_dict['ports']['Contract'] = { '$.int()': [], - '$.int()': {} + '$.string()': {} } self.g = self.mpl_validator._valid_properties(p_dict) @@ -265,7 +265,7 @@ class MuranoPlTests(helpers.BaseValidatorTestClass): p_dict = deepcopy(MURANOPL_BASE['Properties']) p_dict['ports']['Contract'] = [{ '$.string()': '$.string()', - '$.int()': [{'$.int()': '$.string()', '$.int()': []}]}] + '$.int()': [{'$.int()': '$.string()', '$.string()': []}]}] self.g = self.mpl_validator._valid_properties(p_dict) def test_contract_is_a_list_two_elements(self): diff --git a/muranopkgcheck/tests/test_pkg_loader.py b/muranopkgcheck/tests/test_pkg_loader.py index b9f1983..534b777 100644 --- a/muranopkgcheck/tests/test_pkg_loader.py +++ b/muranopkgcheck/tests/test_pkg_loader.py @@ -121,9 +121,9 @@ class BaseLoaderTest(base.TestCase): def test_search_for(self): fake = FakeLoader('fake') self.assertEqual(['1.yaml', 'sub/3.yaml'], - list(fake.search_for('.*\.yaml$'))) + list(fake.search_for(r'.*\.yaml$'))) self.assertEqual(['3.yaml'], - list(fake.search_for('.*\.yaml$', subdir='sub'))) + list(fake.search_for(r'.*\.yaml$', subdir='sub'))) def test_read(self): fake = FakeLoader('fake') diff --git a/muranopkgcheck/validators/base.py b/muranopkgcheck/validators/base.py index 5dcc268..2e36d3c 100644 --- a/muranopkgcheck/validators/base.py +++ b/muranopkgcheck/validators/base.py @@ -21,8 +21,8 @@ import six from muranopkgcheck import error from muranopkgcheck.i18n import _ -FQN_REGEX = re.compile('^([a-zA-Z_$][\w$]*\.)*[a-zA-Z_$][\w$]*$') -NAME_REGEX = re.compile('^[A-Za-z_][\w]*$') +FQN_REGEX = re.compile(r'^([a-zA-Z_$][\w$]*\.)*[a-zA-Z_$][\w$]*$') +NAME_REGEX = re.compile(r'^[A-Za-z_][\w]*$') error.register.E002(description='Yaml Error') error.register.E005(description='YAML multi document is not allowed') diff --git a/muranopkgcheck/validators/muranopl.py b/muranopkgcheck/validators/muranopl.py index 9a8fc56..b86f35b 100644 --- a/muranopkgcheck/validators/muranopl.py +++ b/muranopkgcheck/validators/muranopl.py @@ -62,7 +62,7 @@ error.register.W060(description='Wrong namespace fqn') class MuranoPLValidator(base.YamlValidator): def __init__(self, loaded_package): super(MuranoPLValidator, self).__init__(loaded_package, - 'Classes/.*\.yaml$', + r'Classes/.*\.yaml$', True) self.yaql_checker = yaql_checker.YaqlChecker() self.code_structure = code_structure.CheckCodeStructure() diff --git a/muranopkgcheck/validators/ui.py b/muranopkgcheck/validators/ui.py index bafa19b..1b423a3 100644 --- a/muranopkgcheck/validators/ui.py +++ b/muranopkgcheck/validators/ui.py @@ -38,7 +38,7 @@ error.register.W100(description='Not known type. Probably typo') class UiValidator(base.YamlValidator): def __init__(self, loaded_package): - super(UiValidator, self).__init__(loaded_package, 'UI/.*\.yaml$') + super(UiValidator, self).__init__(loaded_package, r'UI/.*\.yaml$') self.add_checker(self._valid_forms, 'Forms', False) self.add_checker(self._null_checker, 'Templates', False) self.add_checker(self._valid_application, 'Application', False) diff --git a/muranopkgcheck/yaml_loader.py b/muranopkgcheck/yaml_loader.py index 3a277d5..a29bfb0 100644 --- a/muranopkgcheck/yaml_loader.py +++ b/muranopkgcheck/yaml_loader.py @@ -89,6 +89,7 @@ class YamlLoader(BaseLoader): value.__yaml_meta__ = node.start_mark return value + YamlLoader.add_constructor( u'tag:yaml.org,2002:seq', YamlLoader.construct_yaml_seq) diff --git a/test-requirements.txt b/test-requirements.txt index d871a96..5354fcc 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking<0.12,>=0.11.0 # Apache-2.0 +hacking>=2.0,<2.1 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 python-subunit>=1.0.0 # Apache-2.0/BSD diff --git a/tools/gen_errors.py b/tools/gen_errors.py index 4a1c514..41a034c 100644 --- a/tools/gen_errors.py +++ b/tools/gen_errors.py @@ -41,5 +41,6 @@ def main(): with open('doc/source/_errors_list.rst', 'w') as f: f.write(r) + if __name__ == '__main__': main() diff --git a/tox.ini b/tox.ini index 6d2e160..5ea8359 100644 --- a/tox.ini +++ b/tox.ini @@ -61,7 +61,7 @@ commands = # E123, E125 skipped as they are invalid PEP-8. show-source = True -ignore = E123,E125 +ignore = E123,E125,W504 builtins = _ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build