Skip to content

Commit

Permalink
Merge pull request #15 from kapicorp/improve-tests
Browse files Browse the repository at this point in the history
Fix tests and add github tests
  • Loading branch information
ademariag authored Aug 17, 2024
2 parents 856b34c + fde6f24 commit eeb5aab
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 33 deletions.
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
51 changes: 51 additions & 0 deletions .github/workflows/test-build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
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:
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
pip install pytest pytest-md pytest-emoji mock
- name: Run pytest
uses: pavelzw/pytest-action@v2
with:
verbose: true
emoji: false
job-summary: true
custom-arguments: '-q'
click-to-expand: true
report-title: 'Reclass Tests'
22 changes: 11 additions & 11 deletions reclass/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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):
Expand Down
20 changes: 10 additions & 10 deletions reclass/values/tests/test_compitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
Expand All @@ -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, '')
Expand All @@ -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, '')
Expand All @@ -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, '')
Expand All @@ -69,22 +69,22 @@ 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)
expected = '1'

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):
Expand All @@ -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, '')
Expand All @@ -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, '')
Expand All @@ -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})
Expand Down
6 changes: 3 additions & 3 deletions reclass/values/tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)


Expand All @@ -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()
2 changes: 1 addition & 1 deletion reclass/values/tests/test_listitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 2 additions & 2 deletions reclass/values/tests/test_parser_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__':
Expand Down
6 changes: 3 additions & 3 deletions reclass/values/tests/test_refitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -34,15 +34,15 @@ 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):
reference = RefItem('', Settings({'delimiter': ':'}))

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': ':'}))
Expand Down
4 changes: 2 additions & 2 deletions reclass/values/tests/test_scaitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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)
scalar2 = ScaItem([2], SETTINGS)

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})
Expand Down
2 changes: 1 addition & 1 deletion reclass/values/tests/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eeb5aab

Please sign in to comment.