Exemplo n.º 1
0
    def test_infer_and_cast(self):
        lots_of_strings = {
            "a": ["10", "1.3", "true"],
            "b": {
                "x": 10,
                "y": "20.1",
                "z": "other things"
            },
            "c": "just a string"
        }

        casted = {
            "a": [10, 1.3, True],
            "b": {
                "x": 10,
                "y": 20.1,
                "z": "other things"
            },
            "c": "just a string"
        }

        assert infer_and_cast(lots_of_strings) == casted

        contains_bad_data = {"x": 10, "y": int}
        with pytest.raises(ValueError, match="cannot infer type"):
            infer_and_cast(contains_bad_data)

        params = Params(lots_of_strings)

        assert params.as_dict() == lots_of_strings
        assert params.as_dict(infer_type_and_cast=True) == casted
Exemplo n.º 2
0
    def test_infer_and_cast(self):
        lots_of_strings = {
                "a": ["10", "1.3", "true"],
                "b": {"x": 10, "y": "20.1", "z": "other things"},
                "c": "just a string"
        }

        casted = {
                "a": [10, 1.3, True],
                "b": {"x": 10, "y": 20.1, "z": "other things"},
                "c": "just a string"
        }

        assert infer_and_cast(lots_of_strings) == casted

        contains_bad_data = {"x": 10, "y": int}
        with pytest.raises(ValueError, match="cannot infer type"):
            infer_and_cast(contains_bad_data)

        params = Params(lots_of_strings)

        assert params.as_dict() == lots_of_strings
        assert params.as_dict(infer_type_and_cast=True) == casted