flexablelib 2.0.20__tar.gz → 2.0.21__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. {flexablelib-2.0.20 → flexablelib-2.0.21}/CHANGELOG.md +30 -0
  2. {flexablelib-2.0.20/flexablelib.egg-info → flexablelib-2.0.21}/PKG-INFO +1 -1
  3. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/cells.py +9 -2
  4. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/merges.py +20 -0
  5. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/style_compositions.py +1 -1
  6. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/table.py +30 -6
  7. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/writers.py +31 -7
  8. {flexablelib-2.0.20 → flexablelib-2.0.21/flexablelib.egg-info}/PKG-INFO +1 -1
  9. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib.egg-info/SOURCES.txt +2 -0
  10. {flexablelib-2.0.20 → flexablelib-2.0.21}/package.json +1 -1
  11. flexablelib-2.0.21/tests/test_style_line_widths.py +46 -0
  12. flexablelib-2.0.21/tests/test_v2021_fixes.py +262 -0
  13. {flexablelib-2.0.20 → flexablelib-2.0.21}/LICENSE +0 -0
  14. {flexablelib-2.0.20 → flexablelib-2.0.21}/MANIFEST.in +0 -0
  15. {flexablelib-2.0.20 → flexablelib-2.0.21}/README.md +0 -0
  16. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/__init__.py +0 -0
  17. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/_speedups.c +0 -0
  18. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/_width_tables.h +0 -0
  19. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/colors.py +0 -0
  20. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/columns.py +0 -0
  21. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/fast.py +0 -0
  22. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/options.py +0 -0
  23. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/py.typed +0 -0
  24. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/readers.py +0 -0
  25. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/table_strings.py +0 -0
  26. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/text_width.py +0 -0
  27. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib/utils.py +0 -0
  28. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib.egg-info/dependency_links.txt +0 -0
  29. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib.egg-info/requires.txt +0 -0
  30. {flexablelib-2.0.20 → flexablelib-2.0.21}/flexablelib.egg-info/top_level.txt +0 -0
  31. {flexablelib-2.0.20 → flexablelib-2.0.21}/pytest.ini +0 -0
  32. {flexablelib-2.0.20 → flexablelib-2.0.21}/setup.cfg +0 -0
  33. {flexablelib-2.0.20 → flexablelib-2.0.21}/setup.py +0 -0
  34. {flexablelib-2.0.20 → flexablelib-2.0.21}/style_examples.md +0 -0
  35. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/conftest.py +0 -0
  36. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/helpers.py +0 -0
  37. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_cells.py +0 -0
  38. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_columns.py +0 -0
  39. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_excel.py +0 -0
  40. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_features.py +0 -0
  41. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_issues.py +0 -0
  42. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_merge_edge_matrix.py +0 -0
  43. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_merges.py +0 -0
  44. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_readme_examples.py +0 -0
  45. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_styles.py +0 -0
  46. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_text_width.py +0 -0
  47. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_two_pass_measurement.py +0 -0
  48. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_upstream_issues.py +0 -0
  49. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v2110_fixes.py +0 -0
  50. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v213_features.py +0 -0
  51. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v214_features.py +0 -0
  52. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v215_features.py +0 -0
  53. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v216_features.py +0 -0
  54. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v217_features.py +0 -0
  55. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v218_features.py +0 -0
  56. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v219_coverage.py +0 -0
  57. {flexablelib-2.0.20 → flexablelib-2.0.21}/tests/test_v219_fixes.py +0 -0
  58. {flexablelib-2.0.20 → flexablelib-2.0.21}/tools/benchmark.py +0 -0
  59. {flexablelib-2.0.20 → flexablelib-2.0.21}/tools/generate_width_tables.py +0 -0
  60. {flexablelib-2.0.20 → flexablelib-2.0.21}/tools/readme_gallery.py +0 -0
  61. {flexablelib-2.0.20 → flexablelib-2.0.21}/tools/text_to_png.py +0 -0
@@ -2,6 +2,36 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [2.0.21] - 2026-11-03
6
+
7
+ ### Fixed
8
+ - Text exports (``to_csv``, ``to_markdown``, ``to_rst``, ``to_asciidoc``,
9
+ ``to_latex``, ``to_html``) and ``to_records`` wrote
10
+ ``<flexablelib.utils.ValuePlacer object at ...>`` for gaps -- short rows
11
+ padded by the table, NaN/NULL from the readers, ``table.missing``. Gaps
12
+ now export as empty cells (``None`` in records).
13
+ - ``include_index=True`` wrote ``<...IndexCounter object at ...>`` in every
14
+ row, and left the index out when ``show_index`` was off. The index is now
15
+ numbered like the rendered one (``index_start``, ``index_step``,
16
+ ``index_title``, ``roman_index``).
17
+ - A float column whose numbers have no decimal point (``1e+20``) rendered
18
+ one character wider than its border.
19
+ - ``vrules='none'`` kept the corners of the horizontal rules, which made
20
+ them two columns wider than the rows.
21
+ - ``transpose()`` / ``rotate()`` showed gaps blank instead of the missing
22
+ value and exported the sentinel's repr; the missing value is carried over.
23
+ - ``merge_cells`` with a non-integer coordinate (a float, or a
24
+ ``(row, column)`` pair) raises a ``TypeError`` naming the argument instead
25
+ of a comparison error.
26
+ - ``plain`` style: the blank line under the header was one column shorter
27
+ than the rows (no junction between columns), so ``compose()`` output was
28
+ not rectangular.
29
+
30
+ ### Tests
31
+ - Every style renders lines of equal terminal width with CJK / emoji
32
+ headers and ``column_max_width``. Pins that ``*_eheader`` styles draw the
33
+ header row without column separators by design.
34
+
5
35
  ## [2.0.20] - 2026-11-02
6
36
 
7
37
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.0.20
3
+ Version: 2.0.21
4
4
  Summary: Fast, dependency-free terminal tables for Python: 56 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Author: Benjamin Ramirez
