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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
04d65a35
Commit
04d65a35
authored
2 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: added examples from the documentation as tests
parent
a1e3407c
No related branches found
No related tags found
2 merge requests
!71
REL: RElease v0.2.0
,
!51
F better macro doc
Pipeline
#29172
passed with warnings
2 years ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_macros.py
+84
-1
84 additions, 1 deletion
unittests/test_macros.py
with
84 additions
and
1 deletion
unittests/test_macros.py
+
84
−
1
View file @
04d65a35
...
@@ -53,6 +53,7 @@ def _temp_file_load(txt: str):
...
@@ -53,6 +53,7 @@ def _temp_file_load(txt: str):
f
.
write
(
txt
.
encode
())
f
.
write
(
txt
.
encode
())
f
.
flush
()
f
.
flush
()
c
=
Crawler
()
c
=
Crawler
()
print
(
txt
)
definition
=
c
.
load_definition
(
f
.
name
)
definition
=
c
.
load_definition
(
f
.
name
)
return
definition
return
definition
...
@@ -295,7 +296,6 @@ extroot3: !macro
...
@@ -295,7 +296,6 @@ extroot3: !macro
assert
cfood
[
"
extroot3
"
][
"
test_four
"
]
is
None
assert
cfood
[
"
extroot3
"
][
"
test_four
"
]
is
None
# @pytest.mark.xfail(reason="Fix multiple usage of the same macro.")
def
test_use_macro_twice
():
def
test_use_macro_twice
():
"""
Test that the same macro can be used twice with different parameters in
"""
Test that the same macro can be used twice with different parameters in
the same CFood element if the name depends on the parameters.
the same CFood element if the name depends on the parameters.
...
@@ -328,3 +328,86 @@ extroot: !macro
...
@@ -328,3 +328,86 @@ extroot: !macro
assert
cfood
[
"
extroot
"
][
"
once
"
][
"
something
"
][
"
a
"
]
==
"
4
"
assert
cfood
[
"
extroot
"
][
"
once
"
][
"
something
"
][
"
a
"
]
==
"
4
"
assert
cfood
[
"
extroot
"
][
"
twice
"
][
"
something
"
][
"
a
"
]
==
"
5
"
assert
cfood
[
"
extroot
"
][
"
twice
"
][
"
something
"
][
"
a
"
]
==
"
5
"
assert
cfood
[
"
extroot
"
][
"
default_name
"
][
"
something
"
][
"
a
"
]
==
"
4
"
assert
cfood
[
"
extroot
"
][
"
default_name
"
][
"
something
"
][
"
a
"
]
==
"
4
"
# Code sample to generate the expanded macro:
# with open("expanded_test_macro.yaml", "w") as f:
# f.write(yaml.dump(cfood))
def
test_documentation_example_2
():
cfood
=
_temp_file_load
(
"""
---
metadata:
macros:
- !defmacro
name: MarkdownFile
params:
name: null
filename: null
definition:
${name}_filename:
type: SimpleFile
match: $filename
records:
$name:
parents:
- MarkdownFile
role: File
path: ${name}_filename
file: ${name}_filename
---
ExperimentalData:
type: Directory
match: ExperimentalData
subtree: !macro
MarkdownFile:
- name: README
filename: ^README.md$
"""
)
# Code sample to generate the expanded macro:
# with open("expanded_test_macro.yaml", "w") as f:
# f.write(yaml.dump(cfood))
def
test_documentation_example_1
():
cfood
=
_temp_file_load
(
"""
---
metadata:
macros:
- !defmacro
name: SimulationDatasetFile
params:
match: null
recordtype: null
nodename: null
definition:
$nodename:
match: $match
type: SimpleFile
records:
File:
parents:
- $recordtype
role: File
path: $$$nodename
file: $$$nodename
Simulation:
$recordtype: +$File
---
SimulationData:
type: Directory
match: SimulationData
subtree: !macro
SimulationDatasetFile:
- match: .*
recordtype: DatasetFile
nodename: Dataset
"""
)
# Code sample to generate the expanded macro:
# with open("expanded_test_macro.yaml", "w") as f:
# f.write(yaml.dump(cfood))
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