Skip to content

Commit

Permalink
Merge pull request #53 from davidvlaminck/generated_class_dict
Browse files Browse the repository at this point in the history
Generated class dict
  • Loading branch information
davidvlaminck authored Nov 21, 2024
2 parents 7b74a82 + 050182a commit 7016b01
Show file tree
Hide file tree
Showing 28 changed files with 8,479 additions and 335 deletions.
53 changes: 13 additions & 40 deletions UnitTests/GeneralTests/Instantiation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from UnitTests.TestModel.OtlmowModel.Classes.Onderdeel.AnotherTestClass import AnotherTestClass
from otlmow_model.OtlmowModel.BaseClasses.OTLObject import dynamic_create_instance_from_uri, \
dynamic_create_instance_from_ns_and_name, dynamic_create_type_from_uri, dynamic_create_type_from_ns_and_name
from otlmow_model.OtlmowModel.Helpers.generated_lists import get_hardcoded_class_dict

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -75,46 +76,18 @@ def test_instantiate_test_and_real_classes_using_dynamic_import():

@pytest.mark.filterwarnings("ignore::DeprecationWarning")
@pytest.mark.timeout(300)
def test_instantiate_all_classes(subtests):
classes_to_instantiate = {}

class_location = Path(ROOT_DIR) / '../../otlmow_model/OtlmowModel/Classes/'
installatie_location = class_location / 'Installatie'
onderdeel_location = class_location / 'Onderdeel'
levenscyclus_location = class_location / 'Levenscyclus'
proefenmeting_location = class_location / 'ProefEnMeting'

for dir_location in {installatie_location, onderdeel_location, levenscyclus_location, proefenmeting_location}:
for f in os.listdir(dir_location):
if not isfile(dir_location / f):
continue
class_name = f[:-3]
classes_to_instantiate[class_name] = (dir_location.stem, class_name)

classes_to_instantiate['Agent'] = (None, 'Agent')
classes_to_instantiate['ActivityComplex'] = ('ImplementatieElement', 'ActivityComplex')
classes_to_instantiate['ElectricityAppurtenance'] = ('ImplementatieElement', 'ElectricityAppurtenance')
classes_to_instantiate['Derdenobject'] = ('ImplementatieElement', 'Derdenobject')
classes_to_instantiate['ElectricityCable'] = ('ImplementatieElement', 'ElectricityCable')
classes_to_instantiate['Pipe'] = ('ImplementatieElement', 'Pipe')
classes_to_instantiate['TelecommunicationsAppurtenance'] = ('ImplementatieElement', 'TelecommunicationsAppurtenance')
classes_to_instantiate['TelecommunicationsCable'] = ('ImplementatieElement', 'TelecommunicationsCable')


# # use multithreading
# executor = ThreadPoolExecutor(8)
# futures = [executor.submit(subtest_instantiate, namespace=namespace, class_name=class_name, subtests=subtests)
# for namespace, class_name in classes_to_instantiate.values()]
# concurrent.futures.wait(futures)

for namespace, class_name in classes_to_instantiate.values():
subtest_instantiate(namespace, class_name, subtests)


def subtest_instantiate(namespace, class_name, subtests):
with subtests.test(msg=f'Trying to instantiate {class_name}'):
instance = dynamic_create_instance_from_ns_and_name(namespace, class_name)
assert instance is not None
def test_instantiate_all_classes_using_class_dict(subtests):
classes_to_instantiate = [uri for uri, class_dict in get_hardcoded_class_dict().items() if not class_dict['abstract']]
# use multithreading
executor = ThreadPoolExecutor(8)
futures = [executor.submit(subtest_instantiate, uri=uri, subtests=subtests) for uri in classes_to_instantiate]
concurrent.futures.wait(futures)

def subtest_instantiate(uri: str, subtests):
with subtests.test(msg=uri):
instance = dynamic_create_instance_from_uri(uri)
instance.fill_with_dummy_data()
assert instance is not None, f'failed to instantiate {uri}'



4 changes: 2 additions & 2 deletions UnitTests/TestModel/OtlmowModel/Helpers/OTLObjectHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ def verify_asset_id_is_unique_within_list(dict_list: List[Dict]) -> bool:

def is_relation(otl_object: OTLObject, model_directory=Path(__file__).parent.parent.parent) -> bool:
type_uri = otl_object.typeURI
relation_dict = get_hardcoded_relation_dict()
relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
if type_uri in relation_dict:
return True


def is_directional_relation(otl_object: OTLObject, model_directory=Path(__file__).parent.parent.parent) -> bool:
type_uri = otl_object.typeURI
relation_dict = get_hardcoded_relation_dict()
relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
relation_info = relation_dict.get(type_uri)
if relation_info is None:
return False
Expand Down
6 changes: 6 additions & 0 deletions UnitTests/TestModel/OtlmowModel/Helpers/all_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from otlmow_model.OtlmowModel.BaseClasses.MetaInfo import *
from otlmow_model.OtlmowModel.BaseClasses.OTLObject import *
from otlmow_model.OtlmowModel.Helpers.GenericHelper import *
from otlmow_model.OtlmowModel.Helpers.OTLObjectHelper import *
from otlmow_model.OtlmowModel.Helpers.RelationCreator import *
from otlmow_model.OtlmowModel.Helpers.RelationValidator import *
78 changes: 74 additions & 4 deletions UnitTests/TestModel/OtlmowModel/generated_info.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,78 @@
{
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#Voedt": {
"directional": true
"relations": {
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#Voedt": {
"directional": true
},
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#Bevestiging": {
"directional": false
}
},
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#Bevestiging": {
"directional": false
"classes": {
"https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#AIMDBStatus": {
"abstract": true,
"name": "AIMDBStatus",
"label": "AIM databank status",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#AIMObject": {
"abstract": true,
"name": "AIMObject",
"label": "AIM object",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#AIMToestand": {
"abstract": true,
"name": "AIMToestand",
"label": "AIM Toestand",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#DirectioneleRelatie": {
"abstract": true,
"name": "DirectioneleRelatie",
"label": "Directionele relatie",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#NietDirectioneleRelatie": {
"abstract": true,
"name": "NietDirectioneleRelatie",
"label": "Niet-directionele relatie",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#RelatieObject": {
"abstract": true,
"name": "RelatieObject",
"label": "Relatieobject",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#AllCasesTestClass": {
"abstract": false,
"name": "AllCasesTestClass",
"label": "All Cases TestClass",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#AnotherTestClass": {
"abstract": false,
"name": "AnotherTestClass",
"label": "Another TestClass",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#Bevestiging": {
"abstract": false,
"name": "Bevestiging",
"label": "Bevestiging",
"deprecated_version": ""
},
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#DeprecatedTestClass": {
"abstract": false,
"name": "DeprecatedTestClass",
"label": "Deprecated TestClass",
"deprecated_version": "2.0.0"
},
"https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#Voedt": {
"abstract": false,
"name": "Voedt",
"label": "Voedt",
"deprecated_version": ""
}
}
}
Loading

0 comments on commit 7016b01

Please sign in to comment.