Skip to content

Commit

Permalink
isinstance unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvlaminck committed Nov 23, 2023
1 parent 485a284 commit 125c62d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions UnitTests/GeneralTests/OTLObject_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

from UnitTests.TestClasses.Classes.ImplementatieElement.AIMObject import AIMObject
from UnitTests.TestClasses.Classes.Onderdeel.AllCasesTestClass import AllCasesTestClass
from UnitTests.TestClasses.Classes.Onderdeel.AnotherTestClass import AnotherTestClass
from UnitTests.TestClasses.Classes.Onderdeel.Bevestiging import Bevestiging
from otlmow_model.BaseClasses.OTLObject import OTLObject, create_dict_from_asset
from otlmow_model.Exceptions.NonStandardAttributeWarning import NonStandardAttributeWarning
from otlmow_model.Helpers import AssetCreator
from otlmow_model.warnings.IncorrectTypeWarning import IncorrectTypeWarning


Expand Down Expand Up @@ -975,3 +977,20 @@ def test_raise_value_errors_in_set_waarde_with_cardinality():
instance = AllCasesTestClass()
with pytest.raises(ValueError):
instance.testKeuzelijstMetKard = ['1']


def test_isinstance_checks():
instance = AllCasesTestClass()
dynamically_created_instance = AssetCreator.dynamic_create_instance_from_uri(
AllCasesTestClass.typeURI, model_directory='UnitTests.TestClasses')
assert isinstance(instance, AllCasesTestClass)
assert instance.typeURI == AllCasesTestClass.typeURI
assert isinstance(instance, AIMObject)
assert not isinstance(instance, AnotherTestClass)

assert dynamically_created_instance.typeURI == AllCasesTestClass.typeURI
assert isinstance(dynamically_created_instance, AllCasesTestClass)
assert isinstance(dynamically_created_instance, AIMObject)
assert not isinstance(dynamically_created_instance, AnotherTestClass)

# TODO if fails: implement class.__instancecheck__(self, instance)

0 comments on commit 125c62d

Please sign in to comment.