"""Type checking util tests.""" import json import pytest from video.constants import field_types from video.utils import typer @pytest.mark.parametrize( ( "data_to_type", "expected_type", ), [ ( {}, field_types.JSON, ), ( {"a": "b"}, field_types.JSON, ), ( [], field_types.JSON, ), ( [1, 3, 1], field_types.JSON, ), ( json.dumps({}), field_types.STRING, ), ( json.dumps({"a": "b"}), field_types.STRING, ), ( json.dumps([]), field_types.STRING, ), ( json.dumps([1, 3, 1]), field_types.STRING, ), ( "123", field_types.STRING, ), ( "1.23", field_types.STRING, ), ( "", field_types.STRING, ), ( None, field_types.NULL, ), (True, field_types.BOOLEAN), (False, field_types.BOOLEAN), (123, field_types.INTEGER), (1.23, field_types.FLOAT), ], ) def test_typer(data_to_type: object, expected_type: str) -> None: """Test typer.""" assert typer.typer(data_to_type) == expected_type def test_stringify() -> None: """Test stringify.""" assert json.dumps({"yup": "good"}) == typer.stringify({"yup": "good"}) @pytest.mark.parametrize( ("value_to_unstringify", "expected_result"), [ (json.dumps({"yup": "good"}), {"yup": "good"}), (json.dumps(json.dumps({"yup": "good"})), json.dumps({"yup": "good"})), ("yup good", "yup good"), (json.dumps("yup good"), "yup good"), (None, None), ], ) def test_unstringify(value_to_unstringify: object, expected_result: object) -> None: """Test unstringify.""" assert expected_result == typer.unstringify(value_to_unstringify)