flexablelib 2.2.1__tar.gz → 2.2.3__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.
- {flexablelib-2.2.1 → flexablelib-2.2.3}/CHANGELOG.md +31 -0
- {flexablelib-2.2.1/flexablelib.egg-info → flexablelib-2.2.3}/PKG-INFO +1 -1
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/table.py +70 -14
- {flexablelib-2.2.1 → flexablelib-2.2.3/flexablelib.egg-info}/PKG-INFO +1 -1
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib.egg-info/SOURCES.txt +2 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/package.json +1 -1
- flexablelib-2.2.3/tests/test_v222_fixes.py +72 -0
- flexablelib-2.2.3/tests/test_v223_fixes.py +66 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/LICENSE +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/MANIFEST.in +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/README.md +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/__init__.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/_speedups.c +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/_width_tables.h +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/cells.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/colors.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/columns.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/fast.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/merges.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/options.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/py.typed +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/readers.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/style_compositions.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/table_strings.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/text_width.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/utils.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib/writers.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/pytest.ini +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/setup.cfg +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/setup.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/style_examples.md +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/conftest.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/helpers.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_cells.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_columns.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_excel.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_features.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_issues.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_merges.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_readme_examples.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_style_line_widths.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_styles.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_text_width.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_upstream_issues.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v211_fixes.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v213_features.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v214_features.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v215_features.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v216_features.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v217_features.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v218_features.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v219_coverage.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v219_fixes.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v220_exports.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tests/test_v221_fixes.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tools/benchmark.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tools/generate_width_tables.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tools/readme_gallery.py +0 -0
- {flexablelib-2.2.1 → flexablelib-2.2.3}/tools/text_to_png.py +0 -0
|
@@ -2,6 +2,32 @@
|
|
|
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.2.3] - 2026-11-06
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- ``Table(headers=..., rows=...)`` with a short first row and a wider later
|
|
9
|
+
row no longer invents a ghost ``column N``. Padding now uses the live
|
|
10
|
+
column count after every row is loaded, so later cells that already fill
|
|
11
|
+
the remaining headers are enough.
|
|
12
|
+
- ``add_row`` / ``add_column`` reject bare ``str`` / ``bytes`` data with
|
|
13
|
+
``TypeError`` instead of expanding them into one cell per character.
|
|
14
|
+
``Table(rows=...)`` does the same for a string ``rows`` value or string
|
|
15
|
+
row entries. Wrap a single string cell in a list.
|
|
16
|
+
- ``show_empty_columns`` coerces with ``bool(...)``, matching
|
|
17
|
+
``show_empty_rows``.
|
|
18
|
+
|
|
19
|
+
## [2.2.2] - 2026-11-05
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- ``zebra = True`` (and ``row_stripe = True``) raised ``ColourError: unknown
|
|
23
|
+
colour: 'true'`` when ``use_colors`` was on. ``True`` now enables a default
|
|
24
|
+
odd-row ``reverse`` stripe; ``False`` clears it. Other non-spec values raise
|
|
25
|
+
``TypeError`` at assignment time instead of blowing up later in ``compose()``.
|
|
26
|
+
- ``parse_str_numbers = True`` before ``add_column`` / ``add_row`` left digit
|
|
27
|
+
strings unparsed, contrary to the documented "order does not matter". New
|
|
28
|
+
cells are parsed on the way in, matching ``set_cell`` and the re-parse that
|
|
29
|
+
already ran when the flag was turned on after the data was there.
|
|
30
|
+
|
|
5
31
|
## [2.2.1] - 2026-11-04
|
|
6
32
|
|
|
7
33
|
### Fixed
|
|
@@ -25,6 +51,11 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
25
51
|
(Linux manylinux + musllinux, Windows, macOS arm64; CPython 3.8-3.14) and
|
|
26
52
|
the sdist, checks the count and that the tag matches ``package.json``, and
|
|
27
53
|
is safe to re-run. One run per ref (``concurrency``).
|
|
54
|
+
- The real reason the macOS job never started: GitHub's hosted macOS arm64
|
|
55
|
+
runners are short of capacity, and a job no runner picks up is cancelled
|
|
56
|
+
after ~15 minutes. A new ``wheels-retry`` workflow re-runs the failed or
|
|
57
|
+
cancelled jobs of a tag run (up to three more attempts), so publishing
|
|
58
|
+
finishes on its own.
|
|
28
59
|
- Actions moved off Node 20: ``checkout@v5``, ``setup-python@v6``,
|
|
29
60
|
``upload-artifact@v6``, ``download-artifact@v7``.
|
|
30
61
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.3
|
|
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
|
|
@@ -952,19 +952,39 @@ class Table(object):
|
|
|
952
952
|
self.__check_add_header_on_init(header)
|
|
953
953
|
except TypeError:
|
|
954
954
|
pass
|
|
955
|
+
if isinstance(rows, (str, bytes)):
|
|
956
|
+
raise TypeError(
|
|
957
|
+
'Table() rows must be a sequence of rows, not '
|
|
958
|
+
f'{type(rows).__name__}'
|
|
959
|
+
)
|
|
955
960
|
try:
|
|
956
|
-
|
|
961
|
+
rows_iter = iter(rows)
|
|
962
|
+
except TypeError:
|
|
963
|
+
rows_iter = None
|
|
964
|
+
if rows_iter is not None:
|
|
965
|
+
for row in rows_iter:
|
|
966
|
+
if isinstance(row, (str, bytes)):
|
|
967
|
+
raise TypeError(
|
|
968
|
+
'Table() row entries must be sequences of cells, not '
|
|
969
|
+
f'{type(row).__name__}; wrap a single value in a list'
|
|
970
|
+
)
|
|
957
971
|
try:
|
|
958
972
|
row.__iter__
|
|
959
|
-
self.add_row(data=list(row))
|
|
960
973
|
except AttributeError:
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
974
|
+
continue
|
|
975
|
+
self.add_row(data=list(row))
|
|
976
|
+
# Activate any headers the rows did not already fill. Use the
|
|
977
|
+
# live column count, not len(rows[0]): a short first row followed
|
|
978
|
+
# by a wider one used to spawn a ghost "column N" because the
|
|
979
|
+
# padding arithmetic ignored later rows that had already claimed
|
|
980
|
+
# the remaining headers.
|
|
981
|
+
try:
|
|
982
|
+
n_headers = len(headers)
|
|
983
|
+
except TypeError:
|
|
984
|
+
n_headers = 0
|
|
985
|
+
for _ in range(max(0, n_headers - self.__real_column_count)):
|
|
964
986
|
self.add_column()
|
|
965
987
|
return None
|
|
966
|
-
except (TypeError, IndexError):
|
|
967
|
-
pass
|
|
968
988
|
try:
|
|
969
989
|
for column in columns:
|
|
970
990
|
try:
|
|
@@ -1455,7 +1475,8 @@ class Table(object):
|
|
|
1455
1475
|
"""
|
|
1456
1476
|
Alternating body-row colours (Rich ``row_styles`` / zebra striping).
|
|
1457
1477
|
|
|
1458
|
-
Accepts ``None`` (off),
|
|
1478
|
+
Accepts ``None`` / ``False`` (off), ``True`` (default striping:
|
|
1479
|
+
odd rows in ``reverse``), a single colour spec applied to odd rows
|
|
1459
1480
|
(1, 3, …), or a two-item sequence ``(even_spec, odd_spec)``. Empty
|
|
1460
1481
|
/ falsy specs leave that parity uncoloured. Alias: :attr:`row_stripe`.
|
|
1461
1482
|
"""
|
|
@@ -1945,11 +1966,21 @@ class Table(object):
|
|
|
1945
1966
|
|
|
1946
1967
|
@zebra.setter
|
|
1947
1968
|
def zebra(self, value):
|
|
1969
|
+
if value is True:
|
|
1970
|
+
# Common "just turn it on" request; reverse works on every terminal.
|
|
1971
|
+
value = ('', 'reverse')
|
|
1972
|
+
elif value is False:
|
|
1973
|
+
value = None
|
|
1974
|
+
elif value is not None and not isinstance(value, (str, list, tuple)):
|
|
1975
|
+
raise TypeError(
|
|
1976
|
+
'zebra must be None, False, True, a colour spec, or a '
|
|
1977
|
+
f'(even_spec, odd_spec) pair, got {type(value).__name__}'
|
|
1978
|
+
)
|
|
1948
1979
|
self.__zebra = value
|
|
1949
1980
|
|
|
1950
1981
|
@row_stripe.setter
|
|
1951
1982
|
def row_stripe(self, value):
|
|
1952
|
-
self.
|
|
1983
|
+
self.zebra = value
|
|
1953
1984
|
|
|
1954
1985
|
@footer_rows.setter
|
|
1955
1986
|
def footer_rows(self, value):
|
|
@@ -2281,7 +2312,7 @@ class Table(object):
|
|
|
2281
2312
|
|
|
2282
2313
|
@show_empty_columns.setter
|
|
2283
2314
|
def show_empty_columns(self, value: bool):
|
|
2284
|
-
self.__show_empty_columns = value
|
|
2315
|
+
self.__show_empty_columns = bool(value)
|
|
2285
2316
|
|
|
2286
2317
|
@property
|
|
2287
2318
|
def hide_columns(self):
|
|
@@ -2621,6 +2652,31 @@ class Table(object):
|
|
|
2621
2652
|
if isinstance(cell, str):
|
|
2622
2653
|
row[index] = parse_value(cell, True)
|
|
2623
2654
|
|
|
2655
|
+
def __coerce_incoming_value(self, value):
|
|
2656
|
+
"""Parse a newly added cell when ``parse_str_numbers`` is on."""
|
|
2657
|
+
if self.__parse_str_numbers and isinstance(value, str):
|
|
2658
|
+
from .readers import parse_value
|
|
2659
|
+
return parse_value(value, True)
|
|
2660
|
+
return value
|
|
2661
|
+
|
|
2662
|
+
def __coerce_incoming_sequence(self, data):
|
|
2663
|
+
"""Copy ``data`` with ``__coerce_incoming_value`` applied to each cell.
|
|
2664
|
+
|
|
2665
|
+
``str`` and ``bytes`` are rejected: both are iterable, so a bare
|
|
2666
|
+
``add_row('abc')`` or ``add_column('h', 'abc')`` used to expand into
|
|
2667
|
+
one cell per character. Pass a list/tuple of cells instead.
|
|
2668
|
+
"""
|
|
2669
|
+
if data is None:
|
|
2670
|
+
return data
|
|
2671
|
+
if isinstance(data, (str, bytes)):
|
|
2672
|
+
raise TypeError(
|
|
2673
|
+
'row/column data must be a sequence of cells, not '
|
|
2674
|
+
f'{type(data).__name__}; wrap a single value in a list'
|
|
2675
|
+
)
|
|
2676
|
+
if not self.__parse_str_numbers:
|
|
2677
|
+
return data
|
|
2678
|
+
return [self.__coerce_incoming_value(cell) for cell in data]
|
|
2679
|
+
|
|
2624
2680
|
@property
|
|
2625
2681
|
def missing(self):
|
|
2626
2682
|
"""
|
|
@@ -3142,6 +3198,7 @@ class Table(object):
|
|
|
3142
3198
|
# top, which is right for a column that row had just created and
|
|
3143
3199
|
# wrong for this one, and its values came out shifted down by one.
|
|
3144
3200
|
is_new_column = checked_header not in self.__headers
|
|
3201
|
+
data = self.__coerce_incoming_sequence(data)
|
|
3145
3202
|
if is_new_column:
|
|
3146
3203
|
self.__add_header(checked_header)
|
|
3147
3204
|
self.__add_column_data(
|
|
@@ -3334,7 +3391,7 @@ class Table(object):
|
|
|
3334
3391
|
Add a row to the table. Can be left empty to add
|
|
3335
3392
|
an empty row.
|
|
3336
3393
|
|
|
3337
|
-
``data``:
|
|
3394
|
+
``data``: Sequence of cell values (list or tuple). Bare ``str``/``bytes`` are rejected.
|
|
3338
3395
|
|
|
3339
3396
|
Example::
|
|
3340
3397
|
|
|
@@ -3358,6 +3415,7 @@ class Table(object):
|
|
|
3358
3415
|
... | size 5 | 39865 |
|
|
3359
3416
|
... +----------+------------+
|
|
3360
3417
|
"""
|
|
3418
|
+
data = self.__coerce_incoming_sequence(data)
|
|
3361
3419
|
self.__columns_with_i[self.__index_title].append(self.__index_counter)
|
|
3362
3420
|
added_to_column_count = self.__add_row_data(data)
|
|
3363
3421
|
add_headers = True if added_to_column_count is not None else False
|
|
@@ -3406,9 +3464,7 @@ class Table(object):
|
|
|
3406
3464
|
f'{column_count} columns'
|
|
3407
3465
|
)
|
|
3408
3466
|
column_i = column % column_count
|
|
3409
|
-
|
|
3410
|
-
from .readers import parse_value
|
|
3411
|
-
value = parse_value(value, True)
|
|
3467
|
+
value = self.__coerce_incoming_value(value)
|
|
3412
3468
|
header = self.__headers[column_i]
|
|
3413
3469
|
# Both orientations hold the same data and both are read while
|
|
3414
3470
|
# rendering, so all four stores change together.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.3
|
|
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
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""2.2.2 regressions: zebra=True and parse_str_numbers on add_column/add_row."""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from flexablelib import Table
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
ANSI = re.compile(r'\x1b\[[0-9;]*m')
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def bare(text: str) -> str:
|
|
13
|
+
return ANSI.sub('', text)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_zebra_true_turns_on_default_striping():
|
|
17
|
+
table = Table(rows=[[1], [2], [3]], headers=['n'])
|
|
18
|
+
table.use_colors = True
|
|
19
|
+
table.zebra = True
|
|
20
|
+
assert table.zebra == ('', 'reverse')
|
|
21
|
+
coloured = table.compose()
|
|
22
|
+
assert '\x1b[' in coloured
|
|
23
|
+
assert '1' in bare(coloured) and '2' in bare(coloured)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_zebra_false_clears_striping():
|
|
27
|
+
table = Table(rows=[[1], [2]], headers=['n'])
|
|
28
|
+
table.zebra = True
|
|
29
|
+
table.zebra = False
|
|
30
|
+
assert table.zebra is None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_row_stripe_true_matches_zebra():
|
|
34
|
+
table = Table(rows=[[1], [2]], headers=['n'])
|
|
35
|
+
table.row_stripe = True
|
|
36
|
+
assert table.zebra == ('', 'reverse')
|
|
37
|
+
assert table.row_stripe == ('', 'reverse')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_zebra_rejects_non_colour_objects():
|
|
41
|
+
table = Table()
|
|
42
|
+
with pytest.raises(TypeError, match='zebra must be'):
|
|
43
|
+
table.zebra = 3
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_parse_str_numbers_before_add_column():
|
|
47
|
+
"""Docs: order of the flag and the data must not matter."""
|
|
48
|
+
table = Table()
|
|
49
|
+
table.parse_str_numbers = True
|
|
50
|
+
table.add_column('n', ['10', '20', '3.5', 'x'])
|
|
51
|
+
assert table.rows == [[10], [20], [3.5], ['x']]
|
|
52
|
+
# Numeric column stays right-aligned once typed.
|
|
53
|
+
assert ' 10' in bare(table.compose()) or '| 10' in bare(table.compose())
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_parse_str_numbers_before_add_row():
|
|
57
|
+
table = Table()
|
|
58
|
+
table.parse_str_numbers = True
|
|
59
|
+
table.add_column('a')
|
|
60
|
+
table.add_column('b')
|
|
61
|
+
# Replace empty placeholders by adding typed rows via a fresh table.
|
|
62
|
+
table = Table()
|
|
63
|
+
table.parse_str_numbers = True
|
|
64
|
+
table.add_row(['1', '2.5'])
|
|
65
|
+
table.add_row(['3', 'x'])
|
|
66
|
+
assert table.rows == [[1, 2.5], [3, 'x']]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_parse_str_numbers_off_keeps_digit_strings():
|
|
70
|
+
table = Table()
|
|
71
|
+
table.add_column('code', ['007', '1.50'])
|
|
72
|
+
assert table.rows == [['007'], ['1.50']]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""2.2.3 regressions: constructor jagged rows, str data rejection, bool coerce."""
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from flexablelib import Table
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_constructor_jagged_rows_do_not_spawn_ghost_column():
|
|
8
|
+
"""A short first row must not invent a column after a wider later row."""
|
|
9
|
+
table = Table(headers=['a', 'b'], rows=[[1], [2, 3]])
|
|
10
|
+
assert table.headers == ['a', 'b']
|
|
11
|
+
assert table.column_count == 2
|
|
12
|
+
assert table.rows == [[1, None], [2, 3]]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_constructor_jagged_rows_with_three_headers():
|
|
16
|
+
table = Table(headers=['a', 'b', 'c'], rows=[[1, 2], [3, 4, 5]])
|
|
17
|
+
assert table.headers == ['a', 'b', 'c']
|
|
18
|
+
assert table.column_count == 3
|
|
19
|
+
assert table.rows == [[1, 2, None], [3, 4, 5]]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_constructor_more_headers_than_first_row_still_keeps_them():
|
|
23
|
+
table = Table(headers=['a', 'b', 'c', 'd'], rows=[[1, 2]])
|
|
24
|
+
assert table.headers == ['a', 'b', 'c', 'd']
|
|
25
|
+
assert table.column_count == 4
|
|
26
|
+
assert table.rows == [[1, 2, None, None]]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_add_row_rejects_bare_string():
|
|
30
|
+
table = Table()
|
|
31
|
+
with pytest.raises(TypeError, match='sequence of cells'):
|
|
32
|
+
table.add_row('not-cells')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_add_column_rejects_bare_string_data():
|
|
36
|
+
table = Table()
|
|
37
|
+
with pytest.raises(TypeError, match='sequence of cells'):
|
|
38
|
+
table.add_column('name', 'abc')
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_add_row_accepts_single_string_cell_in_a_list():
|
|
42
|
+
table = Table()
|
|
43
|
+
table.add_row(['hello'])
|
|
44
|
+
assert table.rows == [['hello']]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_constructor_rejects_string_row_entries():
|
|
48
|
+
with pytest.raises(TypeError, match='sequences of cells'):
|
|
49
|
+
Table(rows=['ab', 'cd'])
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_constructor_rejects_rows_as_string():
|
|
53
|
+
with pytest.raises(TypeError, match='sequence of rows'):
|
|
54
|
+
Table(rows='ab')
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_show_empty_columns_coerces_to_bool():
|
|
58
|
+
table = Table()
|
|
59
|
+
table.add_column('a', [1, 2])
|
|
60
|
+
table.add_column('b', ['', ''])
|
|
61
|
+
table.show_empty_columns = 0
|
|
62
|
+
assert table.show_empty_columns is False
|
|
63
|
+
assert 'b' not in table.compose()
|
|
64
|
+
table.show_empty_columns = 1
|
|
65
|
+
assert table.show_empty_columns is True
|
|
66
|
+
assert 'b' in table.compose()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|