Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Validata
Validata Core
Commits
c4ff054e
Commit
c4ff054e
authored
Nov 09, 2021
by
Pierre Dittgen
Browse files
Add tests
parent
9d387437
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_task_errors.py
0 → 100644
View file @
c4ff054e
import
pytest
from
validata_core
import
validate
@
pytest
.
fixture
()
def
schema_with_orphan_custom_check
():
return
{
"$schema"
:
"https://frictionlessdata.io/schemas/table-schema.json"
,
"fields"
:
[
{
"name"
:
"siren"
,
"title"
:
"Numéro SIREN"
,
"type"
:
"string"
,
}
],
"custom_checks"
:
[
{
"name"
:
"french-siren-value"
,
"params"
:
{
"column"
:
"sirene"
}}
],
}
@
pytest
.
fixture
()
def
schema_with_unknown_custom_check
():
return
{
"$schema"
:
"https://frictionlessdata.io/schemas/table-schema.json"
,
"fields"
:
[
{
"name"
:
"siren"
,
"title"
:
"Numéro SIREN"
,
"type"
:
"string"
,
}
],
"custom_checks"
:
[{
"name"
:
"foo-siren-value"
,
"params"
:
{
"column"
:
"sirene"
}}],
}
@
pytest
.
fixture
()
def
schema_with_non_existing_primary_key
():
return
{
"$schema"
:
"https://frictionlessdata.io/schemas/table-schema.json"
,
"fields"
:
[
{
"name"
:
"a"
,
}
],
"primaryKey"
:
[
"b"
],
}
@
pytest
.
fixture
()
def
schema_with_existing_primary_key
():
return
{
"$schema"
:
"https://frictionlessdata.io/schemas/table-schema.json"
,
"fields"
:
[
{
"name"
:
"a"
,
}
],
"primaryKey"
:
[
"a"
],
}
def
test_schema_with_orphan_custom_checks
(
schema_with_orphan_custom_check
):
source
=
[[
"siren"
],
[
"529173189"
]]
report
=
validate
(
source
,
schema_with_orphan_custom_check
)
assert
not
report
.
valid
# Error doesn't appear in error common list
assert
len
(
report
.
errors
)
==
0
# but in task errors
assert
len
(
report
.
tasks
[
0
].
errors
)
==
1
# as a 'check-error'
assert
report
.
tasks
[
0
].
errors
[
0
][
"code"
]
==
"check-error"
def
test_schema_with_unknown_custom_checks
(
schema_with_unknown_custom_check
):
source
=
[[
"siren"
],
[
"529173189"
]]
report
=
validate
(
source
,
schema_with_unknown_custom_check
)
assert
not
report
.
valid
# Error doesn't appear in error common list
assert
len
(
report
.
errors
)
==
0
# but in task errors
assert
len
(
report
.
tasks
[
0
].
errors
)
==
1
# as a 'check-error'
assert
report
.
tasks
[
0
].
errors
[
0
][
"code"
]
==
"check-error"
print
(
report
.
tasks
[
0
].
errors
[
0
][
"note"
])
def
test_primary_key_schema
(
schema_with_non_existing_primary_key
):
source
=
[[
"a"
],
[
"foo"
]]
report
=
validate
(
source
,
schema_with_non_existing_primary_key
)
assert
not
report
.
valid
assert
report
[
"errors"
]
assert
report
[
"errors"
][
0
][
"code"
]
==
"schema-error"
def
test_primary_key_schema_2
(
schema_with_existing_primary_key
):
source
=
[[
"b"
],
[
"foo"
]]
report
=
validate
(
source
,
schema_with_existing_primary_key
)
assert
not
report
.
valid
assert
not
report
[
"errors"
]
assert
report
[
"tasks"
]
assert
report
[
"tasks"
][
0
][
"errors"
]
assert
report
[
"tasks"
][
0
][
"errors"
][
0
][
"code"
]
==
"schema-error"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment