|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import unittest |
| 4 | + |
| 5 | +from sahi.utils.table import create_ascii_table |
| 6 | + |
| 7 | + |
| 8 | +class TestTable(unittest.TestCase): |
| 9 | + def test_create_ascii_table_basic(self): |
| 10 | + data = [ |
| 11 | + ["Model", "Params(M)", "Dataset"], |
| 12 | + ["ResNet50", 25.6, "ImageNet"], |
| 13 | + ["YOLOv8n", 4.5, "COCO"], |
| 14 | + ["Swin-Transformer", 88.2, "ADE20K"], |
| 15 | + ] |
| 16 | + table = create_ascii_table(data) |
| 17 | + |
| 18 | + # Verify basic structure |
| 19 | + self.assertIn("ResNet50", table) |
| 20 | + self.assertIn("Dataset", table) |
| 21 | + self.assertTrue(table.startswith("+")) |
| 22 | + self.assertTrue(table.endswith("+")) |
| 23 | + |
| 24 | + # Verify alignment (Swin-Transformer is the longest model name) |
| 25 | + # Content row should contain the full model name padded correctly. |
| 26 | + self.assertIn("| Swin-Transformer |", table) |
| 27 | + |
| 28 | + def test_empty_data(self): |
| 29 | + self.assertEqual(create_ascii_table([]), "") |
| 30 | + self.assertEqual(create_ascii_table([[]]), "") |
| 31 | + |
| 32 | + def test_none_values(self): |
| 33 | + data = [["ID", "Value"], [1, None]] |
| 34 | + table = create_ascii_table(data) |
| 35 | + self.assertIn("| 1 | |", table) |
0 commit comments