Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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-pylib
Commits
da04056f
Verified
Commit
da04056f
authored
5 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
TST: _parse_value when datatype is an entity
parent
734c5e50
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/common/models.py
+18
-17
18 additions, 17 deletions
src/caosdb/common/models.py
unittests/test_datatype.py
+11
-0
11 additions, 0 deletions
unittests/test_datatype.py
with
29 additions
and
17 deletions
src/caosdb/common/models.py
+
18
−
17
View file @
da04056f
...
@@ -992,25 +992,26 @@ def _parse_value(datatype, value):
...
@@ -992,25 +992,26 @@ def _parse_value(datatype, value):
return
value
return
value
# deal with collections
# deal with collections
matcher
=
re
.
compile
(
r
"
^(?P<col>[^<]+)<(?P<dt>[^>]+)>$
"
)
if
isinstance
(
datatype
,
str
):
m
=
matcher
.
match
(
datatype
)
matcher
=
re
.
compile
(
r
"
^(?P<col>[^<]+)<(?P<dt>[^>]+)>$
"
)
if
m
:
m
=
matcher
.
match
(
datatype
)
col
=
m
.
group
(
"
col
"
)
if
m
:
dt
=
m
.
group
(
"
dt
"
)
col
=
m
.
group
(
"
col
"
)
dt
=
m
.
group
(
"
dt
"
)
if
col
==
"
LIST
"
:
ret
=
list
()
if
col
==
"
LIST
"
:
else
:
ret
=
list
()
return
value
else
:
return
value
if
hasattr
(
value
,
"
__iter__
"
)
and
not
isinstance
(
value
,
str
):
if
hasattr
(
value
,
"
__iter__
"
)
and
not
isinstance
(
value
,
str
):
for
v
in
value
:
for
v
in
value
:
ret
.
append
(
_parse_value
(
dt
,
v
))
ret
.
append
(
_parse_value
(
dt
,
v
))
else
:
else
:
# put a single value into a list since the datatype says so.
# put a single value into a list since the datatype says so.
ret
.
append
(
_parse_value
(
dt
,
value
))
ret
.
append
(
_parse_value
(
dt
,
value
))
return
ret
return
ret
# This is for a special case, where the xml parser could not differentiate
# This is for a special case, where the xml parser could not differentiate
# between single values and lists with one element. As
# between single values and lists with one element. As
...
...
This diff is collapsed.
Click to expand it.
unittests/test_datatype.py
+
11
−
0
View file @
da04056f
...
@@ -77,3 +77,14 @@ def test_parsing_of_references():
...
@@ -77,3 +77,14 @@ def test_parsing_of_references():
entity
=
db
.
Record
(
name
=
"
bla
"
)
entity
=
db
.
Record
(
name
=
"
bla
"
)
assert
id
(
_parse_value
(
dtype
,
entity
))
==
id
(
entity
)
assert
id
(
_parse_value
(
dtype
,
entity
))
==
id
(
entity
)
dtype
=
db
.
RecordType
(
name
=
"
Person
"
)
assert
_parse_value
(
dtype
,
"
Anna Lytik
"
)
==
"
Anna Lytik
"
assert
_parse_value
(
None
,
"
Anna Lytik
"
)
==
"
Anna Lytik
"
assert
_parse_value
(
dtype
,
"
2345@sdfg
"
)
==
"
2345@sdfg
"
assert
_parse_value
(
dtype
,
"
2345
"
)
==
2345
assert
_parse_value
(
dtype
,
2345
)
==
2345
entity
=
db
.
Record
(
name
=
"
bla
"
)
assert
id
(
_parse_value
(
dtype
,
entity
))
==
id
(
entity
)
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