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
66173ba1
Commit
66173ba1
authored
2 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: added unit tests for macro expansion during cfood loading
parent
ecabc99f
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!53
Release 0.1
,
!25
F macros
Pipeline
#28570
failed
2 years ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caoscrawler/crawl.py
+1
-1
1 addition, 1 deletion
src/caoscrawler/crawl.py
unittests/test_macros.py
+68
-0
68 additions, 0 deletions
unittests/test_macros.py
with
69 additions
and
1 deletion
src/caoscrawler/crawl.py
+
1
−
1
View file @
66173ba1
...
@@ -235,7 +235,7 @@ class Crawler(object):
...
@@ -235,7 +235,7 @@ class Crawler(object):
if
len
(
crawler_definitions
)
==
1
:
if
len
(
crawler_definitions
)
==
1
:
# Simple case, just one document:
# Simple case, just one document:
crawler_definition
=
crawler_definitions
[
0
]
crawler_definition
=
crawler_definitions
[
0
]
elif
len
(
crawler_definition
)
==
2
:
elif
len
(
crawler_definition
s
)
==
2
:
crawler_definition
=
crawler_definitions
[
1
]
crawler_definition
=
crawler_definitions
[
1
]
else
:
else
:
raise
RuntimeError
(
"
Crawler definition must not contain more than two documents.
"
)
raise
RuntimeError
(
"
Crawler definition must not contain more than two documents.
"
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_macros.py
+
68
−
0
View file @
66173ba1
...
@@ -24,6 +24,10 @@
...
@@ -24,6 +24,10 @@
from
caoscrawler.macros
import
defmacro_constructor
,
macro_constructor
from
caoscrawler.macros
import
defmacro_constructor
,
macro_constructor
from
caoscrawler.macros.macro_yaml_object
import
macro_store
from
caoscrawler.macros.macro_yaml_object
import
macro_store
from
caoscrawler.crawl
import
Crawler
from
tempfile
import
NamedTemporaryFile
import
yaml
import
yaml
import
pytest
import
pytest
...
@@ -142,6 +146,70 @@ testnode: !macro
...
@@ -142,6 +146,70 @@ testnode: !macro
assert
dat
[
"
testnode
"
][
"
replaced3
"
]
==
"
ok
"
assert
dat
[
"
testnode
"
][
"
replaced3
"
]
==
"
ok
"
def
temp_file_load
(
txt
:
str
):
"""
Create a temporary file with txt and load the crawler
definition using load_definition from Crawler.
"""
definition
=
None
with
NamedTemporaryFile
()
as
f
:
f
.
write
(
txt
.
encode
())
f
.
flush
()
c
=
Crawler
()
definition
=
c
.
load_definition
(
f
.
name
)
return
definition
def
test_load_definition
(
register_macros
,
macro_store_reset
):
txt
=
"""
extroot:
type: Directory
match: extroot
subtree:
SimulationData:
type: Directory
match: SimulationData
"""
# Check whether simple cfoods can be loaded:
cfood
=
temp_file_load
(
txt
)
assert
cfood
[
"
extroot
"
][
"
subtree
"
][
"
SimulationData
"
][
"
match
"
]
==
"
SimulationData
"
cfood
=
temp_file_load
(
"""
---
metadata:
macros:
- !defmacro
name: test_one
params: {}
definition:
replaced1: ok
- !defmacro
name: test_two
params:
match_name: null
definition:
type: Directory
match: $match_name
---
extroot:
type: Directory
match: extroot
subtree:
SimulationData:
type: Directory
match: SimulationData
extroot2: !macro # test top level macro
test_one:
extroot3:
subtree:
SimulationData: !macro
test_two:
match_name: SimulationData
"""
)
assert
cfood
[
"
extroot
"
][
"
subtree
"
][
"
SimulationData
"
][
"
match
"
]
==
"
SimulationData
"
assert
cfood
[
"
extroot2
"
][
"
replaced1
"
]
==
"
ok
"
assert
cfood
[
"
extroot3
"
][
"
subtree
"
][
"
SimulationData
"
][
"
match
"
]
==
"
SimulationData
"
@pytest.mark.xfail
@pytest.mark.xfail
def
test_replace_arbitrary_objects
(
register_macros
,
macro_store_reset
):
def
test_replace_arbitrary_objects
(
register_macros
,
macro_store_reset
):
"""
"""
...
...
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