Skip to content

Commit b71a2b0

Browse files
committed
Address PR review comments
- twodim.py: move 'import os' to top of file (was inline inside to_table) - twodim.py: move _compute_natural_widths() call inside _fit_table_to_width() so nat_widths is no longer an external parameter at the call site - test_store.py: restore the '| 6' check to assert the report count is exactly 6; use Unicode │ (U+2502) to match PrettyTable's separator
1 parent 41d9987 commit b71a2b0

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

tools/report-converter/codechecker_report_converter/twodim.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
import json
14+
import os
1415
import shutil
1516

1617
from operator import itemgetter
@@ -120,7 +121,9 @@ def _compute_natural_widths(
120121

121122
def _fit_table_to_width(
122123
table: PrettyTable,
123-
nat_widths: List[int],
124+
field_names: List[str],
125+
data_rows: List[List[str]],
126+
show_header: bool,
124127
terminal_width: int,
125128
) -> str:
126129
"""
@@ -148,6 +151,7 @@ def _fit_table_to_width(
148151
3 characters per column (space + content + space + border) plus 1 for
149152
the leading border: ``overhead = num_cols * 3 + 1``.
150153
"""
154+
nat_widths = _compute_natural_widths(field_names, data_rows, show_header)
151155
num_cols = len(nat_widths)
152156
# SINGLE_BORDER layout: │ c1 │ c2 │ … │ cn │
153157
# overhead = 1 (left border) + num_cols *
@@ -261,11 +265,10 @@ def to_table(
261265
if not lns:
262266
return ''
263267

264-
# Detect the current terminal width. honour the COLUMNS environment
268+
# Detect the current terminal width. Honour the COLUMNS environment
265269
# variable first (allows the user to override), then fall back to the
266270
# OS-reported terminal size, and finally to 80 columns when stdout is
267271
# redirected to a file or pipe.
268-
import os # pylint: disable=import-outside-toplevel
269272
try:
270273
terminal_width = int(os.environ['COLUMNS'])
271274
except (KeyError, ValueError):
@@ -286,8 +289,8 @@ def to_table(
286289
else:
287290
table = _make_table(field_names, data_rows, show_header)
288291

289-
nat_widths = _compute_natural_widths(field_names, data_rows, show_header)
290-
return _fit_table_to_width(table, nat_widths, terminal_width)
292+
return _fit_table_to_width(
293+
table, field_names, data_rows, show_header, terminal_width)
291294

292295

293296
def to_csv(lines: Iterable[str]) -> str:

web/tests/functional/store/test_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,5 @@ def test_store_stats(self):
511511
_, out, _ = _call_cmd(store_cmd)
512512
# There are 9 individual reports, but only 6 unique.
513513
# The statistics should only print the unique ones.
514-
self.assertIn("Number of analyzer reports", out)
514+
# PrettyTable uses │ (U+2502) as column separator instead of ASCII |.
515+
self.assertIn("Number of analyzer reports │ 6", out)

0 commit comments

Comments
 (0)