Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
CIM
CIMpy
Commits
6e780f37
Commit
6e780f37
authored
Jan 29, 2020
by
Philipp Reuber
Browse files
split tests into separate stages, modify tests
parent
a620a7aa
Pipeline
#234428
failed with stages
in 1 minute and 17 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
6e780f37
variables
:
DOCKER_TAG_DEV
:
${CI_COMMIT_REF_NAME}
DOCKER_IMAGE_DEV
:
cimpy
stages
:
-
prepare
-
generate
-
test
-
test-import
-
test-export-with-imported-files
-
test-export-with-exported-files
docker
:
stage
:
prepare
...
...
@@ -27,13 +30,32 @@ documentation:
tags
:
-
docker
test:pytest:
stage
:
test
test:import:
stage
:
test-import
variables
:
PYTHONPATH
:
"
build/Source/Python:Source/Python"
script
:
-
pytest -v test_import.py
image
:
${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV}
tags
:
-
docker
test:export-with-imported-files:
stage
:
test-export-with-imported-files
variables
:
PYTHONPATH
:
"
build/Source/Python:Source/Python"
script
:
-
pytest -v test_export_with_imported_files.py
image
:
${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV}
tags
:
-
docker
test:export-export:
stage
:
test-export-with-exported-files
variables
:
PYTHONPATH
:
"
build/Source/Python:Source/Python"
script
:
-
python3 ../setup.py develop
-
pytest -v tests.py
-
pytest -v test_export_with_exported_files.py
image
:
${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV}
tags
:
-
docker
\ No newline at end of file
cimpy/cgmes_v2_4_15/OperationalLimitType.py
View file @
6e780f37
...
...
@@ -24,7 +24,7 @@ class OperationalLimitType(IdentifiedObject):
__doc__
+=
'
\n
Documentation of parent class IdentifiedObject:
\n
'
+
IdentifiedObject
.
__doc__
def
__init__
(
self
,
OperationalLimit
=
"list"
,
acceptableDuration
=
0.
0
,
limitType
=
None
,
direction
=
None
,
*
args
,
**
kw_args
):
def
__init__
(
self
,
OperationalLimit
=
"list"
,
acceptableDuration
=
0
,
limitType
=
None
,
direction
=
None
,
*
args
,
**
kw_args
):
super
().
__init__
(
*
args
,
**
kw_args
)
self
.
OperationalLimit
=
OperationalLimit
...
...
tests/
Test
_DiagramLayout.xml
→
tests/
CIGREMV_reference_cgmes_v2_4_15
_DiagramLayout.xml
View file @
6e780f37
File moved
tests/
Test
_Equipment.xml
→
tests/
CIGREMV_reference_cgmes_v2_4_15
_Equipment.xml
View file @
6e780f37
...
...
@@ -170,12 +170,12 @@
</cim:SubGeographicalRegion>
<cim:OperationalLimitType
rdf:ID=
"_d50aa23d-94a0-4462-a895-6bec6f7b89af"
>
<cim:IdentifiedObject.name>
PATL
</cim:IdentifiedObject.name>
<cim:OperationalLimitType.acceptableDuration>
45000
.0
</cim:OperationalLimitType.acceptableDuration>
<cim:OperationalLimitType.acceptableDuration>
45000
</cim:OperationalLimitType.acceptableDuration>
<cim:OperationalLimitType.direction>
absoluteValue
</cim:OperationalLimitType.direction>
</cim:OperationalLimitType>
<cim:OperationalLimitType
rdf:ID=
"_182e44b2-641d-4502-b36d-1949f49a90ea"
>
<cim:IdentifiedObject.name>
TATL
</cim:IdentifiedObject.name>
<cim:OperationalLimitType.acceptableDuration>
60
.0
</cim:OperationalLimitType.acceptableDuration>
<cim:OperationalLimitType.acceptableDuration>
60
</cim:OperationalLimitType.acceptableDuration>
<cim:OperationalLimitType.direction>
absoluteValue
</cim:OperationalLimitType.direction>
</cim:OperationalLimitType>
<cim:EnergyConsumer
rdf:ID=
"Load7-I"
>
...
...
tests/
Test
_StateVariables.xml
→
tests/
CIGREMV_reference_cgmes_v2_4_15
_StateVariables.xml
View file @
6e780f37
File moved
tests/
Test
_Topology.xml
→
tests/
CIGREMV_reference_cgmes_v2_4_15
_Topology.xml
View file @
6e780f37
File moved
tests/tests.py
→
tests/test
_export_with_exported_file
s.py
View file @
6e780f37
...
...
@@ -3,9 +3,8 @@ import cimpy
import
xmltodict
import
os
import
pytest_check
as
check
import
pickle
logging
.
basicConfig
(
filename
=
'Test.log'
,
level
=
logging
.
INFO
,
filemode
=
'w'
)
logging
.
basicConfig
(
filename
=
'Test
_export_with_exported_files
.log'
,
level
=
logging
.
INFO
,
filemode
=
'w'
)
short_profile_name
=
{
"DiagramLayout"
:
'DI'
,
...
...
@@ -85,118 +84,3 @@ def test_export_with_exported_files():
for
file
in
os
.
listdir
(
os
.
getcwd
()):
if
'EXPORTED'
in
str
(
file
):
os
.
remove
(
file
)
# def test_export_with_imported_files():
# 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(import_files, 'cgmes_v2_4_15')
# cimpy.cim_export(imported_files, namespaces, 'EXPORTED_Test', 'cgmes_v2_4_15', activeProfileList)
#
# test_list = []
# for file in import_files:
# 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_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_list.append(parsed_export_file['rdf:RDF'])
#
# 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]
# test_mRIDs = []
# test_class_dict = {}
# if isinstance(current_test_class, list):
# for obj in current_test_class:
# test_mRIDs.append(obj['$rdf:ID'])
# test_class_dict[obj['$rdf:ID']] = obj
# else:
# test_mRIDs.append(current_test_class['$rdf:ID'])
# test_class_dict[current_test_class['$rdf:ID']] = current_test_class
#
# export_mRIDs = []
# export_class_dict = {}
# if isinstance(current_export_class, list):
# for obj in current_export_class:
# export_mRIDs.append(obj['$rdf:ID'])
# export_class_dict[obj['$rdf:ID']] = obj
# else:
# export_mRIDs.append(current_export_class['$rdf:ID'])
# export_class_dict[current_export_class['$rdf:ID']] = current_export_class
#
# for mRID in test_mRIDs:
# check.is_in(mRID, export_mRIDs)
# if mRID in export_mRIDs:
# test_attr = test_class_dict[mRID].items()
# export_attr = export_class_dict[mRID].items()
# for item in test_attr:
# if item[0] is 'cim:NameType':
# continue
# if item[1] in ['0', '0e+000', '0.0', '', 'false', 'None', 'list']:
# continue
# if isinstance(item[1], dict):
# test_item = item
# elif len(item[1].split('.')) > 1:
# try:
# test_item = (item[0], str(float(item[1])))
# except ValueError:
# continue
# except TypeError:
# pass
# else:
# test_item = item
#
# check.is_in(test_item, export_attr)
#
#
# for file in os.listdir(os.getcwd()):
# if 'EXPORTED' in str(file):
# os.remove(file)
def
test_import
():
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'
)
import_resolved
=
cimpy
.
cimexport
.
_get_class_attributes_with_references
(
imported_files
,
'cgmes_v2_4_15'
)
check_dict_pickle
=
pickle
.
load
(
open
(
'CIGREMV_import_reference_cgmes_v2_4_15.p'
,
'rb'
))
for
elem
in
import_resolved
:
check
.
is_in
(
elem
,
check_dict_pickle
)
tests/test_export_with_imported_files.py
0 → 100644
View file @
6e780f37
import
logging
import
cimpy
import
xmltodict
import
os
import
pytest_check
as
check
logging
.
basicConfig
(
filename
=
'Test_export_with_imported_files.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_with_imported_files
():
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
(
import_files
,
'cgmes_v2_4_15'
)
cimpy
.
cim_export
(
imported_files
,
namespaces
,
'EXPORTED_Test'
,
'cgmes_v2_4_15'
,
activeProfileList
)
test_list
=
[]
for
file
in
import_files
:
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_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_list
.
append
(
parsed_export_file
[
'rdf:RDF'
])
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
class_key
in
[
'cim:NameType'
,
'cim:Name'
]:
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
]
test_mRIDs
=
[]
test_class_dict
=
{}
if
isinstance
(
current_test_class
,
list
):
for
obj
in
current_test_class
:
try
:
test_mRIDs
.
append
(
obj
[
'$rdf:ID'
])
test_class_dict
[
obj
[
'$rdf:ID'
]]
=
obj
except
KeyError
:
try
:
test_mRIDs
.
append
(
obj
[
'$rdf:about'
])
test_class_dict
[
obj
[
'$rdf:about'
]]
=
obj
except
KeyError
:
check
.
is_in
(
'$rdf:about'
,
obj
.
keys
())
check
.
is_in
(
'$rdf:ID'
,
obj
.
keys
())
else
:
try
:
test_mRIDs
.
append
(
current_test_class
[
'$rdf:ID'
])
test_class_dict
[
current_test_class
[
'$rdf:ID'
]]
=
current_test_class
except
KeyError
:
try
:
test_mRIDs
.
append
(
current_test_class
[
'$rdf:about'
])
test_class_dict
[
current_test_class
[
'$rdf:about'
]]
=
obj
except
KeyError
:
check
.
is_in
(
'$rdf:about'
,
current_test_class
.
keys
())
check
.
is_in
(
'$rdf:ID'
,
current_test_class
.
keys
())
export_mRIDs
=
[]
export_class_dict
=
{}
if
isinstance
(
current_export_class
,
list
):
for
obj
in
current_export_class
:
try
:
export_mRIDs
.
append
(
obj
[
'$rdf:ID'
])
export_class_dict
[
obj
[
'$rdf:ID'
]]
=
obj
except
KeyError
:
try
:
export_mRIDs
.
append
(
obj
[
'$rdf:about'
])
export_class_dict
[
obj
[
'$rdf:about'
]]
=
obj
except
KeyError
:
check
.
is_in
(
'$rdf:about'
,
obj
.
keys
())
check
.
is_in
(
'$rdf:ID'
,
obj
.
keys
())
else
:
try
:
export_mRIDs
.
append
(
current_export_class
[
'$rdf:ID'
])
export_class_dict
[
current_export_class
[
'$rdf:ID'
]]
=
current_export_class
except
KeyError
:
try
:
export_mRIDs
.
append
(
current_export_class
[
'$rdf:about'
])
export_class_dict
[
current_export_class
[
'$rdf:about'
]]
=
obj
except
KeyError
:
check
.
is_in
(
'$rdf:about'
,
current_export_class
.
keys
())
check
.
is_in
(
'$rdf:ID'
,
current_export_class
.
keys
())
for
mRID
in
test_mRIDs
:
check
.
is_in
(
mRID
,
export_mRIDs
)
if
mRID
in
export_mRIDs
:
test_attr
=
test_class_dict
[
mRID
].
items
()
export_attr
=
export_class_dict
[
mRID
].
items
()
for
item
in
test_attr
:
if
item
[
0
]
in
[
'cim:NameType'
,
'cim:ExternalNetworkInjection.referencePriority'
,
'cim:Terminal.connected'
,
'cim:PowerTransformerEnd.connectionKind'
,
'cim:OperationalLimitType.direction'
,
'cim:Diagram.orientation'
]:
continue
elif
item
[
0
]
==
'cim:Terminal.sequenceNumber'
:
test_item
=
'cim:ACDCTerminal.sequenceNumber'
else
:
test_item
=
item
[
0
]
if
item
[
1
]
in
[
'0'
,
'0e+000'
,
'0.0'
,
''
,
'false'
,
'None'
,
'list'
,
{
'$rdf:resource'
:
'#_32d6d32e-c3f0-43d4-8103-079a15594fc6'
}]:
continue
if
isinstance
(
item
[
1
],
dict
):
test_item
=
item
elif
len
(
item
[
1
].
split
(
'.'
))
>
1
:
try
:
test_item
=
(
item
[
0
],
str
(
float
(
item
[
1
])))
except
ValueError
:
continue
except
TypeError
:
pass
elif
item
[
1
]
==
'true'
:
test_item
=
(
test_item
,
'True'
)
else
:
test_item
=
(
test_item
,
item
[
1
])
check
.
is_in
(
test_item
,
export_attr
)
for
file
in
os
.
listdir
(
os
.
getcwd
()):
if
'EXPORTED'
in
str
(
file
):
os
.
remove
(
file
)
\ No newline at end of file
tests/test_import.py
0 → 100644
View file @
6e780f37
import
logging
import
cimpy
import
os
import
pytest_check
as
check
import
pickle
logging
.
basicConfig
(
filename
=
'Test_import.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_import
():
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'
)
import_resolved
=
cimpy
.
cimexport
.
_get_class_attributes_with_references
(
imported_files
,
'cgmes_v2_4_15'
)
check_dict_pickle
=
pickle
.
load
(
open
(
'CIGREMV_import_reference_cgmes_v2_4_15.p'
,
'rb'
))
for
elem
in
import_resolved
:
check
.
is_in
(
elem
,
check_dict_pickle
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment