Commit af649c62 authored by Philipp Reuber's avatar Philipp Reuber
Browse files

add tests

parent b6739aa9
Pipeline #233538 failed
......@@ -25,3 +25,13 @@ documentation:
- documentation
tags:
- docker
test:pytest:
stage: test
variables:
PYTHONPATH: "build/Source/Python:Source/Python"
script:
- pytest -v tests
image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV}
tags:
- docker
\ No newline at end of file
......@@ -14,5 +14,7 @@ if __name__ == '__main__':
'chevron',
'sphinx',
'sphinx_rtd_theme',
'pytest',
'pytest-check'
]
)
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cim="http://iec.ch/TC57/2012/CIM-schema-cim16#" xmlns:md="http://iec.ch/TC57/61970-552/ModelDescription/1#" xmlns:entsoe="http://entsoe.eu/Secretariat/ProfileExtension/2#" xmlns:neplan="http://www.neplan.ch#" >
<md:FullModel rdf:about="Slack_Trafo_Load">
<md:Model.created>03/12/2019 15:38:12</md:Model.created>
<md:FullModel rdf:about="Test">
<md:Model.created>27/01/2020 18:45:27</md:Model.created>
<md:Model.modelingAuthoritySet>www.acs.eonerc.rwth-aachen.de</md:Model.modelingAuthoritySet>
<md:Model.profile>DiagramLayout</md:Model.profile>
</md:FullModel>
......
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cim="http://iec.ch/TC57/2012/CIM-schema-cim16#" xmlns:md="http://iec.ch/TC57/61970-552/ModelDescription/1#" xmlns:entsoe="http://entsoe.eu/Secretariat/ProfileExtension/2#" xmlns:neplan="http://www.neplan.ch#" >
<md:FullModel rdf:about="Slack_Trafo_Load">
<md:Model.created>03/12/2019 15:38:12</md:Model.created>
<md:FullModel rdf:about="Test">
<md:Model.created>27/01/2020 18:45:27</md:Model.created>
<md:Model.modelingAuthoritySet>www.acs.eonerc.rwth-aachen.de</md:Model.modelingAuthoritySet>
<md:Model.profile>Equipment</md:Model.profile>
</md:FullModel>
......
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cim="http://iec.ch/TC57/2012/CIM-schema-cim16#" xmlns:md="http://iec.ch/TC57/61970-552/ModelDescription/1#" xmlns:entsoe="http://entsoe.eu/Secretariat/ProfileExtension/2#" xmlns:neplan="http://www.neplan.ch#" >
<md:FullModel rdf:about="Slack_Trafo_Load">
<md:Model.created>03/12/2019 15:38:12</md:Model.created>
<md:FullModel rdf:about="Test">
<md:Model.created>27/01/2020 18:45:27</md:Model.created>
<md:Model.modelingAuthoritySet>www.acs.eonerc.rwth-aachen.de</md:Model.modelingAuthoritySet>
<md:Model.profile>StateVariables</md:Model.profile>
</md:FullModel>
......
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cim="http://iec.ch/TC57/2012/CIM-schema-cim16#" xmlns:md="http://iec.ch/TC57/61970-552/ModelDescription/1#" xmlns:entsoe="http://entsoe.eu/Secretariat/ProfileExtension/2#" xmlns:neplan="http://www.neplan.ch#" >
<md:FullModel rdf:about="Slack_Trafo_Load">
<md:Model.created>03/12/2019 15:38:12</md:Model.created>
<md:FullModel rdf:about="Test">
<md:Model.created>27/01/2020 18:45:27</md:Model.created>
<md:Model.modelingAuthoritySet>www.acs.eonerc.rwth-aachen.de</md:Model.modelingAuthoritySet>
<md:Model.profile>Topology</md:Model.profile>
</md:FullModel>
......
......@@ -7,38 +7,87 @@ import pickle
logging.basicConfig(filename='Test.log', level=logging.INFO, filemode='w')
short_profile_name = {
"DiagramLayout": 'DI',
"Dynamics": "DY",
"Equipment": "EQ",
"GeographicalLocation": "GL",
"StateVariables": "SV",
"SteadyStateHypothesis": "SSH",
"Topology": "TP"
}
example_path = os.path.join('..',
os.path.join('examples',
os.path.join('sampledata',
os.path.join('CIGRE_MV',
'CIGRE_MV_Rudion_With_LoadFlow_Results'))))
def test_export():
test_files = [r".\Test_DiagramLayout.xml",
r".\Test_Equipment.xml",
r".\Test_StateVariables.xml",
r".\Test_Topology.xml", ]
import_files = [os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_DI.xml'),
os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_EQ.xml'),
os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_SV.xml'),
os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_TP.xml'), ]
activeProfileList = ['DI', 'EQ', 'SV', 'TP']
imported_files, namespaces = cimpy.cim_import(test_files, 'cgmes_v2_4_15')
imported_files, namespaces = cimpy.cim_import(import_files, 'cgmes_v2_4_15')
cimpy.cim_export(imported_files, namespaces, 'EXPORTED_Test', 'cgmes_v2_4_15', activeProfileList)
test_dict = {}
for file in test_files:
xmlstring = open(file, encoding='utf8').read()
parsed_export_file = xmltodict.parse(xmlstring, attr_prefix="$", cdata_key="_", dict_constructor=dict)
test_dict.update(parsed_export_file['rdf:RDF'])
test_list = []
for file in os.listdir(os.getcwd()):
if '.xml' in file and 'EXPORTED' not in file:
xmlstring = open(file, encoding='utf8').read()
parsed_export_file = xmltodict.parse(xmlstring, attr_prefix="$", cdata_key="_", dict_constructor=dict)
test_list.append(parsed_export_file['rdf:RDF'])
export_dict = {}
export_list = []
for file in os.listdir(os.getcwd()):
if file.endswith(".xml") and 'EXPORTED' in str(file):
xmlstring = open(file, encoding='utf8').read()
parsed_export_file = xmltodict.parse(xmlstring, attr_prefix="$", cdata_key="_", dict_constructor=dict)
export_dict.update(parsed_export_file['rdf:RDF'])
export_list.append(parsed_export_file['rdf:RDF'])
for key in test_dict.keys():
if 'cim:' in key:
if key in export_dict.keys():
# if key in ['cim:PowerTransformerEnd', 'cim:OperationalLimitType', 'cim:Diagram']:
# continue
for elem in test_dict[key]:
check.is_in(elem, export_dict[key])
export_dict = {}
for export_file in export_list:
profile = export_file['md:FullModel']['md:Model.profile']
for key in short_profile_name.keys():
if key in profile:
export_dict[key] = export_file
test_dict = {}
for elem in test_list:
profile = elem['md:FullModel']['md:Model.profile']
for key in short_profile_name.keys():
if key in profile:
test_dict[key] = elem
for profile, current_test_dict in test_dict.items():
check.is_in(profile, export_dict.keys())
if profile in export_dict.keys():
current_export_dict = export_dict[profile]
for class_key in current_test_dict:
if 'cim:' not in class_key or 'cim:NameType' in class_key:
continue
check.is_in(class_key, current_export_dict.keys())
if class_key in current_export_dict.keys():
current_export_class = current_export_dict[class_key]
current_test_class = current_test_dict[class_key]
if isinstance(current_test_class, list):
for item in current_test_class:
check.is_in(item, current_export_class)
else:
check.equal(current_test_class, current_export_class)
# for key in test_dict.keys():
# if 'cim:' in key:
# if key in export_dict.keys():
# # if key in ['cim:PowerTransformerEnd', 'cim:OperationalLimitType', 'cim:Diagram']:
# # continue
# for elem in test_dict[key]:
# check.is_in(elem, export_dict[key])
for file in os.listdir(os.getcwd()):
if 'EXPORTED' in str(file):
......@@ -46,10 +95,10 @@ def test_export():
def test_import():
test_files = [r".\Test_DiagramLayout.xml",
r".\Test_Equipment.xml",
r".\Test_StateVariables.xml",
r".\Test_Topology.xml", ]
test_files = [os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_DI.xml'),
os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_EQ.xml'),
os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_SV.xml'),
os.path.join(example_path, 'Rootnet_FULL_NE_24J13h_TP.xml'), ]
imported_files, _ = cimpy.cim_import(test_files, 'cgmes_v2_4_15')
......@@ -59,3 +108,5 @@ def test_import():
for elem in import_resolved:
check.is_in(elem, check_dict_pickle)
test_export()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment