|
5 | 5 | from bittensor_cli.src.bittensor.utils import ( |
6 | 6 | check_img_mimetype, |
7 | 7 | confirm_action, |
8 | | - create_table, |
9 | 8 | ) |
10 | | -from rich.table import Column, Table |
11 | | -from bittensor_cli.src import COLOR_PALETTE |
12 | 9 |
|
13 | 10 |
|
14 | 11 | @pytest.mark.parametrize( |
@@ -134,175 +131,3 @@ def test_confirm_action_default_values(self): |
134 | 131 | result = confirm_action("Do you want to proceed?") |
135 | 132 | assert result is True |
136 | 133 | mock_ask.assert_called_once() |
137 | | - |
138 | | - |
139 | | -class TestCreateTable: |
140 | | - """Tests for the create_table utility function.""" |
141 | | - |
142 | | - def test_simple_table_creation(self): |
143 | | - """Test creating a simple table with default styling.""" |
144 | | - table = create_table(title="My Subnets") |
145 | | - |
146 | | - # Verify it returns a Table instance |
147 | | - assert isinstance(table, Table) |
148 | | - assert table.title == "My Subnets" |
149 | | - |
150 | | - # Verify default styling is applied |
151 | | - assert table.show_footer is True |
152 | | - assert table.show_edge is False |
153 | | - assert table.header_style == "bold white" |
154 | | - assert table.border_style == "bright_black" |
155 | | - assert table.title_justify == "center" |
156 | | - assert table.show_lines is False |
157 | | - assert table.pad_edge is True |
158 | | - |
159 | | - def test_table_with_columns_added_later(self): |
160 | | - """Test adding columns after table creation.""" |
161 | | - table = create_table(title="Test Table") |
162 | | - |
163 | | - # Add columns dynamically |
164 | | - table.add_column("Column1", justify="center") |
165 | | - table.add_column("Column2", justify="left") |
166 | | - |
167 | | - assert len(table.columns) == 2 |
168 | | - assert table.columns[0].header == "Column1" |
169 | | - assert table.columns[1].header == "Column2" |
170 | | - |
171 | | - # Add rows |
172 | | - table.add_row("Value1", "Value2") |
173 | | - assert len(table.rows) == 1 |
174 | | - |
175 | | - def test_table_with_column_objects(self): |
176 | | - """Test creating table with Column objects upfront (identity table pattern).""" |
177 | | - table = create_table( |
178 | | - Column( |
179 | | - "Item", |
180 | | - justify="right", |
181 | | - style=COLOR_PALETTE["GENERAL"]["SUBHEADING_MAIN"], |
182 | | - no_wrap=True, |
183 | | - ), |
184 | | - Column("Value", style=COLOR_PALETTE["GENERAL"]["SUBHEADING"]), |
185 | | - title="Identity", |
186 | | - ) |
187 | | - |
188 | | - # Verify columns were added |
189 | | - assert len(table.columns) == 2 |
190 | | - assert table.columns[0].header == "Item" |
191 | | - assert table.columns[1].header == "Value" |
192 | | - assert table.columns[0].justify == "right" |
193 | | - assert table.columns[0].no_wrap is True |
194 | | - |
195 | | - # Verify default styling still applied |
196 | | - assert table.show_footer is True |
197 | | - assert table.show_edge is False |
198 | | - |
199 | | - def test_custom_overrides(self): |
200 | | - """Test overriding default parameters.""" |
201 | | - table = create_table( |
202 | | - title="Custom Table", |
203 | | - show_footer=False, |
204 | | - border_style="blue", |
205 | | - show_lines=True, |
206 | | - ) |
207 | | - |
208 | | - # Verify overrides applied |
209 | | - assert table.show_footer is False |
210 | | - assert table.border_style == "blue" |
211 | | - assert table.show_lines is True |
212 | | - |
213 | | - # Verify non-overridden defaults preserved |
214 | | - assert table.show_edge is False |
215 | | - assert table.header_style == "bold white" |
216 | | - |
217 | | - def test_subnets_list_pattern(self): |
218 | | - """Test actual pattern from subnets_list() function.""" |
219 | | - table = create_table( |
220 | | - title=f"[{COLOR_PALETTE['GENERAL']['HEADER']}]Subnets\n" |
221 | | - f"Network: [{COLOR_PALETTE['GENERAL']['SUBHEADING']}]finney\n", |
222 | | - ) |
223 | | - |
224 | | - # Add columns as in actual code |
225 | | - table.add_column("[bold white]Netuid", style="grey89", justify="center") |
226 | | - table.add_column("[bold white]Name", style="cyan", justify="left") |
227 | | - table.add_column("[bold white]Price", style="dark_sea_green2", justify="left") |
228 | | - |
229 | | - assert len(table.columns) == 3 |
230 | | - |
231 | | - # Add sample row |
232 | | - table.add_row("1", "Alpha", "0.0025") |
233 | | - assert len(table.rows) == 1 |
234 | | - |
235 | | - def test_registration_pattern(self): |
236 | | - """Test registration confirmation table pattern.""" |
237 | | - table = create_table( |
238 | | - title=( |
239 | | - f"[{COLOR_PALETTE.G.HEADER}]" |
240 | | - f"Register to [{COLOR_PALETTE.G.SUBHEAD}]netuid: 1[/{COLOR_PALETTE.G.SUBHEAD}]\n" |
241 | | - f"Network: [{COLOR_PALETTE.G.SUBHEAD}]finney[/{COLOR_PALETTE.G.SUBHEAD}]\n" |
242 | | - ), |
243 | | - ) |
244 | | - |
245 | | - table.add_column( |
246 | | - "Netuid", style="rgb(253,246,227)", no_wrap=True, justify="center" |
247 | | - ) |
248 | | - table.add_column( |
249 | | - "Symbol", style=COLOR_PALETTE["GENERAL"]["SYMBOL"], no_wrap=True |
250 | | - ) |
251 | | - table.add_column( |
252 | | - "Cost (τ)", style=COLOR_PALETTE["POOLS"]["TAO"], justify="center" |
253 | | - ) |
254 | | - |
255 | | - assert len(table.columns) == 3 |
256 | | - |
257 | | - # Add sample row |
258 | | - table.add_row("1", "α", "τ 0.5000") |
259 | | - assert len(table.rows) == 1 |
260 | | - |
261 | | - def test_advanced_rich_features(self): |
262 | | - """Test advanced Rich features with custom box and expand.""" |
263 | | - from rich import box |
264 | | - |
265 | | - table = create_table( |
266 | | - Column("Command", overflow="fold", ratio=2), |
267 | | - Column("Description", overflow="fold", ratio=3), |
268 | | - title="Commands", |
269 | | - box=box.ROUNDED, |
270 | | - expand=True, |
271 | | - padding=(0, 1), |
272 | | - ) |
273 | | - |
274 | | - assert table.box == box.ROUNDED |
275 | | - assert table.expand is True |
276 | | - assert len(table.columns) == 2 |
277 | | - assert table.columns[0].ratio == 2 |
278 | | - assert table.columns[1].ratio == 3 |
279 | | - |
280 | | - def test_empty_table_minimal_config(self): |
281 | | - """Test creating empty table with minimal configuration.""" |
282 | | - table = create_table() |
283 | | - |
284 | | - assert isinstance(table, Table) |
285 | | - assert table.title == "" |
286 | | - assert table.show_footer is True |
287 | | - assert len(table.columns) == 0 |
288 | | - |
289 | | - def test_multiple_column_objects_with_styling(self): |
290 | | - """Test multiple Column objects with various styling options.""" |
291 | | - table = create_table( |
292 | | - Column("Col1", style="cyan", justify="left"), |
293 | | - Column("Col2", style="green", justify="center", no_wrap=True), |
294 | | - Column("Col3", style="yellow", justify="right", overflow="fold"), |
295 | | - title="Multi-Column Test", |
296 | | - ) |
297 | | - |
298 | | - assert len(table.columns) == 3 |
299 | | - assert table.columns[0].style == "cyan" |
300 | | - assert table.columns[1].justify == "center" |
301 | | - assert table.columns[2].overflow == "fold" |
302 | | - |
303 | | - def test_rich_markup_in_title(self): |
304 | | - """Test that rich markup in title is preserved.""" |
305 | | - table = create_table(title="[bold cyan]Test[/bold cyan] [dim]subtitle[/dim]") |
306 | | - |
307 | | - assert "[bold cyan]Test[/bold cyan]" in table.title |
308 | | - assert "[dim]subtitle[/dim]" in table.title |
0 commit comments