Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue 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
caosdb
Software
CaosDB Crawler
Commits
837846d4
Commit
837846d4
authored
7 months ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
TST: Add unit tests for handle_value with units
parent
a8c7279d
No related branches found
No related tags found
2 merge requests
!198
REL: Release 0.10.0
,
!187
F unit
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caoscrawler/converters/converters.py
+12
-8
12 additions, 8 deletions
src/caoscrawler/converters/converters.py
unittests/test_converters.py
+4
-0
4 additions, 0 deletions
unittests/test_converters.py
with
16 additions
and
8 deletions
src/caoscrawler/converters/converters.py
+
12
−
8
View file @
837846d4
...
...
@@ -169,13 +169,19 @@ Parameters
----------
value: Union[dict, str, list]
- If *str*, the value to be interpreted. E.g.
"
4
"
,
"
hello
"
or
"
$a
"
etc.
- If *str*, the value to be interpreted. E.g.
"
4
"
,
"
hello
"
or
"
$a
"
etc. No unit is set and collection mode is determined from the
first character:
-
'
+
'
corresponds to
"
list
"
-
'
*
'
corresponds to
"
multiproperty
"
- everything else is
"
single
"
- If *dict*, it must have a ``value`` key and may ``unit``, and
``collection_mode``. The returned tuple is directly created from
the corresponding values whereby unit defaults to None and
collection_mode defaults to
"
single
"
.
- If *list*, each element is checked for replacement and the resulting list will be used
as (list) value for the property
the corresponding values if they are given; ``unit`` defaults to
None and ``collection_mode`` is determined from ``value`` as
explained for the str case above.
- If *list*, each element is checked for replacement and the
resulting list will be used as (list) value for the property
Returns
-------
...
...
@@ -197,7 +203,7 @@ out: tuple
raise
NotImplementedError
(
f
"
This definition has no
\"
value
\"
:
{
value
}
"
)
propvalue
=
value
[
"
value
"
]
if
"
unit
"
in
value
:
propunit
=
value
[
"
unit
"
]
propunit
=
replace_variables
(
value
[
"
unit
"
]
,
values
)
# can be "single", "list" or "multiproperty"
if
"
collection_mode
"
in
value
:
collection_mode
=
value
[
"
collection_mode
"
]
...
...
@@ -237,8 +243,6 @@ out: tuple
return
(
propvalue
,
propunit
,
collection_mode
)
propvalue
=
replace_variables
(
propvalue
,
values
)
if
propunit
:
propunit
=
replace_variables
(
propunit
,
values
)
return
(
propvalue
,
propunit
,
collection_mode
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_converters.py
+
4
−
0
View file @
837846d4
...
...
@@ -384,9 +384,13 @@ def test_variable_replacement():
# Unit specified in the same way as value:
assert
handle_value
({
"
value
"
:
5
,
"
unit
"
:
"
m
"
},
values
)
==
(
5
,
"
m
"
,
"
single
"
)
assert
handle_value
({
"
value
"
:
5
,
"
unit
"
:
"
${my_unit}
"
},
values
)
==
(
5
,
"
m
"
,
"
single
"
)
assert
handle_value
({
"
value
"
:
"
+5
"
,
"
unit
"
:
"
${my_unit}
"
},
values
)
==
(
"
5
"
,
"
m
"
,
"
list
"
)
assert
handle_value
({
"
value
"
:
"
*5
"
,
"
unit
"
:
"
${my_unit}
"
},
values
)
==
(
"
5
"
,
"
m
"
,
"
multiproperty
"
)
assert
handle_value
([
"
a
"
,
"
b
"
],
values
)
==
([
"
a
"
,
"
b
"
],
None
,
"
single
"
)
assert
handle_value
([
"
$a
"
,
"
$b
"
],
values
)
==
([
4
,
"
68
"
],
None
,
"
single
"
)
assert
handle_value
({
"
value
"
:
[
"
$a
"
,
"
$a
"
],
"
unit
"
:
"
${my_unit}
"
},
values
)
==
([
4
,
4
],
"
m
"
,
"
single
"
)
def
test_apply_transformers
(
converter_registry
):
...
...
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