Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dccQuantities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DigitalDynamicMeasurement
dccQuantities
Commits
169f8f67
Commit
169f8f67
authored
4 months ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
added fisr version of serilizer test
parent
24ba052a
No related branches found
No related tags found
No related merge requests found
Pipeline
#52113
failed
4 months ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/DccQuantityType.py
+2
-2
2 additions, 2 deletions
src/DccQuantityType.py
tests/test_SiRealList.py
+2
-1
2 additions, 1 deletion
tests/test_SiRealList.py
tests/test_serilizer.py
+85
-0
85 additions, 0 deletions
tests/test_serilizer.py
with
89 additions
and
3 deletions
src/DccQuantityType.py
+
2
−
2
View file @
169f8f67
...
...
@@ -4,7 +4,7 @@ from numpy.ma.core import shape
import
numpy
as
np
from
AbstractQuantityTypeData
import
AbstractQuantityTypeData
from
typing
import
Union
from
helpers
import
format_slice
,
ensureList
from
helpers
import
format_slice
,
ensureList
from
DccName
import
DccName
class
DccQuantityType
:
...
...
@@ -180,5 +180,5 @@ class DccQuantityType:
else
:
result
[
key
]
=
value
# TODO: This should not happen, maybe add a warning?
return
result
return
{
'
dcc:quantity
'
:
result
}
This diff is collapsed.
Click to expand it.
tests/test_SiRealList.py
+
2
−
1
View file @
169f8f67
...
...
@@ -529,4 +529,5 @@ def test_div_SiRealList():
"
test1/test2c
"
,
"
test1/test2d
"
,
]
assert
result
.
hasSameValue
([
ufloat
(
0.02
),
ufloat
(
0.22
),
ufloat
(
1.1
),
ufloat
(
5.5
)])
\ No newline at end of file
assert
result
.
hasSameValue
([
ufloat
(
0.02
),
ufloat
(
0.22
),
ufloat
(
1.1
),
ufloat
(
5.5
)])
This diff is collapsed.
Click to expand it.
tests/test_serilizer.py
0 → 100644
+
85
−
0
View file @
169f8f67
from
__future__
import
annotations
# for type annotation recursion
from
typing
import
Union
# from pathlib import Path
import
warnings
import
json
import
pytest
import
os
from
dccQuantityParser
import
parse
print
(
"
TESTING test_parser.py
"
)
print
(
os
.
getcwd
())
# Print current working directory
from
testHelpers
import
get_test_file
from
helpers
import
dccTypeCollector
from
dccXMLJSONConv.dccConv
import
XMLToDict
,
get_from_dict
from
json
import
dumps
,
loads
def
convertToListOfStr
(
data
:
Union
(
object
,
List
[
object
]))
->
List
[
str
]:
if
isinstance
(
data
,
list
):
return
[
str
(
item
)
for
item
in
data
]
else
:
return
[
str
(
data
)]
quantityDataKeysWUnit
=
{
'
si:real
'
,
'
si:hybrid
'
,
'
si:complex
'
,
'
si:constant
'
,
'
si:realListXMLList
'
,
'
si:complexListXMLList
'
,
'
si:hybridListXMLList
'
,
'
si:constantListXMLList
'
}
quantityDataKeysWOUnit
=
[
'
dcc:noQuantity
'
,
'
dcc:charsXMLList
'
]
def
test_basic
():
# Use the correct relative paths
try
:
test_file
=
get_test_file
(
"
tests
"
,
"
data
"
,
"
simpleSineCalibration.xml
"
)
with
open
(
test_file
,
"
r
"
)
as
xml_file
:
xml_data
=
xml_file
.
read
()
# parse XML to Json
jsonDict
,
errors
=
XMLToDict
(
xml_data
)
# get dccQuantities
quantityDict
=
dccTypeCollector
(
jsonDict
)
dccQunats
=
parse
(
xml_data
)
except
FileNotFoundError
as
e
:
warnings
.
warn
(
str
(
e
))
serilizedData
=
[]
for
q
in
dccQunats
:
serilizedData
.
append
(
q
.
toJsonDict
())
# check if the first key is 'dcc:qunatity'
for
i
,
serilized
in
enumerate
(
serilizedData
):
inputJsonData
=
quantityDict
[
i
][
1
]
# Test name
assert
serilized
[
'
dcc:name
'
]
==
inputJsonData
[
'
dcc:name
'
]
# Test unit
#TODO reconsider this test strategy may be it would convert to json str and than with normal json loads back to have the str casting done
matching_QuantityTypesWUnit
=
list
(
set
(
quantityDataKeysWUnit
)
&
set
(
inputJsonData
.
keys
()))
if
len
(
matching_QuantityTypesWUnit
)
==
1
:
quantType
=
matching_QuantityTypesWUnit
[
0
]
isList
=
True
if
quantType
.
endswith
(
'
XMLList
'
)
else
False
suffix
=
'
XMLList
'
if
isList
else
''
outData
=
serilized
[
quantType
]
strOutData
=
json
.
dumps
(
outData
)
inData
=
inputJsonData
[
quantType
]
# test for same unit since we know we must have a unit
# we don't serilize to str only data but everything musst castable in str and then be equal
if
'
si:unit
'
+
suffix
in
inData
.
keys
()
and
'
si:unit
'
+
suffix
in
outData
.
keys
():
if
not
isList
:
print
(
outData
[
'
si:unit
'
+
suffix
])
assert
str
(
outData
[
'
si:unit
'
+
suffix
])
==
inData
[
'
si:unit
'
+
suffix
]
else
:
print
(
convertToListOfStr
(
outData
[
'
si:unit
'
+
suffix
]))
assert
convertToListOfStr
(
outData
[
'
si:unit
'
+
suffix
])
==
inData
[
'
si:unit
'
+
suffix
]
else
:
raise
KeyError
(
"
Unit not found in or out test data But we know we must have a unit in both.
"
)
# test for same data
# okay this is rather ahrd to implent so we will go over the json dumps way....
"""
if
'
si:value
'
+suffix in inData.keys() and
'
si:value
'
+suffix in outData.keys():
if not isList:
assert outData[
'
si:value
'
]==inData[
'
si:value
'
]
else:
assert outData[
'
si:value
'
+suffix].value==inData[
'
si:value
'
+suffix]
else:
raise KeyError(
"
Data not found in or out test data But we know we must have a data in both.
"
)
"""
# there was no unit so i must have a quantity without unit
elif
len
(
matching_QuantityTypesWUnit
)
==
0
:
matching_QuantityTypesWOUnit
=
list
(
set
(
quantityDataKeysWOUnit
)
&
set
(
inputJsonData
.
keys
()))
assert
len
(
matching_QuantityTypesWOUnit
)
==
1
else
:
raise
ValueError
(
"
There should be only one quantity type with unit
"
)
assert
False
# we should never get here
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment