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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
80cc116c
Commit
80cc116c
authored
2 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
TST: Add test for validating custom converter definitions
parent
d34f0bfa
No related branches found
No related tags found
2 merge requests
!53
Release 0.1
,
!47
F fix two doc validation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_converters.py
+45
-8
45 additions, 8 deletions
unittests/test_converters.py
with
45 additions
and
8 deletions
unittests/test_converters.py
+
45
−
8
View file @
80cc116c
...
...
@@ -23,12 +23,17 @@
"""
test the converters module
"""
import
importlib
import
os
import
pytest
import
yaml
from
caoscrawler.converters
import
Converter
from
caoscrawler.converters
import
(
Converter
,
ConverterValidationError
,
DictConverter
,
DirectoryConverter
,
handle_value
,
MarkdownFileConverter
,
JSONFileConverter
)
from
caoscrawler.crawl
import
Crawler
from
caoscrawler.stores
import
GeneralStore
from
caoscrawler.converters
import
(
ConverterValidationError
,
DictConverter
,
DirectoryConverter
,
handle_value
,
MarkdownFileConverter
,
JSONFileConverter
)
from
caoscrawler.structure_elements
import
(
File
,
DictTextElement
,
DictListElement
,
DictElement
,
DictBooleanElement
,
DictDictElement
,
...
...
@@ -37,10 +42,6 @@ from caoscrawler.structure_elements import (File, DictTextElement,
from
test_tool
import
rfp
import
pytest
import
os
import
importlib
@pytest.fixture
def
converter_registry
():
...
...
@@ -348,3 +349,39 @@ def test_filter_children_of_directory(converter_registry):
with
pytest
.
raises
(
RuntimeError
):
children
=
dc
.
create_children
(
None
,
test_dir
)
def
test_validate_custom_converters
():
one_doc_yaml
=
"""
Converters:
MyNewType:
converter: MyNewTypeConverter
package: some_package.my_converters
MyElement:
type: MyNewType
match: something
"""
crawler1
=
Crawler
()
one_doc_definitions
=
crawler1
.
_load_definition_from_yaml_dict
(
[
yaml
.
load
(
one_doc_yaml
,
Loader
=
yaml
.
SafeLoader
)])
assert
"
MyElement
"
in
one_doc_definitions
assert
one_doc_definitions
[
"
MyElement
"
][
"
type
"
]
==
"
MyNewType
"
# this has to be equivalent
two_doc_yaml
=
"""
---
metadata:
Converters:
MyNewType:
converter: MyNewTypeConverter
package: some_package.my_converters
---
MyElement:
type: MyNewType
match: something
"""
crawler2
=
Crawler
()
two_doc_definitions
=
crawler2
.
_load_definition_from_yaml_dict
(
list
(
yaml
.
safe_load_all
(
two_doc_yaml
)))
assert
"
MyElement
"
in
two_doc_definitions
assert
two_doc_definitions
[
"
MyElement
"
][
"
type
"
]
==
one_doc_definitions
[
"
MyElement
"
][
"
type
"
]
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