22
33These tests focus on Python-specific logic:
44- DataFrame conversion via narwhals
5- - Writer parameter validation
65- Return type handling
76
87Rust logic (parsing, Vega-Lite generation) is tested in the Rust test suite.
@@ -31,17 +30,17 @@ def test_no_visualise_returns_empty_viz(self):
3130 assert viz == ""
3231
3332
34- class TestRenderDataFrameConversion :
35- """Tests for DataFrame handling in render ()."""
33+ class TestRenderAltairDataFrameConversion :
34+ """Tests for DataFrame handling in render_altair ()."""
3635
3736 def test_accepts_polars_dataframe (self ):
3837 df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
39- chart = ggsql .render (df , "VISUALISE x, y DRAW point" )
38+ chart = ggsql .render_altair (df , "VISUALISE x, y DRAW point" )
4039 assert isinstance (chart , altair .TopLevelMixin )
4140
4241 def test_accepts_polars_lazyframe (self ):
4342 lf = pl .LazyFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
44- chart = ggsql .render (lf , "VISUALISE x, y DRAW point" )
43+ chart = ggsql .render_altair (lf , "VISUALISE x, y DRAW point" )
4544 assert isinstance (chart , altair .TopLevelMixin )
4645
4746 def test_accepts_narwhals_dataframe (self ):
@@ -50,67 +49,48 @@ def test_accepts_narwhals_dataframe(self):
5049 pl_df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
5150 nw_df = nw .from_native (pl_df )
5251
53- chart = ggsql .render (nw_df , "VISUALISE x, y DRAW point" )
52+ chart = ggsql .render_altair (nw_df , "VISUALISE x, y DRAW point" )
5453 assert isinstance (chart , altair .TopLevelMixin )
5554
5655 def test_accepts_pandas_dataframe (self ):
5756 pd = pytest .importorskip ("pandas" )
5857
5958 pd_df = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
60- chart = ggsql .render (pd_df , "VISUALISE x, y DRAW point" )
59+ chart = ggsql .render_altair (pd_df , "VISUALISE x, y DRAW point" )
6160 assert isinstance (chart , altair .TopLevelMixin )
6261
6362 def test_rejects_invalid_dataframe_type (self ):
6463 with pytest .raises (TypeError , match = "must be a narwhals DataFrame" ):
65- ggsql .render ({"x" : [1 , 2 , 3 ]}, "VISUALISE x, y DRAW point" )
64+ ggsql .render_altair ({"x" : [1 , 2 , 3 ]}, "VISUALISE x, y DRAW point" )
6665
6766
68- class TestRenderWriterValidation :
69- """Tests for writer parameter validation."""
70-
71- def test_default_writer_is_vegalite (self ):
72- df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
73- chart = ggsql .render (df , "VISUALISE x, y DRAW point" )
74- assert isinstance (chart , altair .TopLevelMixin )
75-
76- def test_explicit_vegalite_writer (self ):
77- df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
78- chart = ggsql .render (df , "VISUALISE x, y DRAW point" , writer = "vegalite" )
79- assert isinstance (chart , altair .TopLevelMixin )
80-
81- def test_unknown_writer_raises (self ):
82- df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
83- with pytest .raises (ValueError , match = "Unknown writer.*Supported writers" ):
84- ggsql .render (df , "VISUALISE x, y DRAW point" , writer = "ggplot2" )
85-
86-
87- class TestRenderReturnType :
88- """Tests for render() return type."""
67+ class TestRenderAltairReturnType :
68+ """Tests for render_altair() return type."""
8969
9070 def test_returns_altair_chart (self ):
9171 df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
92- chart = ggsql .render (df , "VISUALISE x, y DRAW point" )
72+ chart = ggsql .render_altair (df , "VISUALISE x, y DRAW point" )
9373 assert isinstance (chart , altair .TopLevelMixin )
9474
9575 def test_chart_has_data (self ):
9676 df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
97- chart = ggsql .render (df , "VISUALISE x, y DRAW point" )
77+ chart = ggsql .render_altair (df , "VISUALISE x, y DRAW point" )
9878 spec = chart .to_dict ()
9979 # Data should be embedded in datasets
10080 assert "datasets" in spec
10181
10282 def test_chart_can_be_serialized (self ):
10383 df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
104- chart = ggsql .render (df , "VISUALISE x, y DRAW point" )
84+ chart = ggsql .render_altair (df , "VISUALISE x, y DRAW point" )
10585 # Should not raise
10686 json_str = chart .to_json ()
10787 assert len (json_str ) > 0
10888
10989
110- class TestRenderErrorHandling :
111- """Tests for error handling in render ()."""
90+ class TestRenderAltairErrorHandling :
91+ """Tests for error handling in render_altair ()."""
11292
11393 def test_invalid_viz_raises (self ):
11494 df = pl .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
11595 with pytest .raises (ValueError ):
116- ggsql .render (df , "NOT VALID SYNTAX" )
96+ ggsql .render_altair (df , "NOT VALID SYNTAX" )
0 commit comments