Skip to content
Snippets Groups Projects
Commit e5034c9d authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST(transformers): tests for cast transformer functions

parent 685ce79d
No related branches found
No related tags found
2 merge requests!217TST: Make NamedTemporaryFiles Windows-compatible,!203New transformer functions for casting types of variables
Pipeline #58315 passed
......@@ -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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment