@@ -12,140 +12,137 @@ def sample_data():
1212 """Create sample dataset for testing."""
1313 np .random .seed (42 )
1414 n_samples = 100
15-
15+
1616 # Create set membership data
17- data = pd .DataFrame ({
18- 'A' : np .random .choice ([0 , 1 ], size = n_samples , p = [0.3 , 0.7 ]),
19- 'B' : np .random .choice ([0 , 1 ], size = n_samples , p = [0.4 , 0.6 ]),
20- 'C' : np .random .choice ([0 , 1 ], size = n_samples , p = [0.5 , 0.5 ])
21- })
22-
17+ data = pd .DataFrame (
18+ {
19+ "A" : np .random .choice ([0 , 1 ], size = n_samples , p = [0.3 , 0.7 ]),
20+ "B" : np .random .choice ([0 , 1 ], size = n_samples , p = [0.4 , 0.6 ]),
21+ "C" : np .random .choice ([0 , 1 ], size = n_samples , p = [0.5 , 0.5 ]),
22+ }
23+ )
24+
2325 # Add set-specific attributes
24- data [' set_size' ] = data .sum (axis = 1 ) # Number of sets each element belongs to
25-
26+ data [" set_size" ] = data .sum (axis = 1 ) # Number of sets each element belongs to
27+
2628 return data
2729
2830
2931@pytest .fixture
3032def basic_chart (sample_data ):
3133 """Create basic UpSet chart for testing."""
32- return au .UpSetAltair (
33- data = sample_data ,
34- sets = ['A' , 'B' , 'C' ],
35- title = "Test Chart"
36- )
34+ return au .UpSetAltair (data = sample_data , sets = ["A" , "B" , "C" ], title = "Test Chart" )
3735
3836
3937def test_basic_chart_structure (basic_chart ):
4038 """Test that the basic chart has all required components."""
4139 # The chart should be a VConcatChart (vertical concatenation)
4240 assert isinstance (basic_chart .chart , alt .VConcatChart )
43-
41+
4442 # Should have intersection matrix and bar charts
4543 assert len (basic_chart .chart .vconcat ) == 2 # Vertical components
46- assert isinstance (basic_chart .chart .vconcat [1 ], alt .HConcatChart ) # Horizontal components
44+ assert isinstance (
45+ basic_chart .chart .vconcat [1 ], alt .HConcatChart
46+ ) # Horizontal components
4747
4848
4949def test_set_size_encoding (basic_chart ):
5050 """Test that set sizes are correctly encoded."""
5151 # Get the horizontal bar chart component
5252 hconcat = basic_chart .chart .vconcat [1 ]
5353 horizontal_bar = hconcat .hconcat [- 1 ]
54-
54+
5555 # Check encoding - need to convert to dict to access field values
5656 encoding_dict = horizontal_bar .encoding .to_dict ()
57- assert encoding_dict ['x' ][ ' field' ] == ' count'
58- assert encoding_dict ['y' ][ ' field' ] == ' set_order'
57+ assert encoding_dict ["x" ][ " field" ] == " count"
58+ assert encoding_dict ["y" ][ " field" ] == " set_order"
5959
6060
6161def test_intersection_encoding (basic_chart ):
6262 """Test that intersections are correctly encoded."""
6363 # Get the matrix view component
6464 hconcat = basic_chart .chart .vconcat [1 ]
6565 matrix = hconcat .hconcat [0 ]
66-
66+
6767 # Convert encodings to dict for checking
68- encoding_dict = matrix .layer [0 ].encoding .to_dict () # Use first layer for matrix encodings
69- assert encoding_dict ['x' ]['field' ] == 'intersection_id'
70- assert encoding_dict ['y' ]['field' ] == 'set_order'
68+ encoding_dict = matrix .layer [
69+ 0
70+ ].encoding .to_dict () # Use first layer for matrix encodings
71+ assert encoding_dict ["x" ]["field" ] == "intersection_id"
72+ assert encoding_dict ["y" ]["field" ] == "set_order"
7173
7274
7375def test_interactive_legend (basic_chart ):
7476 """Test that the chart has interactive legend selection."""
7577 # Check for legend selection parameter
7678 params = basic_chart .chart .params
77- assert any (' legend' in str (p ) for p in params )
79+ assert any (" legend" in str (p ) for p in params )
7880
7981
8082def test_hover_interaction (basic_chart ):
8183 """Test that the chart has hover interactions."""
8284 # Get the matrix view component
8385 hconcat = basic_chart .chart .vconcat [1 ]
8486 matrix = hconcat .hconcat [0 ]
85-
87+
8688 # Check for tooltips in any layer of the matrix
8789 has_tooltip = False
8890 for layer in matrix .layer :
89- if hasattr (layer , ' encoding' ):
91+ if hasattr (layer , " encoding" ):
9092 encoding_dict = layer .encoding .to_dict ()
91- if ' tooltip' in encoding_dict :
93+ if " tooltip" in encoding_dict :
9294 has_tooltip = True
9395 break
94-
96+
9597 assert has_tooltip , "No tooltip found in matrix view"
9698
9799
98100def test_sort_by_frequency (sample_data ):
99101 """Test sorting intersections by frequency."""
100102 chart = au .UpSetAltair (
101103 data = sample_data ,
102- sets = ['A' , 'B' , 'C' ],
103- sort_by = ' frequency' ,
104- sort_order = ' descending'
104+ sets = ["A" , "B" , "C" ],
105+ sort_by = " frequency" ,
106+ sort_order = " descending" ,
105107 )
106-
108+
107109 # Get the matrix view component
108110 matrix_view = chart .chart .vconcat [1 ].hconcat [0 ]
109-
111+
110112 # Check sort configuration in the first layer
111113 encoding_dict = matrix_view .layer [0 ].encoding .to_dict ()
112- sort_config = encoding_dict ['x' ].get (' sort' , {})
113-
114- assert sort_config .get (' field' ) == ' count'
115- assert sort_config .get (' order' ) == ' descending'
114+ sort_config = encoding_dict ["x" ].get (" sort" , {})
115+
116+ assert sort_config .get (" field" ) == " count"
117+ assert sort_config .get (" order" ) == " descending"
116118
117119
118120def test_sort_by_degree (sample_data ):
119121 """Test sorting intersections by degree."""
120122 chart = au .UpSetAltair (
121- data = sample_data ,
122- sets = ['A' , 'B' , 'C' ],
123- sort_by = 'degree' ,
124- sort_order = 'ascending'
123+ data = sample_data , sets = ["A" , "B" , "C" ], sort_by = "degree" , sort_order = "ascending"
125124 )
126-
125+
127126 # Get the matrix view component
128127 matrix_view = chart .chart .vconcat [1 ].hconcat [0 ]
129-
128+
130129 # Check sort configuration in the first layer
131130 encoding_dict = matrix_view .layer [0 ].encoding .to_dict ()
132- sort_config = encoding_dict ['x' ].get (' sort' , {})
133-
134- assert sort_config .get (' field' ) == ' degree'
135- assert sort_config .get (' order' ) == ' ascending'
131+ sort_config = encoding_dict ["x" ].get (" sort" , {})
132+
133+ assert sort_config .get (" field" ) == " degree"
134+ assert sort_config .get (" order" ) == " ascending"
136135
137136
138137def test_custom_colors (sample_data ):
139138 """Test applying custom colors to the chart."""
140139 custom_colors = ["#FF0000" , "#00FF00" , "#0000FF" ]
141140 chart = au .UpSetAltair (
142- data = sample_data ,
143- sets = ['A' , 'B' , 'C' ],
144- color_range = custom_colors
141+ data = sample_data , sets = ["A" , "B" , "C" ], color_range = custom_colors
145142 )
146-
143+
147144 # Check that custom colors are applied
148145 hconcat = chart .chart .vconcat [1 ]
149146 horizontal_bar = hconcat .hconcat [- 1 ]
150- assert ' scale' in str (horizontal_bar .encoding .color )
147+ assert " scale" in str (horizontal_bar .encoding .color )
151148 assert all (color in str (horizontal_bar .encoding .color ) for color in custom_colors )
0 commit comments