Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
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-advanced-user-tools
Commits
8909f28d
Commit
8909f28d
authored
3 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
add conversion
parent
a108328b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!22
Release 0.3
,
!14
F fix list
Pipeline
#10433
passed
3 years ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/models/parser.py
+15
-3
15 additions, 3 deletions
src/caosadvancedtools/models/parser.py
unittests/test_parser.py
+6
-1
6 additions, 1 deletion
unittests/test_parser.py
with
21 additions
and
4 deletions
src/caosadvancedtools/models/parser.py
+
15
−
3
View file @
8909f28d
...
...
@@ -192,7 +192,7 @@ class Parser(object):
self
.
_add_entity_to_model
(
name
,
entity
)
# initialize recordtypes
self
.
_set_recordtypes
()
self
.
_check_datatypes
()
self
.
_check_
and_convert_
datatypes
()
for
name
,
entity
in
ymlmodel
.
items
():
self
.
_treat_entity
(
name
,
entity
,
line
=
ymlmodel
[
"
__line__
"
])
...
...
@@ -384,7 +384,7 @@ class Parser(object):
raise
e
self
.
treated
.
append
(
name
)
def
_check_datatypes
(
self
):
def
_check_
and_convert_
datatypes
(
self
):
"""
checks if datatype is valid.
datatype of properties is simply initialized with string. Here, we
iterate over properties and check whether it is a base datatype of a
...
...
@@ -395,13 +395,19 @@ class Parser(object):
if
isinstance
(
value
,
db
.
Property
):
dtype
=
value
.
datatype
is_list
=
False
if
_get_listdatatype
(
value
.
datatype
)
is
not
None
:
dtype
=
_get_listdatatype
(
value
.
datatype
)
is_list
=
True
if
dtype
in
self
.
model
:
if
is_list
:
value
.
datatype
=
db
.
LIST
(
self
.
model
[
dtype
])
else
:
value
.
datatype
=
self
.
model
[
dtype
]
continue
# get the datatype
if
dtype
in
[
db
.
DOUBLE
,
db
.
REFERENCE
,
...
...
@@ -411,7 +417,13 @@ class Parser(object):
db
.
FILE
,
db
.
BOOLEAN
]:
if
is_list
:
value
.
datatype
=
db
.
LIST
(
db
.
__getattribute__
(
dtype
))
else
:
value
.
datatype
=
db
.
__getattribute__
(
dtype
)
continue
raise
ValueError
(
"
Unknown Datatype.
"
)
def
_set_recordtypes
(
self
):
...
...
This diff is collapsed.
Click to expand it.
unittests/test_parser.py
+
6
−
1
View file @
8909f28d
...
...
@@ -200,9 +200,14 @@ RT1:
recommended_properties:
a:
datatype: LIST(RT2)
b:
datatype: LIST(TEXT)
RT2:
"""
parse_model_from_yaml
(
to_file
(
string
))
model
=
parse_model_from_yaml
(
to_file
(
string
))
self
.
assertTrue
(
isinstance
(
model
[
'
b
'
],
db
.
Property
))
self
.
assertEqual
(
model
[
'
b
'
].
datatype
,
db
.
LIST
(
db
.
TEXT
))
# This failed for an older version of caosdb-models
string_list
=
"""
...
...
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