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
c3ead4ad
Commit
c3ead4ad
authored
5 months ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Plain Diff
Merge branch 'f-casting-transformers' into ruqad
parents
dddf26d9
716ec67e
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!217
TST: Make NamedTemporaryFiles Windows-compatible
Pipeline
#59612
passed
4 months ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
src/caoscrawler/validator.py
+12
-9
12 additions, 9 deletions
src/caoscrawler/validator.py
with
14 additions
and
9 deletions
CHANGELOG.md
+
2
−
0
View file @
c3ead4ad
...
...
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-
ZipFileConverter that opens zip files and exposes their contents as
File and Directory structure elements.
-
`linkahead-crawler`
script as alias for
`caosdb-crawler`
.
-
New transformers of the form
`cast_to_*`
which allow casting variables to
`int`
,
`float`
,
`str`
and
`bool`
.
### Changed ###
...
...
This diff is collapsed.
Click to expand it.
src/caoscrawler/validator.py
+
12
−
9
View file @
c3ead4ad
...
...
@@ -123,12 +123,14 @@ def convert_record(record: db.Record):
return
_apply_schema_patches
(
pobj
)
def
validate
(
records
:
list
[
db
.
Record
],
schemas
:
dict
[
str
,
dict
])
->
list
[
tuple
[
bool
,
list
]
]:
def
validate
(
records
:
list
[
db
.
Record
],
schemas
:
dict
[
str
,
dict
])
->
list
[
tuple
]:
"""
Validate a list of records against a list of possible JSON schemas.
It is tried to validate each schema from the list of schemas. If none of them validates
without error, it is assumed that it does not match at all.
Validate a list of records against a dictionary of schemas.
The keys of the dictionary are record types and the corresponding values are json schemata
associated with that record type. The current implementation assumes that each record that is
checked has exactly one parent and raises an error if that is not the case.
The schema belonging to a record is identified using the name of the first (and only) parent
of the record.
Arguments:
----------
...
...
@@ -136,15 +138,16 @@ def validate(records: list[db.Record], schemas: dict[str, dict]) -> list[tuple[b
records: list[db.Record]
List of records that will be validated.
schemas:
list[
dict]
A
list
of JSON schemas generated using `load_json_schema_from_datamodel_yaml`.
schemas:
dict[str,
dict]
A
dictionary
of JSON schemas generated using `load_json_schema_from_datamodel_yaml`.
Returns:
--------
A list of tuples, one element for each record:
- Index 0: A boolean that determines whether at least one schema matched for this record.
- Index 1: A list of schemas matching the record at this position of the list `records`.
- Index 0: A boolean that determines whether the schema belonging to the record type of the
record matched.
- Index 1: A validation error if the schema did not match or None otherwise.
"""
retval
=
[]
...
...
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