@@ -182,8 +182,15 @@ def fljust(string: str,
182
182
  right = pad_to_width(right_string, right_width, 'l', fill_char)
183
183
 
184
184
  # A number with no point leaves the point's own column blank, so it is
185
- # still exactly as wide as the ones that have one.
186
- return ''.join([left, point or fill_char, right])
185
+ # still exactly as wide as the ones that have one. When no number in the
186
+ # column has a point (a column of exponentials such as ``1e+20``) that
187
+ # column is zero wide, and padding it anyway made the cell one character
188
+ # wider than the column and pushed the right border out.
189
+ if not point:
190
+ point_width = (sides_widths[POINT_WIDTH_I]
191
+ if len(sides_widths) > 2 else 1)
192
+ point = fill_char * point_width
193
+ return ''.join([left, point, right])
187
194
 
188
195
 
189
196
  def __fill_to(aligned: str, cell_length: int, fill_char: str) -> str:
@@ -16,6 +16,7 @@ The consequence is that a merged region never widens the table. Content longer
16
16
  than the span it was given is truncated, not accommodated.
17
17
  """
18
18
 
19
+ import operator
19
20
  import re
20
21
  from typing import List, NamedTuple, Optional
21
22
 
@@ -99,6 +100,25 @@ def normalise(first_row, first_column, last_row, last_column, value, align,
99
100
  single cell, coordinates outside the table, an unknown alignment, or an
100
101
  overlap with a merge already in place.
101
102
  """
103
+ # Coordinates are indexes. ``operator.index`` accepts ints and integer
104
+ # types such as numpy's, and turns anything else -- a float, or a
105
+ # ``(row, column)`` pair given where a single number goes -- into a
106
+ # TypeError naming the argument, instead of a comparison error from
107
+ # deep inside the validation or the renderer.
108
+ coordinates = []
109
+ for name, coordinate in (('first_row', first_row),
110
+ ('first_column', first_column),
111
+ ('last_row', last_row),
112
+ ('last_column', last_column)):
113
+ try:
114
+ coordinates.append(operator.index(coordinate))
115
+ except TypeError:
116
+ raise TypeError(
117
+ f'{name} must be an integer, not '
118
+ f'{type(coordinate).__name__} ({coordinate!r})'
119
+ ) from None
120
+ first_row, first_column, last_row, last_column = coordinates
121
+
102
122
  first_row, last_row = sorted((first_row, last_row))
103
123
  first_column, last_column = sorted((first_column, last_column))
104
124
 
@@ -154,7 +154,7 @@ Compositions = namedtuple(
154
154
  __style_compositions = Compositions(
155
155
  plain=TableComposition(
156
156
  superior_header_line=None,
157
- inferior_header_line=SeparatorLine(None, INVISIBLE_SEPARATOR, None, None),
157
+ inferior_header_line=SeparatorLine(None, INVISIBLE_SEPARATOR, INVISIBLE_SEPARATOR, None),
158
158
  superior_header_line_no_header=None,
159
159
  table_body_line=None,
160
160
  table_end_line=None,
@@ -2357,17 +2357,30 @@ class Table(object):
2357
2357
  fill = sep.middle if sep.middle not in (None, '') else INVISIBLE_SEPARATOR
2358
2358
  return SeparatorLine(sep.left, fill, fill, sep.right)
2359
2359
 
2360
+ def drop_verticals(sep):
2361
+ """
2362
+ Horizontal rule with no junctions and no corners (vrules none).
2363
+
2364
+ The rows lose their left and right borders in this mode, so a
2365
+ rule that kept its corners came out two columns wider than every
2366
+ row it framed.
2367
+ """
2368
+ sep = drop_intersections(sep)
2369
+ if sep is None:
2370
+ return None
2371
+ return SeparatorLine(None, sep.middle, sep.intersection, None)
2372
+
2360
2373
  if mode in ('none', 'n', 'off', 'false', '0'):
2361
2374
  return {
2362
2375
  'vertical_header_lines': invisible,
2363
2376
  'vertical_table_body_lines': invisible,
2364
- 'superior_header_line': drop_intersections(base.superior_header_line),
2365
- 'inferior_header_line': drop_intersections(base.inferior_header_line),
2366
- 'superior_header_line_no_header': drop_intersections(
2377
+ 'superior_header_line': drop_verticals(base.superior_header_line),
2378
+ 'inferior_header_line': drop_verticals(base.inferior_header_line),
2379
+ 'superior_header_line_no_header': drop_verticals(
2367
2380
  base.superior_header_line_no_header
2368
2381
  ),
2369
- 'table_body_line': drop_intersections(base.table_body_line),
2370
- 'table_end_line': drop_intersections(base.table_end_line),
2382
+ 'table_body_line': drop_verticals(base.table_body_line),
2383
+ 'table_end_line': drop_verticals(base.table_end_line),
2371
2384
  }
2372
2385
  if mode in ('frame', 'f'):
2373
2386
  def frame_only(sep):
@@ -5988,9 +6001,20 @@ class Table(object):
5988
6001
  for r in range(len(rows))]
5989
6002
  )
5990
6003
  style = options.pop('style_name', self.style_name)
6004
+ keep_missing = 'missing_val' not in options
6005
+ # Gaps carry this table's ``missing`` sentinel, which the new table
6006
+ # does not recognise: it rendered as a blank instead of the missing
6007
+ # value and the exports wrote its repr. Hand them over as the new
6008
+ # table's own sentinel.
5991
6009
  out = type(self).from_records(
5992
- new_rows, headers=new_headers, style_name=style, **options
6010
+ [], headers=new_headers, style_name=style, **options
5993
6011
  )
6012
+ if keep_missing:
6013
+ out.missing_value = self.__missing_value
6014
+ placer = self.__value_placer
6015
+ for row in new_rows:
6016
+ out.add_row([out.missing if cell is placer else cell
6017
+ for cell in row])
5994
6018
  return out
5995
6019
 
5996
6020
  def rotate(self, **options):
@@ -27,6 +27,7 @@ from typing import Any, List, Optional, Sequence
27
27
  from .fast import strip_ansi
28
28
  from .colors import background_hex, foreground_hex, spec_to_css
29
29
  from .options import FLT_FILTER, INT_FILTER
30
+ from .utils import to_roman
30
31
 
31
32
 
32
33
 
@@ -58,14 +59,37 @@ def _plain(value: Any) -> str:
58
59
 
59
60
 
60
61
  def _table_data(table, include_index: bool):
61
- """(headers, rows) as plain strings, honouring the index setting."""
62
+ """
63
+ (headers, rows) honouring the index setting.
64
+
65
+ Gaps hold the table's ``missing`` sentinel -- short rows padded by the
66
+ table, NaN and NULL from the readers, ``table.missing`` placed by hand.
67
+ It is an internal marker with no printable form, and every export used
68
+ to write its ``repr`` (``<flexablelib.utils.ValuePlacer object at ...>``)
69
+ into the CSV field, the Markdown cell or the record. It leaves here as
70
+ ``None``, which every writer already turns into an empty cell.
71
+ """
72
+ missing = table.missing
73
+ headers = [str(header) for header in table.headers]
74
+ rows = [
75
+ [None if cell is missing else cell for cell in row]
76
+ for row in table.rows
77
+ ]
62
78
  if include_index:
63
- headers = [str(header) for header in table.internal_headers]
64
- rows = table.internal_rows
65
- else:
66
- headers = [str(header) for header in table.headers]
67
- rows = table.rows
68
- return headers, [[cell for cell in row] for row in rows]
79
+ # The stored index column holds a counter object that only the
80
+ # renderer knows how to read, so exports wrote its ``repr`` in every
81
+ # row -- and left the column out altogether when ``show_index`` was
82
+ # off, although the Excel writer already shifted merges for it.
83
+ # Number the rows here the way the rendered index does.
84
+ start, step = table.index_start, table.index_step
85
+ roman = table.roman_index
86
+ labels = []
87
+ for row_i in range(len(rows)):
88
+ label = start + row_i * step
89
+ labels.append(to_roman(label) if roman else label)
90
+ headers = [str(table.index_title)] + headers
91
+ rows = [[label] + row for label, row in zip(labels, rows)]
92
+ return headers, rows
69
93
 
70
94
 
71
95
  def _effective_region_color(table, region):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.0.20
3
+ Version: 2.0.21
4
4
  Summary: Fast, dependency-free terminal tables for Python: 56 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Author: Benjamin Ramirez
@@ -39,10 +39,12 @@ tests/test_issues.py
39
39
  tests/test_merge_edge_matrix.py
40
40
  tests/test_merges.py
41
41
  tests/test_readme_examples.py
42
+ tests/test_style_line_widths.py
42
43
  tests/test_styles.py
43
44
  tests/test_text_width.py
44
45
  tests/test_two_pass_measurement.py
45
46
  tests/test_upstream_issues.py
47
+ tests/test_v2021_fixes.py
46
48
  tests/test_v2110_fixes.py
47
49
  tests/test_v213_features.py
48
50
  tests/test_v214_features.py
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexablelib",
3
- "version": "2.0.20",
3
+ "version": "2.0.21",
4
4
  "private": true,
5
5
  "description": "Flexible console and HTML tables for Python: styles, merges, colors, widths, decimal alignment.",
6
6
  "repository": {
@@ -0,0 +1,46 @@
1
+ """Every rendered line has the same terminal width, in every style.
2
+
3
+ Regression for ``plain``: its header separator line was one column short
4
+ because it had no junction between columns. Also pins that wide (CJK /
5
+ emoji) headers and ``column_max_width`` keep all lines aligned. Note that
6
+ ``*_eheader`` styles intentionally draw the header row without column
7
+ separators (documented design, not a bug).
8
+ """
9
+ import pytest
10
+
11
+ from flexablelib import Table
12
+ from flexablelib.style_compositions import __style_compositions as catalogue
13
+ from flexablelib.text_width import visible_width
14
+
15
+ CASES = [
16
+ (['名前', 'n'], [['日本語テキスト', 1.25], ['😀😀', -3]], {'名前': 4}),
17
+ (['名前', 'n'], [['日本語テキスト', 1.25], ['😀😀', -3]], None),
18
+ (['x', 'yy'], [['abc', 1], ['d', 2]], None),
19
+ (['東京', '😀値'], [['東京タワー展望台', 'x'], ['a', '👍 ok']], 3),
20
+ ]
21
+
22
+
23
+ @pytest.mark.parametrize('style', catalogue._fields)
24
+ @pytest.mark.parametrize('headers,rows,max_width', CASES)
25
+ def test_all_lines_same_width(style, headers, rows, max_width):
26
+ table = Table(rows=rows, headers=headers)
27
+ table.style_name = style
28
+ if max_width is not None:
29
+ table.column_max_width = max_width
30
+ lines = table.compose().split('\n')
31
+ widths = {visible_width(line) for line in lines}
32
+ assert len(widths) == 1, (style, [visible_width(l) for l in lines])
33
+
34
+
35
+ def test_plain_header_separator_spans_table():
36
+ table = Table(rows=[['abc', 1], ['d', 2]], headers=['x', 'yy'])
37
+ table.style_name = 'plain'
38
+ lines = table.compose().split('\n')
39
+ assert lines[1] == ' ' * len(lines[0])
40
+
41
+
42
+ def test_eheader_header_row_has_no_column_separator_by_design():
43
+ table = Table(rows=[['a', 'b']], headers=['x', 'y'])
44
+ table.style_name = 'grid_eheader'
45
+ assert table.compose().split('\n')[:3] == [
46
+ '+-------+', '| x y |', '+===+===+']
@@ -0,0 +1,262 @@
1
+ """Fixes and coverage added for 2.0.21."""
2
+ import pytest
3
+
4
+ from flexablelib import Table
5
+ from flexablelib.text_width import strip_ansi, visible_width
6
+
7
+
8
+ def _widths(text):
9
+ return {visible_width(line) for line in strip_ansi(text).split('\n')}
10
+
11
+
12
+ # --- exponent-only float columns ---------------------------------------------
13
+
14
+ @pytest.mark.parametrize('values', [
15
+ [1e20], [1e20, -2e30], [1e16, 12345], [1.5e-7, 2e-9],
16
+ ])
17
+ def test_float_column_without_any_point_stays_rectangular(values):
18
+ t = Table(rows=[[v] for v in values], headers=['x'])
19
+ t.style_name = 'grid'
20
+ out = t.compose()
21
+ assert len(_widths(out)) == 1, out
22
+ for v in values:
23
+ assert str(v) in out
24
+
25
+
26
+ def test_exponent_still_aligns_with_decimals_in_the_same_column():
27
+ t = Table(rows=[[1e20], [1.5]], headers=['x'])
28
+ lines = t.compose().split('\n')
29
+ assert len(_widths('\n'.join(lines))) == 1
30
+ body = [line for line in lines if '1e+20' in line or '1.5' in line]
31
+ # The integer part of 1.5 lines up with the end of the mantissa block.
32
+ assert body[0].index('1e+20') + len('1e+20') - 1 == body[1].index('1.5')
33
+
34
+
35
+ def test_exponent_column_next_to_other_columns_with_index():
36
+ t = Table(rows=[[1e20, 'a'], [3e21, 'bb']], headers=['n', 's'])
37
+ t.show_index = True
38
+ t.style_name = 'rounded'
39
+ assert len(_widths(t.compose())) == 1
40
+
41
+
42
+ # --- vrules='none' -----------------------------------------------------------
43
+
44
+ @pytest.mark.parametrize('style', [
45
+ 'grid', 'rounded', 'pretty_grid', 'dashes', 'ascii_rounded',
46
+ 'bold_header', 'pretty_columns', 'markdown',
47
+ ])
48
+ def test_vrules_none_rules_are_as_wide_as_the_rows(style):
49
+ t = Table(rows=[[1, 'ab'], [2.5, '漢字']], headers=['A', 'B'])
50
+ t.style_name = style
51
+ t.vrules = 'none'
52
+ out = t.compose()
53
+ assert len(_widths(out)) == 1, out
54
+
55
+
56
+ def test_vrules_none_draws_no_corners():
57
+ t = Table(rows=[[1, 2]], headers=['A', 'B'])
58
+ t.style_name = 'rounded'
59
+ t.vrules = 'none'
60
+ out = t.compose()
61
+ for corner in '╭╮╰╯├┤┬┴┼│':
62
+ assert corner not in out
63
+
64
+
65
+ def test_vrules_frame_keeps_the_outer_corners():
66
+ t = Table(rows=[[1, 2]], headers=['A', 'B'])
67
+ t.style_name = 'rounded'
68
+ t.vrules = 'frame'
69
+ out = t.compose()
70
+ assert out.split('\n')[0].startswith('╭')
71
+ assert out.split('\n')[-1].endswith('╯')
72
+ assert len(_widths(out)) == 1
73
+
74
+
75
+ # --- merge_cells argument types ----------------------------------------------
76
+
77
+ def test_merge_cells_rejects_a_pair_where_a_number_goes():
78
+ t = Table(rows=[[1, 2], [3, 4]], headers=['a', 'b'])
79
+ with pytest.raises(TypeError, match='first_row must be an integer'):
80
+ t.merge_cells((0, 0), (1, 1))
81
+ assert t.merged_regions == []
82
+
83
+
84
+ def test_merge_cells_rejects_floats():
85
+ t = Table(rows=[[1, 2], [3, 4]], headers=['a', 'b'])
86
+ with pytest.raises(TypeError, match='last_column must be an integer'):
87
+ t.merge_cells(0, 0, 1, 1.0)
88
+
89
+
90
+ def test_merge_cells_accepts_integer_like_objects():
91
+ class Idx:
92
+ def __init__(self, n):
93
+ self.n = n
94
+
95
+ def __index__(self):
96
+ return self.n
97
+
98
+ t = Table(rows=[[1, 2], [3, 4]], headers=['a', 'b'])
99
+ region = t.merge_cells(Idx(0), Idx(0), last_column=Idx(1), value='X')
100
+ assert (region.first_row, region.last_column) == (0, 1)
101
+ assert type(region.first_row) is int
102
+ assert 'X' in t.compose()
103
+
104
+
105
+ # --- coverage: public paths not exercised before -----------------------------
106
+
107
+ def test_init_with_columns_and_more_headers_pads_the_extra_column():
108
+ t = Table(columns=[[1, 2], [3, 4]], headers=['a', 'b', 'c'])
109
+ assert t.headers == ['a', 'b', 'c']
110
+ assert t.column_count == 3
111
+ assert t.to_records()[0] == {'a': 1, 'b': 3, 'c': None}
112
+
113
+
114
+ def test_init_with_rows_and_more_headers_pads_the_extra_column():
115
+ t = Table(rows=[[1, 2]], headers=['a', 'b', 'c'])
116
+ assert t.column_count == 3
117
+ assert t.to_records() == [{'a': 1, 'b': 2, 'c': None}]
118
+
119
+
120
+ def test_cell_valign_must_be_a_dict():
121
+ t = Table(rows=[[1, 2]], headers=['a', 'b'])
122
+ with pytest.raises(TypeError, match='cell_valign'):
123
+ t.cell_valign = [('t',)]
124
+ t.cell_valign = None
125
+ assert t.cell_valign == {}
126
+
127
+
128
+ def test_col_valign_list_is_normalised_per_column():
129
+ t = Table(rows=[['x\ny\nz', 1, 2]], headers=['a', 'b', 'c'])
130
+ t.col_valign = ['top', 'middle', 'bottom']
131
+ assert t.col_valign == ['t', 'm', 'b']
132
+ lines = t.compose().split('\n')
133
+ body = [line for line in lines if 'x' in line or 'y' in line or 'z' in line]
134
+ assert '1' in body[1] and '2' in body[2]
135
+
136
+
137
+ @pytest.mark.parametrize('args, message', [
138
+ ((0,), 'n must be >= 1'),
139
+ ((2, -1), 'start must be >= 0'),
140
+ ])
141
+ def test_divide_every_rejects_bad_arguments(args, message):
142
+ t = Table(rows=[[i] for i in range(4)], headers=['x'])
143
+ with pytest.raises(ValueError, match=message):
144
+ t.divide_every(*args)
145
+
146
+
147
+ def test_add_dividers_accepts_a_single_iterable():
148
+ t = Table(rows=[[i] for i in range(4)], headers=['x'], style_name='rounded')
149
+ plain = t.compose()
150
+ t.add_dividers([0, 2])
151
+ out = t.compose()
152
+ assert out.count('\n') == plain.count('\n') + 2
153
+
154
+
155
+ def test_title_wider_than_the_table_is_printed_whole():
156
+ t = Table(rows=[[1, 2]], headers=['a', 'b'])
157
+ t.title = 'a title much wider than the table'
158
+ out = t.compose()
159
+ assert out.split('\n')[0] == 'a title much wider than the table'
160
+
161
+
162
+ def test_paginate_without_frozen_header_shows_it_once():
163
+ t = Table(rows=[[i] for i in range(5)], headers=['head'])
164
+ pages = t.paginate(2, freeze_header=False)
165
+ assert len(pages) == 3
166
+ assert 'head' in pages[0]
167
+ assert all('head' not in page for page in pages[1:])
168
+
169
+
170
+ def test_shadow_with_coloured_border_keeps_every_line_equal():
171
+ t = Table(rows=[[1, 2]], headers=['a', 'b'])
172
+ t.shadow = True
173
+ t.border_color = 'red'
174
+ out = t.compose()
175
+ assert '░' in strip_ansi(out)
176
+ assert len(_widths(out)) == 1
177
+
178
+
179
+ # --- exports: gaps and the index column --------------------------------------
180
+
181
+ def _padded_table():
182
+ return Table(rows=[[1, 2], [3]], headers=['a', 'b', 'c'])
183
+
184
+
185
+ def test_exports_never_write_the_missing_sentinel():
186
+ t = _padded_table()
187
+ t.add_row([4, t.missing, 6])
188
+ outputs = [
189
+ t.to_csv(), t.to_markdown(), t.to_rst(), t.to_asciidoc(),
190
+ t.to_latex(), t.to_html(), str(t.to_records()),
191
+ ]
192
+ for out in outputs:
193
+ assert 'ValuePlacer' not in out
194
+ assert 'object at 0x' not in out
195
+ assert t.to_records() == [
196
+ {'a': 1, 'b': 2, 'c': None},
197
+ {'a': 3, 'b': None, 'c': None},
198
+ {'a': 4, 'b': None, 'c': 6},
199
+ ]
200
+ assert t.to_csv().splitlines() == ['a,b,c', '1,2,', '3,,', '4,,6']
201
+
202
+
203
+ def test_include_index_numbers_the_rows():
204
+ t = Table(rows=[[1, 2], [3, 4]], headers=['a', 'b'])
205
+ t.show_index = True
206
+ assert t.to_csv(include_index=True).splitlines() == [
207
+ 'i,a,b', '0,1,2', '1,3,4',
208
+ ]
209
+ for out in (t.to_markdown(include_index=True), t.to_rst(include_index=True),
210
+ t.to_latex(include_index=True), t.to_html(include_index=True),
211
+ t.to_asciidoc(include_index=True)):
212
+ assert 'IndexCounter' not in out
213
+
214
+
215
+ def test_include_index_follows_start_step_title_and_roman():
216
+ t = Table(rows=[[1], [2], [3]], headers=['a'])
217
+ t.show_index = True
218
+ t.index_title = '#'
219
+ t.index_start = 4
220
+ t.index_step = 2
221
+ assert [r['#'] for r in t.to_records(include_index=True)] == [4, 6, 8]
222
+ t.roman_index = True
223
+ assert [r['#'] for r in t.to_records(include_index=True)] == [
224
+ 'IV', 'VI', 'VIII',
225
+ ]
226
+
227
+
228
+ def test_include_index_works_without_show_index():
229
+ t = Table(rows=[[1, 2]], headers=['a', 'b'])
230
+ assert t.to_records(include_index=True) == [{'i': 0, 'a': 1, 'b': 2}]
231
+ assert t.to_records() == [{'a': 1, 'b': 2}]
232
+
233
+
234
+ def test_include_index_html_with_merge_has_one_cell_per_column():
235
+ t = Table(rows=[[1, 2], [3, 4]], headers=['a', 'b'])
236
+ t.merge_cells(0, 0, last_row=1, value='m')
237
+ html = t.to_html(include_index=True)
238
+ assert 'IndexCounter' not in html
239
+ assert 'rowspan="2"' in html
240
+
241
+
242
+ # --- transpose keeps gaps as gaps --------------------------------------------
243
+
244
+ def test_transpose_shows_the_missing_value_in_gaps():
245
+ t = Table(rows=[[1, 2], [3]], headers=['a', 'b', 'c'])
246
+ t.missing_value = '?'
247
+ out = t.transpose()
248
+ assert out.missing_value == '?'
249
+ text = out.compose()
250
+ assert text.count('?') == 3
251
+ assert out.to_csv().splitlines() == [
252
+ 'field,row0,row1', 'a,1,3', 'b,2,', 'c,,',
253
+ ]
254
+ assert 'ValuePlacer' not in out.to_csv()
255
+
256
+
257
+ def test_transpose_missing_val_option_wins():
258
+ t = Table(rows=[[1, 2], [3]], headers=['a', 'b'])
259
+ t.missing_value = '?'
260
+ out = t.transpose(missing_val='-')
261
+ assert '-' in out.compose().split('\n')[-2]
262
+ assert '?' not in out.compose()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes