Skip to content

Commit 6fe52b3

Browse files
committed
Fix list-table width test breaking pytest reporting
The width test replaced the global shutil.get_terminal_size with a no-argument lambda, so pytest's own get_terminal_size(fallback=...) call during progress reporting raised TypeError and aborted the run with an INTERNALERROR. Extract a _list_table_width() helper and test it directly with a signature-compatible stub, so the cap logic is verified without disturbing pytest's terminal-size lookups.
1 parent af9fb48 commit 6fe52b3

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/easydiffraction/utils/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,11 @@ def _tutorial_url_for_format(url: str, fmt: TutorialFormat) -> str:
945945
_LIST_TABLE_MAX_WIDTH = 100
946946

947947

948+
def _list_table_width() -> int:
949+
"""Return the listing-table width, capped at the maximum."""
950+
return min(shutil.get_terminal_size().columns, _LIST_TABLE_MAX_WIDTH)
951+
952+
948953
def list_tutorials() -> None:
949954
"""
950955
Display a table of available tutorial notebooks.
@@ -989,7 +994,7 @@ def list_tutorials() -> None:
989994
columns_headers=columns_headers,
990995
columns_data=columns_data,
991996
columns_alignment=columns_alignment,
992-
width=min(shutil.get_terminal_size().columns, _LIST_TABLE_MAX_WIDTH),
997+
width=_list_table_width(),
993998
)
994999

9951000

tests/unit/easydiffraction/utils/test_utils.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,17 @@ def test_list_tutorials_with_data(monkeypatch, capsys):
356356
('terminal_columns', 'expected_width'),
357357
[(200, 100), (72, 72)],
358358
)
359-
def test_list_tutorials_caps_table_width(monkeypatch, terminal_columns, expected_width):
359+
def test_list_table_width_caps_at_max(monkeypatch, terminal_columns, expected_width):
360360
import easydiffraction.utils.utils as MUT
361361

362-
fake_index = {'quick-start': {'url': 'https://x/{version}/t/quick-start.ipynb'}}
363-
monkeypatch.setattr(MUT, '_fetch_tutorials_index', lambda: fake_index)
364-
monkeypatch.setattr(MUT, 'package_version', lambda name: '0.8.0')
362+
# Accept arbitrary args so pytest's own ``get_terminal_size(fallback=...)``
363+
# keeps working while this patch is active.
365364
monkeypatch.setattr(
366-
MUT.shutil, 'get_terminal_size', lambda: os.terminal_size((terminal_columns, 24))
365+
MUT.shutil,
366+
'get_terminal_size',
367+
lambda *args, **kwargs: os.terminal_size((terminal_columns, 24)),
367368
)
368-
369-
captured = {}
370-
monkeypatch.setattr(MUT, 'render_table', lambda **kwargs: captured.update(kwargs))
371-
372-
MUT.list_tutorials()
373-
assert captured['width'] == expected_width
369+
assert MUT._list_table_width() == expected_width
374370

375371

376372
def test_download_tutorial_unknown_id(monkeypatch):

0 commit comments

Comments
 (0)