-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from FOSSEE/testcases
Added testcases and github actions
- Loading branch information
Showing
15 changed files
with
277 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This workflow will install Python dependencies and run tests with a variety of Python versions | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Package testing | ||
|
||
on: | ||
push: | ||
branches: [ "main", "dev" ] | ||
pull_request: | ||
branches: [ "main", "dev" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install pytest anytree setuptools wheel | ||
python setup.py sdist bdist_wheel | ||
python setup.py install | ||
- name: Test with pytest | ||
run: | | ||
pytest -v |
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()}, " | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|