Skip to content

Commit

Permalink
expand a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jun 28, 2024
1 parent d0dd27f commit abde40b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions py-polars/tests/unit/sql/test_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,24 @@ def test_struct_field_selection_wildcards(


@pytest.mark.parametrize(
"invalid_column",
("invalid_column", "error_type"),
[
"json_msg.invalid_column",
"json_msg.other.invalid_column",
"self.json_msg.other.invalid_column",
("json_msg.invalid_column", StructFieldNotFoundError),
("json_msg.other.invalid_column", StructFieldNotFoundError),
("self.json_msg.other.invalid_column", StructFieldNotFoundError),
("json_msg.other -> invalid_column", SQLSyntaxError),
("json_msg -> DATE '2020-09-11'", SQLSyntaxError),
],
)
def test_struct_field_selection_errors(
invalid_column: str, df_struct: pl.DataFrame
invalid_column: str,
error_type: type[Exception],
df_struct: pl.DataFrame,
) -> None:
with pytest.raises(StructFieldNotFoundError, match="invalid_column"):
error_msg = (
"invalid json/struct path-extract"
if ("->" in invalid_column)
else "invalid_column"
)
with pytest.raises(error_type, match=error_msg):
df_struct.sql(f"SELECT {invalid_column} FROM self")

0 comments on commit abde40b

Please sign in to comment.