From abde40b04f9863e9478fdfd8c0dd70673d25e43e Mon Sep 17 00:00:00 2001 From: Alexander Beedie Date: Fri, 28 Jun 2024 14:37:03 +0400 Subject: [PATCH] expand a unit test --- py-polars/tests/unit/sql/test_structs.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/py-polars/tests/unit/sql/test_structs.py b/py-polars/tests/unit/sql/test_structs.py index f08ded4121ac..fdd404023713 100644 --- a/py-polars/tests/unit/sql/test_structs.py +++ b/py-polars/tests/unit/sql/test_structs.py @@ -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")