From b822316cf0d95b4c27d40c330de888df4bb44293 Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 17 Aug 2024 16:22:00 +0000 Subject: [PATCH 1/6] Fix tests and add github tests --- .github/dependabot.yml | 25 ++++++++++ .github/workflows/test-build-publish.yml | 60 ++++++++++++++++++++++++ reclass/tests/test_core.py | 22 ++++----- requirements.txt | 10 ++-- 4 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/test-build-publish.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..7fc5cf7f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,25 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + commit-message: + prefix: "chore: " + labels: + - "dependencies" + open-pull-requests-limit: 2 + reviewers: + - "kapicorp/kapicorpdevs" + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + labels: + - "github-actions" \ No newline at end of file diff --git a/.github/workflows/test-build-publish.yml b/.github/workflows/test-build-publish.yml new file mode 100644 index 00000000..7d7eb638 --- /dev/null +++ b/.github/workflows/test-build-publish.yml @@ -0,0 +1,60 @@ +--- +name: Test Reclass +run-name: PyTest tests for ${{ github.actor }} on branch ${{ github.ref_name }} + +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + +on: + push: + branches: + - master + - main + + release: + types: [created] + + pull_request: + +jobs: + lint: + name: linter + runs-on: ubuntu-latest + if: success() || failure() # Continue running if other jobs fail + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + - uses: psf/black@main + + test: + name: python ${{ matrix.python-version }} tests + runs-on: ubuntu-latest + if: success() || failure() # Continue running if other jobs fail + strategy: + fail-fast: false + matrix: + python-version: ['3.10', '3.11', '3.12'] + steps: + - name: Checkout kapitan recursively + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + cache: 'pip' + python-version: ${{ matrix.python-version }} + - name: Install libraries dependencies + run: | + pip install -r requirements.txt + - name: Run pytest + uses: pavelzw/pytest-action@v2 + with: + verbose: true + emoji: false + job-summary: true + custom-pytest: poetry run pytest + custom-arguments: '-q' + click-to-expand: true + report-title: 'Reclass Tests' diff --git a/reclass/tests/test_core.py b/reclass/tests/test_core.py index dd51f3a0..dd00dc50 100644 --- a/reclass/tests/test_core.py +++ b/reclass/tests/test_core.py @@ -34,7 +34,7 @@ def _core(self, dataset, opts={}, class_mappings=[]): def test_type_conversion(self): reclass = self._core('01') node = reclass.nodeinfo('data_types') - params = { 'int': 1, 'bool': True, 'string': '1', '_reclass_': { 'environment': 'base', 'name': {'full': 'data_types', 'short': 'data_types' } } } + params = { 'int': 1, 'bool': True, 'string': '1', '_reclass_': { 'environment': 'base', 'name': {'full': 'data_types', 'parts': ['data_types'], 'path': 'data_types', 'short': 'data_types' } } } self.assertEqual(node['parameters'], params) def test_raise_class_notfound(self): @@ -45,7 +45,7 @@ def test_raise_class_notfound(self): def test_ignore_class_notfound(self): reclass = self._core('01', opts={ 'ignore_class_notfound': True, 'ignore_class_notfound_warning': False }) node = reclass.nodeinfo('class_notfound') - params = { 'node_test': 'class not found', '_reclass_': { 'environment': 'base', 'name': {'full': 'class_notfound', 'short': 'class_notfound' } } } + params = { 'node_test': 'class not found', '_reclass_': { 'environment': 'base', 'name': {'full': 'class_notfound', 'parts': ['class_notfound'], 'path': 'class_notfound', 'short': 'class_notfound' } } } self.assertEqual(node['parameters'], params) def test_raise_class_notfound_with_regexp(self): @@ -56,31 +56,31 @@ def test_raise_class_notfound_with_regexp(self): def test_ignore_class_notfound_with_regexp(self): reclass = self._core('01', opts={ 'ignore_class_notfound': True, 'ignore_class_notfound_warning': False, 'ignore_class_notfound_regexp': 'miss.*' }) node = reclass.nodeinfo('class_notfound') - params = { 'node_test': 'class not found', '_reclass_': { 'environment': 'base', 'name': {'full': 'class_notfound', 'short': 'class_notfound' } } } + params = { 'node_test': 'class not found', '_reclass_': { 'environment': 'base', 'name': {'full': 'class_notfound', 'parts': ['class_notfound'], 'path': 'class_notfound', 'short': 'class_notfound' } } } self.assertEqual(node['parameters'], params) def test_relative_class_names(self): reclass = self._core('02') node = reclass.nodeinfo('relative') - params = { 'test1': 1, 'test2': 2, 'test3': 3, 'test4': 4, 'test5': 5, 'one_beta': 1, 'two_beta': 2, 'four_alpha': 3, 'two_gamma': 4, 'alpha_init': 5, '_reclass_': { 'environment': 'base', 'name': { 'full': 'relative', 'short': 'relative' } } } + params = { 'test1': 1, 'test2': 2, 'test3': 3, 'test4': 4, 'test5': 5, 'one_beta': 1, 'two_beta': 2, 'four_alpha': 3, 'two_gamma': 4, 'alpha_init': 5, '_reclass_': { 'environment': 'base', 'name': { 'full': 'relative', 'parts': ['relative'], 'path': 'relative', 'short': 'relative' } } } self.assertEqual(node['parameters'], params) def test_top_relative_class_names(self): reclass = self._core('02') node = reclass.nodeinfo('top_relative') - params = { 'test1': 1, 'test2': 2, 'test3': 3, 'test4': 4, 'test5': 5, 'one_beta': 1, 'two_beta': 2, 'four_alpha': 3, 'two_gamma': 4, 'alpha_init': 5, '_reclass_': { 'environment': 'base', 'name': { 'full': 'top_relative', 'short': 'top_relative' } } } + params = { 'test1': 1, 'test2': 2, 'test3': 3, 'test4': 4, 'test5': 5, 'one_beta': 1, 'two_beta': 2, 'four_alpha': 3, 'two_gamma': 4, 'alpha_init': 5, '_reclass_': { 'environment': 'base', 'name': { 'full': 'top_relative', 'parts': ['top_relative'], 'path': 'top_relative', 'short': 'top_relative' } } } self.assertEqual(node['parameters'], params) def test_compose_node_names(self): reclass = self._core('03', opts={'compose_node_name': True}) alpha_one_node = reclass.nodeinfo('alpha.one') - alpha_one_res = {'a': 1, 'alpha': [1, 2], 'beta': {'a': 1, 'b': 2}, 'b': 2, '_reclass_': {'environment': 'base', 'name': {'full': 'alpha.one', 'short': 'alpha'}}} + alpha_one_res = {'a': 1, 'alpha': [1, 2], 'beta': {'a': 1, 'b': 2}, 'b': 2, '_reclass_': {'environment': 'base', 'name': {'full': 'alpha.one', 'parts': ['alpha', 'one'], 'path': 'alpha/one', 'short': 'one'}}} alpha_two_node = reclass.nodeinfo('alpha.two') - alpha_two_res = {'a': 1, 'alpha': [1, 3], 'beta': {'a': 1, 'c': 3}, 'c': 3, '_reclass_': {'environment': 'base', 'name': {'full': 'alpha.two', 'short': 'alpha'}}} + alpha_two_res = {'a': 1, 'alpha': [1, 3], 'beta': {'a': 1, 'c': 3}, 'c': 3, '_reclass_': {'environment': 'base', 'name': {'full': 'alpha.two', 'parts': ['alpha', 'two'], 'path': 'alpha/two', 'short': 'two'}}} beta_one_node = reclass.nodeinfo('beta.one') - beta_one_res = {'alpha': [2, 3], 'beta': {'c': 3, 'b': 2}, 'b': 2, 'c': 3, '_reclass_': {'environment': 'base', 'name': {'full': 'beta.one', 'short': 'beta'}}} + beta_one_res = {'alpha': [2, 3], 'beta': {'c': 3, 'b': 2}, 'b': 2, 'c': 3, '_reclass_': {'environment': 'base', 'name': {'full': 'beta.one', 'parts': ['beta', 'one'], 'path': 'beta/one', 'short': 'one'}}} beta_two_node = reclass.nodeinfo('beta.two') - beta_two_res = {'alpha': [3, 4], 'c': 3, 'beta': {'c': 3, 'd': 4}, 'd': 4, '_reclass_': {'environment': u'base', 'name': {'full': u'beta.two', 'short': u'beta'}}} + beta_two_res = {'alpha': [3, 4], 'c': 3, 'beta': {'c': 3, 'd': 4}, 'd': 4, '_reclass_': {'environment': u'base', 'name': {'full': u'beta.two', 'parts': ['beta', 'two'], 'path': 'beta/two', 'short': u'two'}}} self.assertEqual(alpha_one_node['parameters'], alpha_one_res) self.assertEqual(alpha_two_node['parameters'], alpha_two_res) self.assertEqual(beta_one_node['parameters'], beta_one_res) @@ -89,13 +89,13 @@ def test_compose_node_names(self): def test_class_mappings_match_path_false(self): reclass = self._core('04', opts={'class_mappings_match_path': False}, class_mappings=['node* two', 'alpha/node* three']) node = reclass.nodeinfo('node1') - params = { 'test1': 1, 'test2': 2, '_reclass_': {'environment': u'base', 'name': {'full': 'node1', 'short': 'node1'}}} + params = { 'test1': 1, 'test2': 2, '_reclass_': {'environment': u'base', 'name': {'full': 'node1', 'parts': ['node1'], 'path': 'node1', 'short': 'node1'}}} self.assertEqual(node['parameters'], params) def test_class_mappings_match_path_true(self): reclass = self._core('04', opts={'class_mappings_match_path': True}, class_mappings=['node* two', 'alpha/node* three']) node = reclass.nodeinfo('node1') - params = { 'test1': 1, 'test3': 3, '_reclass_': {'environment': u'base', 'name': {'full': 'node1', 'short': 'node1'}}} + params = { 'test1': 1, 'test3': 3, '_reclass_': {'environment': u'base', 'name': {'full': 'node1', 'parts': ['node1'], 'path': 'node1', 'short': 'node1'}}} self.assertEqual(node['parameters'], params) def test_merging_of_parameters_before_class_interpolation_enabling_overrides(self): diff --git a/requirements.txt b/requirements.txt index 5f6aed18..f24d3244 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -pyparsing -pyyaml -six -enum34 -ddt +pyparsing==3.1.2 +pyyaml==6.0.2 +six==1.16.0 +enum34==1.1.10 +ddt==1.7.2 From da0862609c3b8bdc4ba4d9ced5416ea15e88d50d Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 17 Aug 2024 16:24:33 +0000 Subject: [PATCH 2/6] Fix tests and add github tests --- .github/workflows/test-build-publish.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/test-build-publish.yml b/.github/workflows/test-build-publish.yml index 7d7eb638..a310d6e6 100644 --- a/.github/workflows/test-build-publish.yml +++ b/.github/workflows/test-build-publish.yml @@ -18,15 +18,6 @@ on: pull_request: jobs: - lint: - name: linter - runs-on: ubuntu-latest - if: success() || failure() # Continue running if other jobs fail - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - - uses: psf/black@main - test: name: python ${{ matrix.python-version }} tests runs-on: ubuntu-latest @@ -54,7 +45,6 @@ jobs: verbose: true emoji: false job-summary: true - custom-pytest: poetry run pytest custom-arguments: '-q' click-to-expand: true report-title: 'Reclass Tests' From 966c9820f063e6ec0a1c3ab85d0ae6ed59715ddd Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 17 Aug 2024 16:26:21 +0000 Subject: [PATCH 3/6] Fix tests and add github tests --- .github/workflows/test-build-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-build-publish.yml b/.github/workflows/test-build-publish.yml index a310d6e6..0e840a64 100644 --- a/.github/workflows/test-build-publish.yml +++ b/.github/workflows/test-build-publish.yml @@ -39,6 +39,7 @@ jobs: - name: Install libraries dependencies run: | pip install -r requirements.txt + pip install pytest pytest-md pytest-emoji - name: Run pytest uses: pavelzw/pytest-action@v2 with: From a538165256b79d16512add92dc8bd658ed23502f Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 17 Aug 2024 16:26:58 +0000 Subject: [PATCH 4/6] Fix tests and add github tests --- .github/workflows/test-build-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-build-publish.yml b/.github/workflows/test-build-publish.yml index 0e840a64..7d78c844 100644 --- a/.github/workflows/test-build-publish.yml +++ b/.github/workflows/test-build-publish.yml @@ -39,7 +39,7 @@ jobs: - name: Install libraries dependencies run: | pip install -r requirements.txt - pip install pytest pytest-md pytest-emoji + pip install pytest pytest-md pytest-emoji mock - name: Run pytest uses: pavelzw/pytest-action@v2 with: From 6cf7f74256fa21ff806095d09e00f558a43d43cd Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 17 Aug 2024 16:32:45 +0000 Subject: [PATCH 5/6] Fix tests and add github tests --- reclass/values/tests/test_compitem.py | 20 +++++++++---------- reclass/values/tests/test_item.py | 6 +++--- reclass/values/tests/test_listitem.py | 2 +- reclass/values/tests/test_parser_functions.py | 4 ++-- reclass/values/tests/test_refitem.py | 6 +++--- reclass/values/tests/test_scaitem.py | 4 ++-- reclass/values/tests/test_value.py | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/reclass/values/tests/test_compitem.py b/reclass/values/tests/test_compitem.py index c3ee6909..0c1b79a6 100644 --- a/reclass/values/tests/test_compitem.py +++ b/reclass/values/tests/test_compitem.py @@ -30,7 +30,7 @@ def test_assembleRefs_one_item_with_one_ref(self): composite = CompItem([val1], SETTINGS) self.assertTrue(composite.has_references) - self.assertEquals(composite.get_references(), expected_refs) + self.assertEqual(composite.get_references(), expected_refs) def test_assembleRefs_one_item_with_two_refs(self): val1 = Value('${foo}${bar}', SETTINGS, '') @@ -39,7 +39,7 @@ def test_assembleRefs_one_item_with_two_refs(self): composite = CompItem([val1], SETTINGS) self.assertTrue(composite.has_references) - self.assertEquals(composite.get_references(), expected_refs) + self.assertEqual(composite.get_references(), expected_refs) def test_assembleRefs_two_items_one_with_one_ref_one_without(self): val1 = Value('${foo}bar', SETTINGS, '') @@ -49,7 +49,7 @@ def test_assembleRefs_two_items_one_with_one_ref_one_without(self): composite = CompItem([val1, val2], SETTINGS) self.assertTrue(composite.has_references) - self.assertEquals(composite.get_references(), expected_refs) + self.assertEqual(composite.get_references(), expected_refs) def test_assembleRefs_two_items_both_with_one_ref(self): val1 = Value('${foo}', SETTINGS, '') @@ -59,7 +59,7 @@ def test_assembleRefs_two_items_both_with_one_ref(self): composite = CompItem([val1, val2], SETTINGS) self.assertTrue(composite.has_references) - self.assertEquals(composite.get_references(), expected_refs) + self.assertEqual(composite.get_references(), expected_refs) def test_assembleRefs_two_items_with_two_refs(self): val1 = Value('${foo}${baz}', SETTINGS, '') @@ -69,7 +69,7 @@ def test_assembleRefs_two_items_with_two_refs(self): composite = CompItem([val1, val2], SETTINGS) self.assertTrue(composite.has_references) - self.assertEquals(composite.get_references(), expected_refs) + self.assertEqual(composite.get_references(), expected_refs) def test_string_representation(self): composite = CompItem(Value(1, SETTINGS, ''), SETTINGS) @@ -77,14 +77,14 @@ def test_string_representation(self): result = str(composite) - self.assertEquals(result, expected) + self.assertEqual(result, expected) def test_render_single_item(self): val1 = Value('${foo}', SETTINGS, '') composite = CompItem([val1], SETTINGS) - self.assertEquals(1, composite.render({'foo': 1}, None)) + self.assertEqual(1, composite.render({'foo': 1}, None)) def test_render_multiple_items(self): @@ -93,7 +93,7 @@ def test_render_multiple_items(self): composite = CompItem([val1, val2], SETTINGS) - self.assertEquals('12', composite.render({'foo': 1, 'bar': 2}, None)) + self.assertEqual('12', composite.render({'foo': 1, 'bar': 2}, None)) def test_merge_over_merge_scalar(self): val1 = Value(None, SETTINGS, '') @@ -102,7 +102,7 @@ def test_merge_over_merge_scalar(self): result = composite.merge_over(scalar) - self.assertEquals(result, composite) + self.assertEqual(result, composite) def test_merge_over_merge_composite(self): val1 = Value(None, SETTINGS, '') @@ -112,7 +112,7 @@ def test_merge_over_merge_composite(self): result = composite2.merge_over(composite1) - self.assertEquals(result, composite2) + self.assertEqual(result, composite2) def test_merge_other_types_not_allowed(self): other = type('Other', (object,), {'type': 34}) diff --git a/reclass/values/tests/test_item.py b/reclass/values/tests/test_item.py index 4b91f6e6..00b11d5a 100644 --- a/reclass/values/tests/test_item.py +++ b/reclass/values/tests/test_item.py @@ -22,7 +22,7 @@ def test_assembleRef_allrefs(self): iwr = ItemWithReferences([phonyitem], {}) - self.assertEquals(iwr.get_references(), [1]) + self.assertEqual(iwr.get_references(), [1]) self.assertTrue(iwr.allRefs) def test_assembleRef_partial(self): @@ -33,7 +33,7 @@ def test_assembleRef_partial(self): iwr = ItemWithReferences([phonyitem], {}) - self.assertEquals(iwr.get_references(), [1]) + self.assertEqual(iwr.get_references(), [1]) self.assertFalse(iwr.allRefs) @@ -42,7 +42,7 @@ class TestContainerItem(unittest.TestCase): def test_render(self): container = ContainerItem('foo', SETTINGS) - self.assertEquals(container.render(None, None), 'foo') + self.assertEqual(container.render(None, None), 'foo') if __name__ == '__main__': unittest.main() diff --git a/reclass/values/tests/test_listitem.py b/reclass/values/tests/test_listitem.py index 618b7797..009f384c 100644 --- a/reclass/values/tests/test_listitem.py +++ b/reclass/values/tests/test_listitem.py @@ -18,7 +18,7 @@ def test_merge_over_merge_list(self): result = listitem2.merge_over(listitem1) - self.assertEquals(result.contents, expected.contents) + self.assertEqual(result.contents, expected.contents) def test_merge_other_types_not_allowed(self): other = type('Other', (object,), {'type': 34}) diff --git a/reclass/values/tests/test_parser_functions.py b/reclass/values/tests/test_parser_functions.py index a660c76c..1b5e01f9 100644 --- a/reclass/values/tests/test_parser_functions.py +++ b/reclass/values/tests/test_parser_functions.py @@ -94,7 +94,7 @@ def test_standard_reference_parser(self, data): result = pf.listify(parser.parseString(instring).asList()) - self.assertEquals(expected, result) + self.assertEqual(expected, result) @ddt.ddt @@ -109,7 +109,7 @@ def test_standard_reference_parser(self, data): result = pf.listify(parser.parseString(instring).asList()) - self.assertEquals(expected, result) + self.assertEqual(expected, result) if __name__ == '__main__': diff --git a/reclass/values/tests/test_refitem.py b/reclass/values/tests/test_refitem.py index 65814782..02bd9f51 100644 --- a/reclass/values/tests/test_refitem.py +++ b/reclass/values/tests/test_refitem.py @@ -23,7 +23,7 @@ def test_assembleRefs_ok(self): iwr = RefItem([phonyitem], {}) - self.assertEquals(iwr.get_references(), ['foo', 'bar']) + self.assertEqual(iwr.get_references(), ['foo', 'bar']) self.assertTrue(iwr.allRefs) def test_assembleRefs_failedrefs(self): @@ -34,7 +34,7 @@ def test_assembleRefs_failedrefs(self): iwr = RefItem([phonyitem], {}) - self.assertEquals(iwr.get_references(), ['foo']) + self.assertEqual(iwr.get_references(), ['foo']) self.assertFalse(iwr.allRefs) def test__resolve_ok(self): @@ -42,7 +42,7 @@ def test__resolve_ok(self): result = reference._resolve('foo:bar', {'foo':{'bar': 1}}) - self.assertEquals(result, 1) + self.assertEqual(result, 1) def test__resolve_fails(self): refitem = RefItem('', Settings({'delimiter': ':'})) diff --git a/reclass/values/tests/test_scaitem.py b/reclass/values/tests/test_scaitem.py index b6d038de..6cf5032d 100644 --- a/reclass/values/tests/test_scaitem.py +++ b/reclass/values/tests/test_scaitem.py @@ -17,7 +17,7 @@ def test_merge_over_merge_scalar(self): result = scalar2.merge_over(scalar1) - self.assertEquals(result.contents, scalar2.contents) + self.assertEqual(result.contents, scalar2.contents) def test_merge_over_merge_composite(self): scalar1 = CompItem(Value(1, SETTINGS, ''), SETTINGS) @@ -25,7 +25,7 @@ def test_merge_over_merge_composite(self): result = scalar2.merge_over(scalar1) - self.assertEquals(result.contents, scalar2.contents) + self.assertEqual(result.contents, scalar2.contents) def test_merge_other_types_not_allowed(self): other = type('Other', (object,), {'type': 34}) diff --git a/reclass/values/tests/test_value.py b/reclass/values/tests/test_value.py index a06d2207..4c9d8eea 100644 --- a/reclass/values/tests/test_value.py +++ b/reclass/values/tests/test_value.py @@ -41,7 +41,7 @@ def test_simple_string(self): s = 'my cat likes to hide in boxes' tv = Value(s, SETTINGS, '') self.assertFalse(tv.has_references) - self.assertEquals(tv.render(CONTEXT, None), s) + self.assertEqual(tv.render(CONTEXT, None), s) def _test_solo_ref(self, key): s = _var(key) From fde6f2488f0d467134386694891e5b8f2fc4af5b Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 17 Aug 2024 16:37:48 +0000 Subject: [PATCH 6/6] Revert requirements.txt --- requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index f24d3244..5f6aed18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -pyparsing==3.1.2 -pyyaml==6.0.2 -six==1.16.0 -enum34==1.1.10 -ddt==1.7.2 +pyparsing +pyyaml +six +enum34 +ddt