Skip to content

Commit

Permalink
add negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-yuwang committed Nov 15, 2024
1 parent 00b639a commit e5b4ca7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/unit/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,9 +1339,49 @@ def test_datatype(tpe, simple_string, json, type_name, json_value):
[StructField("a", StringType()), StructField("b", IntegerType())]
),
),
(
StructField,
{
"name": "AA",
"type": "decimal(38,0)",
"nullable": True,
},
StructField("AA", DecimalType()),
),
(
StructField,
{
"name": "AA",
"type": "decimal(20,10)",
"nullable": True,
},
StructField("AA", DecimalType(20, 10)),
),
],
)
def test_structtype_from_json(tpe, json_dict, expected_result):
result = tpe.from_json(json_dict)
assert result == expected_result
assert isinstance(result, tpe)


def test_from_json_wrong_data_type():
wrong_json = {
"name": "AA",
"type": "wrong_type",
"nullable": True,
}
with pytest.raises(ValueError, match="Cannot parse data type: wrong_type"):
StructField.from_json(wrong_json)

wrong_json = {
"name": "AA",
"type": {
"type": "wrong_type",
"key_type": "integer",
"value_type": "string",
},
"nullable": True,
}
with pytest.raises(ValueError, match="Unsupported data type: wrong_type"):
StructField.from_json(wrong_json)

0 comments on commit e5b4ca7

Please sign in to comment.