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
e6958c63
Commit
e6958c63
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: added tests for validation of schema for crawler definition yaml files
parent
3a5e6063
No related branches found
No related tags found
1 merge request
!53
Release 0.1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/newcrawler/crawl.py
+16
-6
16 additions, 6 deletions
src/newcrawler/crawl.py
unittests/test_schema.py
+29
-0
29 additions, 0 deletions
unittests/test_schema.py
with
45 additions
and
6 deletions
src/newcrawler/crawl.py
+
16
−
6
View file @
e6958c63
...
...
@@ -154,11 +154,10 @@ class Crawler(object):
self
.
debug_metadata
[
"
provenance
"
]
=
defaultdict
(
lambda
:
dict
())
self
.
debug_metadata
[
"
usage
"
]
=
defaultdict
(
lambda
:
set
())
def
crawl_directory
(
self
,
dirname
:
str
,
crawler_definition_path
:
str
):
"""
Crawl a single directory.
Convenience function that starts the crawler (calls start_crawling)
with a single cirectory as the StructureElement.
def
load_definition
(
self
,
crawler_definition_path
:
str
):
"""
Load a cfood from a crawler definition defined by
crawler definition path and validate it using cfood-schema.yml.
"""
# Load the cfood from a yaml file:
...
...
@@ -170,6 +169,17 @@ class Crawler(object):
schema
=
yaml
.
safe_load
(
f
)
validate
(
instance
=
crawler_definition
,
schema
=
schema
[
"
cfood
"
])
return
crawler_definition
def
crawl_directory
(
self
,
dirname
:
str
,
crawler_definition_path
:
str
):
"""
Crawl a single directory.
Convenience function that starts the crawler (calls start_crawling)
with a single directory as the StructureElement.
"""
crawler_definition
=
self
.
load_definition
(
crawler_definition_path
)
self
.
start_crawling
(
Directory
(
os
.
path
.
basename
(
dirname
),
dirname
),
crawler_definition
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_schema.py
0 → 100644
+
29
−
0
View file @
e6958c63
#!/bin/python
# Tests for schema validation
# A. Schlemmer, 06/2021
import
caosdb
as
db
from
os.path
import
join
,
dirname
from
newcrawler
import
Crawler
import
pytest
from
pytest
import
raises
from
jsonschema.exceptions
import
ValidationError
def
rfp
(
*
pathcomponents
):
"""
Return full path.
Shorthand convenience function.
"""
return
join
(
dirname
(
__file__
),
*
pathcomponents
)
def
test_schema_validation
():
cr
=
Crawler
()
cr
.
load_definition
(
rfp
(
"
scifolder_cfood.yml
"
))
cr
.
load_definition
(
rfp
(
"
scifolder_extended.yml
"
))
with
raises
(
ValidationError
,
match
=
"
.*enum.*
"
):
cr
.
load_definition
(
rfp
(
"
broken_cfoods
"
,
"
broken1.yml
"
))
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