Skip to content

Commit acf7e6a

Browse files
committed
test: Test configurable table cell height
#6 Branch: ConciseTables-6 Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 4c01856 commit acf7e6a

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

tests/test_common.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,61 @@ def test_print_table_wraps_all_cells_with_line_limit(self) -> None:
501501
# Verify max_lines is set to 4
502502
assert arg.max_lines == 4
503503

504+
def test_print_table_with_custom_max_lines(self, mock_settings) -> None:
505+
"""Test that print_table respects custom table_max_lines configuration."""
506+
from unittest.mock import patch
507+
508+
# Configure mock_settings with custom max_lines value
509+
mock_settings.table_max_lines = 2
510+
511+
test_data = [
512+
{"id": 1, "name": "Item 1", "description": "Short text"},
513+
{"id": 2, "name": "Item 2", "description": "Line 1\nLine 2\nLine 3\nLine 4\nLine 5"},
514+
]
515+
columns = ["id", "name", "description"]
516+
517+
# Mock Table.add_row to capture what's passed to it
518+
with patch.object(Table, "add_row") as mock_add_row:
519+
print_table(test_data, "Test Table", columns)
520+
521+
# Verify add_row was called for each data row
522+
assert mock_add_row.call_count == 2
523+
524+
# Check that all arguments to add_row are LineLimit instances with custom max_lines
525+
for call in mock_add_row.call_args_list:
526+
args = call[0] # Get positional arguments
527+
for arg in args:
528+
assert isinstance(arg, LineLimit), f"Expected LineLimit but got {type(arg)}"
529+
# Verify max_lines is set to custom value of 2
530+
assert arg.max_lines == 2
531+
532+
def test_print_table_with_disabled_line_limit(self, mock_settings) -> None:
533+
"""Test that print_table skips LineLimit wrapping when table_max_lines is 0 or negative."""
534+
from unittest.mock import patch
535+
536+
# Configure mock_settings with disabled max_lines value (0)
537+
mock_settings.table_max_lines = 0
538+
539+
test_data = [
540+
{"id": 1, "name": "Item 1", "description": "Short text"},
541+
{"id": 2, "name": "Item 2", "description": "Line 1\nLine 2\nLine 3\nLine 4\nLine 5"},
542+
]
543+
columns = ["id", "name", "description"]
544+
545+
# Mock Table.add_row to capture what's passed to it
546+
with patch.object(Table, "add_row") as mock_add_row:
547+
print_table(test_data, "Test Table", columns)
548+
549+
# Verify add_row was called for each data row
550+
assert mock_add_row.call_count == 2
551+
552+
# Check that arguments to add_row are plain strings, NOT LineLimit instances
553+
for call in mock_add_row.call_args_list:
554+
args = call[0] # Get positional arguments
555+
for arg in args:
556+
assert isinstance(arg, str), f"Expected str but got {type(arg)}"
557+
assert not isinstance(arg, LineLimit), "Should not wrap with LineLimit when disabled"
558+
504559

505560
class TestPromptForSchema:
506561
"""Tests for prompt_for_schema function."""

0 commit comments

Comments
 (0)