diff options
author | ThaHobbyist | 2024-05-11 17:15:25 +0530 |
---|---|---|
committer | ThaHobbyist | 2024-05-11 17:15:25 +0530 |
commit | 1c95684c5b42306d6dbb2a0a75a891470a4c4ced (patch) | |
tree | 9493178326cc1aa3eacc628d84dfd5db7a3c72a4 | |
parent | 10a163269ffd184c30b36e3863a65004f47404ca (diff) | |
download | pyvnt-1c95684c5b42306d6dbb2a0a75a891470a4c4ced.tar.gz pyvnt-1c95684c5b42306d6dbb2a0a75a891470a4c4ced.tar.bz2 pyvnt-1c95684c5b42306d6dbb2a0a75a891470a4c4ced.zip |
Added testcases for all current classes and functions in pytest
-rw-r--r-- | manual_tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc | bin | 0 -> 645 bytes | |||
-rwxr-xr-x | manual_tests/test.py (renamed from Testing/test.py) | 0 | ||||
-rwxr-xr-x | manual_tests/test_pyvnt.py (renamed from Testing/test_pyvnt.py) | 8 | ||||
-rwxr-xr-x | manual_tests/treeTest.py (renamed from pyvnt/test/treeTest.py) | 0 | ||||
-rwxr-xr-x | pyvnt/DictionaryElement/foamDS.py | 7 | ||||
-rwxr-xr-x | pyvnt/DictionaryElement/keyData.py | 7 | ||||
-rwxr-xr-x | pyvnt/Reference/basic.py | 4 | ||||
-rw-r--r-- | tests/__pycache__/test_basic.cpython-312-pytest-8.2.0.pyc | bin | 0 -> 25015 bytes | |||
-rw-r--r-- | tests/__pycache__/test_keyData.cpython-312-pytest-8.2.0.pyc | bin | 0 -> 8895 bytes | |||
-rw-r--r-- | tests/__pycache__/test_node.cpython-312-pytest-8.2.0.pyc | bin | 0 -> 9909 bytes | |||
-rw-r--r-- | tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc | bin | 0 -> 638 bytes | |||
-rw-r--r-- | tests/test_basic.py | 115 | ||||
-rw-r--r-- | tests/test_keyData.py | 57 | ||||
-rw-r--r-- | tests/test_node.py | 56 |
14 files changed, 242 insertions, 12 deletions
diff --git a/manual_tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc b/manual_tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc Binary files differnew file mode 100644 index 0000000..3463b13 --- /dev/null +++ b/manual_tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc diff --git a/Testing/test.py b/manual_tests/test.py index e98b25a..e98b25a 100755 --- a/Testing/test.py +++ b/manual_tests/test.py diff --git a/Testing/test_pyvnt.py b/manual_tests/test_pyvnt.py index fbdae29..477429e 100755 --- a/Testing/test_pyvnt.py +++ b/manual_tests/test_pyvnt.py @@ -1,10 +1,10 @@ from pyvnt import * from anytree import RenderTree, AsciiStyle -''' + prop1 = EnumProp('val1', items={'PCG', 'PBiCG', 'PBiCGStab'}, default='PCG') prop2 = EnumProp('val2', items={'PCG', 'PBiCG', 'PBiCGStab'}, default='PBiCG') -''' + # set up automated tests for CI/CD in github @@ -29,9 +29,9 @@ print(RenderTree(child1).by_attr()) ''' # Test for Keydata class singularily -''' + key1 = KeyData('solver', prop1) print(key1) -''' + diff --git a/pyvnt/test/treeTest.py b/manual_tests/treeTest.py index 656dd7d..656dd7d 100755 --- a/pyvnt/test/treeTest.py +++ b/manual_tests/treeTest.py diff --git a/pyvnt/DictionaryElement/foamDS.py b/pyvnt/DictionaryElement/foamDS.py index 9a3ca5c..542cece 100755 --- a/pyvnt/DictionaryElement/foamDS.py +++ b/pyvnt/DictionaryElement/foamDS.py @@ -1,4 +1,5 @@ from anytree import Node, RenderTree, AsciiStyle, NodeMixin +from anytree.search import find_by_attr from typing import Any, Type from pyvnt.DictionaryElement.keyData import KeyData from pyvnt.Reference.errorClasses import * @@ -109,7 +110,7 @@ class Foam(NodeMixin): ''' if pos != None: - self.data.insert(data, pos) + self.data.insert(pos, data) else: self.data.append(data) @@ -119,7 +120,7 @@ class Foam(NodeMixin): ''' try: - self.data.pop(data) + self.data.remove(data) except: raise AttributeError(f"{data.name} does not exist in this node") @@ -129,7 +130,7 @@ class Foam(NodeMixin): ''' try: - self.data.pop(data) + self.data.remove(data) self.data.insert(data, pos) except: raise AttributeError(f"{data.name} does not exist in this node") diff --git a/pyvnt/DictionaryElement/keyData.py b/pyvnt/DictionaryElement/keyData.py index 39c5c7e..894615d 100755 --- a/pyvnt/DictionaryElement/keyData.py +++ b/pyvnt/DictionaryElement/keyData.py @@ -109,7 +109,7 @@ class KeyData(KeyParent): self.__dict__[newKey] = new """ - def replaceVal(self, old: ValueProperty | str, new: ValueProperty): # uses orderedDict instead of regular Dictionary + def replaceVal(self, old: ValueProperty or str, new: ValueProperty): # uses orderedDict instead of regular Dictionary ''' Function to insert and edit values in the class object once it is created @@ -129,9 +129,10 @@ class KeyData(KeyParent): newKey = new._ValueProperty__name if oldKey == newKey: - self.__dict__[newKey] = new + # self.__dict__[newKey] = new + self._privateDict[newKey] = new else: - if newKey != oldKey and newKey in self.__dict__.keys(): + if newKey != oldKey and newKey in self._privateDict.keys(): raise KeyRepeatError(newKey) else: self._privateDict = OrderedDict([(newKey, new) if k == oldKey else (k, v) for k, v in self._privateDict.items()]) diff --git a/pyvnt/Reference/basic.py b/pyvnt/Reference/basic.py index c4a2c93..b6279de 100755 --- a/pyvnt/Reference/basic.py +++ b/pyvnt/Reference/basic.py @@ -215,7 +215,7 @@ class EnumProp(ValueProperty): Parameters: val: The option that is to be removed ''' - if val != self.default: + if val != self.__default: self.__items.remove(val) else: raise IsDefaultError(val) @@ -227,7 +227,7 @@ class EnumProp(ValueProperty): Parameters: val: The new value of the property ''' - if val in self.items: + if val in self.__items: self.__default = val else: raise ValueOutofRangeError(val) diff --git a/tests/__pycache__/test_basic.cpython-312-pytest-8.2.0.pyc b/tests/__pycache__/test_basic.cpython-312-pytest-8.2.0.pyc Binary files differnew file mode 100644 index 0000000..6e4e529 --- /dev/null +++ b/tests/__pycache__/test_basic.cpython-312-pytest-8.2.0.pyc diff --git a/tests/__pycache__/test_keyData.cpython-312-pytest-8.2.0.pyc b/tests/__pycache__/test_keyData.cpython-312-pytest-8.2.0.pyc Binary files differnew file mode 100644 index 0000000..6ad8185 --- /dev/null +++ b/tests/__pycache__/test_keyData.cpython-312-pytest-8.2.0.pyc diff --git a/tests/__pycache__/test_node.cpython-312-pytest-8.2.0.pyc b/tests/__pycache__/test_node.cpython-312-pytest-8.2.0.pyc Binary files differnew file mode 100644 index 0000000..7de7234 --- /dev/null +++ b/tests/__pycache__/test_node.cpython-312-pytest-8.2.0.pyc diff --git a/tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc b/tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc Binary files differnew file mode 100644 index 0000000..b68eaf3 --- /dev/null +++ b/tests/__pycache__/test_pyvnt.cpython-312-pytest-8.2.0.pyc diff --git a/tests/test_basic.py b/tests/test_basic.py new file mode 100644 index 0000000..acfbea4 --- /dev/null +++ b/tests/test_basic.py @@ -0,0 +1,115 @@ +import pytest + +import pyvnt.Reference.basic as basic + +class TestEnum: + def setup_method(self, method): + self.items = {'PCG', 'PBiCG', 'PBiCGStab'} + self.eprop2 = basic.EnumProp('val2', items=self.items, default='PBiCG') + self.eprop1 = basic.EnumProp('val1', items=self.items, default='PCG') + + def teardown_method(self, method): + del self.eprop1 + del self.eprop2 + del self.items + + def test_enum_print(self): + assert str(self.eprop1) == f"EnumProp(name = val1, items = {self.items}, default = PCG)" + assert str(self.eprop2) == f"EnumProp(name = val2, items = {self.items}, default = PBiCG)" + + def test_enum_val(self): + assert self.eprop1.giveVal() == 'PCG' + assert self.eprop2.giveVal() == 'PBiCG' + + def test_enum_items(self): + assert self.eprop1.get_items() == self.items + assert self.eprop2.get_items() == self.items + + def test_enum_edit(self): + dummy_items = {'PCG', 'PBiCG', 'GMRES'} + self.eprop1.setProperties('val1', dummy_items, 'PCG') + assert self.eprop1.get_items() == dummy_items + assert self.eprop1.giveVal() == 'PCG' + + def test_enum_edit_fail(self): + dummy_items = {'PCG', 'PBiCG', 'GMRES'} + with pytest.raises(basic.DefaultOutofRangeError): + self.eprop1.setProperties('val1', dummy_items, 'PBiCGStab') + + with pytest.raises(basic.NotSetType): + self.eprop1.setProperties('val1', 'PCG', 'PCG') + + with pytest.raises(basic.NotStringType): + self.eprop1.setProperties('val1', {1, 2, 3}, 'PCG') + + def test_enum_change(self): + self.eprop1.set_default('PBiCG') + assert self.eprop1.giveVal() == 'PBiCG' + + def test_enum_change_fail(self): + with pytest.raises(basic.ValueOutofRangeError): + self.eprop1.set_default('GMRES') + + def test_enum_remove(self): + self.eprop1.remove_item('PBiCGStab') + assert self.eprop1.get_items() == {'PCG', 'PBiCG'} + + def test_enum_remove_fail(self): + with pytest.raises(basic.IsDefaultError): + self.eprop1.remove_item('PCG') + +class TestInt: + def setup_method(self, method): + self.iprop1 = basic.PropertyInt('val1', 5, 1, 10) + self.iprop2 = basic.PropertyInt('val2', 100, -100, 1000) + + def teardown_method(self, method): + del self.iprop1 + del self.iprop2 + + def test_int_print(self): + assert str(self.iprop1) == f"PropertyInt(name = val1, default = 5, minimum = 1, maximum = 10)" + assert str(self.iprop2) == f"PropertyInt(name = val2, default = 100, minimum = -100, maximum = 1000)" + + def test_int_edit(self): + self.iprop1.setProperties('val1', 10, 1, 10) + assert self.iprop1.giveVal() == 10 + + def test_int_edit_fail(self): + with pytest.raises(basic.DefaultOutofRangeError): + self.iprop1.setProperties('val1', 0, 1, 10) + + with pytest.raises(basic.InvalidRangeError): + self.iprop1.setProperties('val1', 2, 5, 1) + + def test_int_val(self): + assert self.iprop1.giveVal() == 5 + assert self.iprop2.giveVal() == 100 + +class TestFloat: + def setup_method(self, method): + self.fprop1 = basic.PropertyFloat('val1', 5.0, 1.0, 10.0) + self.fprop2 = basic.PropertyFloat('val2', 100.0, -100.0, 1000.0) + + def teardown_method(self, method): + del self.fprop1 + del self.fprop2 + + def test_float_print(self): + assert str(self.fprop1) == f"PropertyFloat(name = val1, default = 5.0, minimum = 1.0, maximum = 10.0)" + assert str(self.fprop2) == f"PropertyFloat(name = val2, default = 100.0, minimum = -100.0, maximum = 1000.0)" + + def test_float_edit(self): + self.fprop1.setProperties('val1', 10.0, 1.0, 10.0) + assert self.fprop1.giveVal() == 10.0 + + def test_float_edit_fail(self): + with pytest.raises(basic.DefaultOutofRangeError): + self.fprop1.setProperties('val1', 0.0, 1.0, 10.0) + + with pytest.raises(basic.InvalidRangeError): + self.fprop1.setProperties('val1', 2.0, 5.0, 1.0) + + def test_float_val(self): + assert self.fprop1.giveVal() == 5.0 + assert self.fprop2.giveVal() == 100.0
\ No newline at end of file diff --git a/tests/test_keyData.py b/tests/test_keyData.py new file mode 100644 index 0000000..ed8a687 --- /dev/null +++ b/tests/test_keyData.py @@ -0,0 +1,57 @@ +import pytest + +import pyvnt.DictionaryElement.keyData as keyData +from pyvnt.Reference.basic import * + +class TestKeyData: + def setup_method(self, method): + self.items = {'PCG', 'PBiCG', 'PBiCGStab'} + self.prop2 = EnumProp('val2', items=self.items, default='PBiCG') + self.prop1 = EnumProp('val1', items=self.items, default='PCG') + self.key1 = keyData.KeyData('solver', self.prop1, self.prop2) + + def teardown_method(self, method): + del self.key1 + del self.prop1 + del self.prop2 + del self.items + + def test_keyData_print(self): + assert str(self.key1) == f"KeyData(val1 : {str(self.prop1)}, val2 : {str(self.prop2)}, )" + + def test_keyData_val(self): + assert self.key1.giveVal() == f"solver : {self.prop1.giveVal()}, {self.prop2.giveVal()}, " + + def test_keyData_edit(self): + tmp_prop1 = PropertyInt('tmpval1', 2, 1, 10) + tmp_prop2 = PropertyInt('tmpval2', 3, 1, 10) + + self.key1.replaceVal('val1', tmp_prop1) + assert self.key1.giveVal() == f"solver : {tmp_prop1.giveVal()}, {self.prop2.giveVal()}, " + + self.key1.replaceVal(self.prop2, tmp_prop2) + assert self.key1.giveVal() == f"solver : {tmp_prop1.giveVal()}, {tmp_prop2.giveVal()}, " + + tmp_prop3 = PropertyInt('tmpval2', 4, 1, 10) + + self.key1.replaceVal(tmp_prop2, tmp_prop3) + assert self.key1.giveVal() == f"solver : {tmp_prop1.giveVal()}, {tmp_prop3.giveVal()}, " + + def test_keyData_edit_fail(self): + tmp_prop1 = PropertyInt('tmpval1', 2, 1, 10) + tmp_prop2 = PropertyInt('tmpval2', 3, 1, 10) + tmp_prop3 = PropertyInt('tmpval2', 4, 1, 10) + + with pytest.raises(keyData.KeyRepeatError): + self.key1.replaceVal('val1', tmp_prop1) + self.key1.replaceVal('val2', tmp_prop1) + + with pytest.raises(keyData.KeyRepeatError): + self.key1.replaceVal('val2', tmp_prop2) + self.key1.replaceVal('val2', tmp_prop3) + + def test_keyData_del(self): + self.key1.delVal('val1') + assert self.key1.giveVal() == f"solver : {self.prop2.giveVal()}, " + +
\ No newline at end of file diff --git a/tests/test_node.py b/tests/test_node.py new file mode 100644 index 0000000..8c0fa32 --- /dev/null +++ b/tests/test_node.py @@ -0,0 +1,56 @@ +import pytest + +from pyvnt import * + +class TestNode: + def setup_method(self, method): + self.items = {'PCG', 'PBiCG', 'PBiCGStab'} + + self.eprop2 = EnumProp('val2', items=self.items, default='PBiCG') + self.eprop1 = EnumProp('val1', items=self.items, default='PCG') + + self.key1 = KeyData('solver', self.eprop1, self.eprop2) + self.key2 = KeyData('solver2', self.eprop2, self.eprop1) + + self.head = Foam("test_head", None, None) + self.chld1 = Foam("test_child", self.head, None, self.key2) + self.chld2 = Foam("test_child2", None, None) + + def teardown_method(self, method): + del self.head + del self.key1 + del self.eprop1 + del self.eprop2 + del self.items + + @pytest.mark.skip(reason = 'Complex to test') + def test_node_print(self): + assert str(self.head) == f"Foam(name : test_head, parent : None, children : ({self.chld1}, {self.chld2}, ), data : ({self.key1}, ), )" + + def test_node_add_child(self): + self.head.addChild(self.chld2) + assert self.head.children == (self.chld1, self.chld2, ) + + def test_node_set_parent(self): + self.chld2.setParent(self.head) + assert self.chld2.parent == self.head + + def test_node_get_child(self): + assert self.head.getChild('test_child') == self.chld1 + + def test_node_add_data(self): + self.chld2.addData(self.key2) + assert self.chld2.data == [self.key2] + + self.chld2.addData(self.key1, 0) + assert self.chld2.data == [self.key1, self.key2] + + def test_node_remove_data(self): + self.chld1.removeData(self.key2) + assert self.chld1.data == [] + + @pytest.mark.skip(reason = 'Complex to test') + def test_node_terminal_display(self): + pass + +
\ No newline at end of file |