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
e5034c9d
Commit
e5034c9d
authored
5 months ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST(transformers): tests for cast transformer functions
parent
685ce79d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!217
TST: Make NamedTemporaryFiles Windows-compatible
,
!203
New transformer functions for casting types of variables
Pipeline
#58315
passed
5 months ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_transformers.py
+34
-3
34 additions, 3 deletions
unittests/test_transformers.py
with
34 additions
and
3 deletions
unittests/test_transformers.py
+
34
−
3
View file @
e5034c9d
...
...
@@ -35,12 +35,13 @@ from unittest.mock import MagicMock, Mock, patch
import
linkahead
as
db
import
pytest
import
yaml
from
pytest
import
raises
from
caoscrawler.converters
import
Converter
,
ListElementConverter
from
caoscrawler.scanner
import
create_transformer_registry
,
scan_directory
from
caoscrawler.stores
import
GeneralStore
from
caoscrawler.transformer_functions
import
replace
,
split
from
caoscrawler.transformer_functions
import
(
cast_to_bool
,
cast_to_float
,
cast_to_int
,
cast_to_str
,
replace
,
split
)
from
pytest
import
raises
UNITTESTDIR
=
Path
(
__file__
).
parent
...
...
@@ -163,3 +164,33 @@ def test_empty_functions_list(converter_registry):
conv
.
apply_transformers
(
values
,
transformer_functions
)
assert
values
[
'
b
'
]
==
"
16_45
"
def
test_cast_transformer_functions
():
for
val
in
(
"
True
"
,
"
true
"
,
"
False
"
,
"
false
"
):
assert
type
(
cast_to_bool
(
val
,
{}))
==
bool
if
val
[
1
]
==
"
r
"
:
assert
cast_to_bool
(
val
,
{})
else
:
assert
not
cast_to_bool
(
val
,
{})
for
val_err
in
(
"
jaksdlfj
"
,
"
0
"
,
1
):
with
pytest
.
raises
(
ValueError
):
cast_to_bool
(
val_err
,
{})
assert
not
cast_to_bool
(
False
,
{})
assert
cast_to_bool
(
True
,
{})
assert
cast_to_int
(
"
24
"
,
{})
==
24
assert
cast_to_int
(
24.0
,
{})
==
24
assert
cast_to_int
(
24
,
{})
==
24
with
pytest
.
raises
(
ValueError
):
cast_to_int
(
"
24dsf
"
,
{})
cast_to_int
(
"
24.0
"
,
{})
==
24
assert
cast_to_float
(
"
24
"
,
{})
==
24.0
assert
cast_to_float
(
"
24.0
"
,
{})
==
24.0
assert
cast_to_float
(
24.0
,
{})
==
24.0
assert
cast_to_float
(
24
,
{})
==
24.0
with
pytest
.
raises
(
ValueError
):
cast_to_float
(
"
24dsf
"
,
{})
assert
cast_to_str
(
24
,
{})
==
"
24
"
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