Skip to content

Commit 66d0d48

Browse files
authored
Merge pull request #40 from bci-oss/main
Reuse JAVA SDK models for testing (fix)
2 parents 10a4af1 + 331e500 commit 66d0d48

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

core/esmf-aspect-meta-model-python/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,20 @@ aspect = model_elements[0]
109109

110110
SAMMUnitsGraph is a class contains functions for accessing units of measurement.
111111
```python
112-
from esmf_aspect_meta_model_python.samm_meta_model import SammUnitsGraph
112+
from esmf_aspect_meta_model_python.samm_meta_model import units
113113

114-
units_graph = SammUnitsGraph()
115-
unit_data = units_graph.get_info("unit:volt")
114+
unit_name = "unit:volt"
115+
units.print_description(units.get_info(unit_name))
116+
# preferredName: volt
117+
# commonCode: VLT
118+
# ...
119+
# symbol: V
120+
121+
# Get unit data as dictionary
122+
volt_info = units.get_info("unit:volt")
116123
# {'preferredName': rdflib.term.Literal('volt', lang='en'), 'commonCode': rdflib.term.Literal('VLT'), ... }
117124

118-
units_graph.print_description(unit_data)
125+
units.print_description(volt_info)
119126
# preferredName: volt
120127
# commonCode: VLT
121128
# ...

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_meta_model.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,20 @@ def get_info(self, unit: str) -> Dict:
8181

8282
return unit_data
8383

84-
def print_description(self, unit_data: Dict, tabs: int = 0):
84+
def print_info(self, unit_data: Dict, tabs: int = 0):
8585
"""Pretty print a unit data."""
8686
for key, value in unit_data.items():
8787
if isinstance(value, dict):
8888
print("\t" * tabs + f"{key}:")
89-
self.print_description(value, tabs + 1)
89+
self.print_info(value, tabs + 1)
9090
elif isinstance(value, list):
9191
print("\t" * tabs + f"{key}:")
9292
for node in value:
9393
for key, sub_value in node.items():
9494
print("\t" * (tabs + 1) + f"{key}:")
95-
self.print_description(sub_value, tabs + 2)
95+
self.print_info(sub_value, tabs + 2)
9696
else:
9797
print("\t" * tabs + f"{key}: {value}")
98+
99+
100+
units = SammUnitsGraph()

core/esmf-aspect-meta-model-python/scripts/download_test_models.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ def get_resources_folder_path() -> str:
2929
return models_path
3030

3131

32-
def clear_folder():
32+
def clear_folder(resources_folder):
3333
"""Remove all files to clear test models directory."""
34-
resources_folder = get_resources_folder_path()
35-
36-
if exists(resources_folder) or len(listdir(resources_folder)) != 0:
34+
if exists(resources_folder) and len(listdir(resources_folder)) != 0:
3735
shutil.rmtree(resources_folder)
3836

3937
mkdir(resources_folder)
@@ -66,7 +64,7 @@ def download_test_models(version: str = Const.JAVA_CLI_VERSION):
6664
jar_file_path = join(resources_folder, jar_file_name)
6765

6866
print(f"Remove previous version of test models from the folder {resources_folder}")
69-
clear_folder()
67+
clear_folder(resources_folder)
7068

7169
print(f"Start downloading esmf-test-aspect-models version {version}")
7270
download_jar_file(jar_file_path)

0 commit comments

Comments
 (0)