flexablelib 2.3.0__tar.gz → 2.3.1__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.3.0 → flexablelib-2.3.1}/CHANGELOG.md +21 -0
- {flexablelib-2.3.0/flexablelib.egg-info → flexablelib-2.3.1}/PKG-INFO +1 -1
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/table.py +8 -4
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/utils.py +0 -80
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/writers.py +1 -1
- {flexablelib-2.3.0 → flexablelib-2.3.1/flexablelib.egg-info}/PKG-INFO +1 -1
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib.egg-info/SOURCES.txt +3 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/package.json +1 -1
- flexablelib-2.3.1/tests/test_align_indicators.py +77 -0
- flexablelib-2.3.1/tests/test_public_api_edges.py +63 -0
- flexablelib-2.3.1/tests/test_v231_fixes.py +31 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/LICENSE +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/MANIFEST.in +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/README.md +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/__init__.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/_speedups.c +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/_width_tables.h +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/cells.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/colors.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/columns.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/fast.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/merges.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/options.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/py.typed +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/readers.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/style_compositions.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/table_strings.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib/text_width.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/pytest.ini +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/setup.cfg +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/setup.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/style_examples.md +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/conftest.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/helpers.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_cells.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_columns.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_excel.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_features.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_issues.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_merges.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_readme_examples.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_stress_matrix.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_style_line_widths.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_styles.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_text_width.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_upstream_issues.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v211_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v213_features.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v214_features.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v215_features.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v216_features.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v217_features.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v218_features.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v219_coverage.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v219_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v220_exports.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v221_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v222_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v223_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v224_fixes.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tests/test_v230_none.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tools/benchmark.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tools/generate_width_tables.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tools/readme_gallery.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tools/stress_matrix.py +0 -0
- {flexablelib-2.3.0 → flexablelib-2.3.1}/tools/text_to_png.py +0 -0
|
@@ -2,6 +2,27 @@
|
|
|
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.3.1] - 2026-11-10
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- ``to_html(paginate=None)`` raised ``TypeError``; ``None`` now means no
|
|
9
|
+
paging, like ``0``.
|
|
10
|
+
- ``index_start = None`` / ``index_step = None`` raised ``TypeError``;
|
|
11
|
+
they now fall back to the defaults (``0`` and ``1``), as non-numeric
|
|
12
|
+
strings already did.
|
|
13
|
+
|
|
14
|
+
### Internal
|
|
15
|
+
- Removed unused helpers from ``flexablelib.utils`` (``float_format``,
|
|
16
|
+
``is_list``/``is_tuple``/``is_dict``/``is_set``/``is_str``/``is_bytes``,
|
|
17
|
+
``length_of_elements``, ``flatten``, ``delete_repetitions``). None were
|
|
18
|
+
part of the public API or called anywhere in the package.
|
|
19
|
+
- Tests for alignment indicators on ``pipes`` and ``sticks``: centred and
|
|
20
|
+
right markers, wide characters, one-character and zero-width columns.
|
|
21
|
+
- Behaviour tests for public edge paths: `add_dividers` with one iterable,
|
|
22
|
+
`hrules=True`, invalid `hrules`/`vrules`/`border_text` arguments,
|
|
23
|
+
`clear_border_texts`, non-callable `row_filter`/`color_rule`, and
|
|
24
|
+
out-of-range `hide_columns`.
|
|
25
|
+
|
|
5
26
|
## [2.3.0] - 2026-11-07
|
|
6
27
|
|
|
7
28
|
### Changed (visible behaviour)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.1
|
|
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
|
|
@@ -2170,14 +2170,18 @@ class Table(object):
|
|
|
2170
2170
|
def index_start(self, value: int):
|
|
2171
2171
|
try:
|
|
2172
2172
|
self.__i_start = int(value)
|
|
2173
|
-
except ValueError:
|
|
2173
|
+
except (TypeError, ValueError):
|
|
2174
|
+
# None or any non-numeric value falls back to the default,
|
|
2175
|
+
# the same way a non-numeric string always has.
|
|
2174
2176
|
self.__i_start = 0
|
|
2175
2177
|
|
|
2176
2178
|
@index_step.setter
|
|
2177
2179
|
def index_step(self, value: int):
|
|
2178
2180
|
try:
|
|
2179
2181
|
self.__i_step = int(value)
|
|
2180
|
-
except ValueError:
|
|
2182
|
+
except (TypeError, ValueError):
|
|
2183
|
+
# None or any non-numeric value falls back to the default,
|
|
2184
|
+
# the same way a non-numeric string always has.
|
|
2181
2185
|
self.__i_step = 1
|
|
2182
2186
|
|
|
2183
2187
|
@index_title.setter
|
|
@@ -6698,8 +6702,8 @@ class Table(object):
|
|
|
6698
6702
|
Write a self-contained HTML page with sorting, filtering and paging.
|
|
6699
6703
|
|
|
6700
6704
|
Everything is inline -- no external requests -- so the file works
|
|
6701
|
-
offline and from a file:// URL. ``paginate`` is the page size; 0
|
|
6702
|
-
every row on one page. Returns the markup when no target is given.
|
|
6705
|
+
offline and from a file:// URL. ``paginate`` is the page size; 0,
|
|
6706
|
+
False or None put every row on one page. Returns the markup when no target is given.
|
|
6703
6707
|
"""
|
|
6704
6708
|
from .writers import to_html
|
|
6705
6709
|
return to_html(self, target, title, paginate, include_index,
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import json
|
|
3
3
|
import shutil
|
|
4
|
-
from typing import Iterable, Union
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def float_format(number, decimal_spaces):
|
|
8
|
-
return ''.join(['{:.', str(decimal_spaces), 'f}']).format(number)
|
|
9
4
|
|
|
10
5
|
|
|
11
6
|
def get_window_size():
|
|
@@ -32,30 +27,6 @@ def get_window_size():
|
|
|
32
27
|
return size.columns, size.lines
|
|
33
28
|
|
|
34
29
|
|
|
35
|
-
def is_list(piece):
|
|
36
|
-
return isinstance(piece, list)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def is_tuple(piece):
|
|
40
|
-
return isinstance(piece, tuple)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def is_dict(piece):
|
|
44
|
-
return isinstance(piece, dict)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def is_set(piece):
|
|
48
|
-
return isinstance(piece, set)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def is_str(piece):
|
|
52
|
-
return isinstance(piece, str)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def is_bytes(piece):
|
|
56
|
-
return isinstance(piece, bytes)
|
|
57
|
-
|
|
58
|
-
|
|
59
30
|
def is_some_instance(piece, *instances):
|
|
60
31
|
"""
|
|
61
32
|
Returns True if the data piece is any instance of the requested.
|
|
@@ -104,50 +75,9 @@ def is_multi_row(row):
|
|
|
104
75
|
return all(isinstance(cell, (list, tuple)) for cell in row)
|
|
105
76
|
|
|
106
77
|
|
|
107
|
-
def length_of_elements(element_list, index=0, lengths=None):
|
|
108
|
-
"""
|
|
109
|
-
Returns the length of each row (sub-array) in a single array
|
|
110
|
-
"""
|
|
111
|
-
if lengths is None:
|
|
112
|
-
lengths = []
|
|
113
|
-
# Will only calculate len if index is lower than the len of the array.
|
|
114
|
-
# If it isn't less, will return the final array of lengths.
|
|
115
|
-
if index < len(element_list):
|
|
116
|
-
|
|
117
|
-
# Appends the length of the current element using the
|
|
118
|
-
# "index" param, which starts as 0.
|
|
119
|
-
lengths.append(len(element_list[index]))
|
|
120
|
-
|
|
121
|
-
# For each time it appends a length, calls again the function, sending
|
|
122
|
-
# the listOfElements, the lengths array with the previous value\s and the
|
|
123
|
-
# index plus 1, last one so looks for the next element
|
|
124
|
-
length_of_elements(element_list, index + 1, lengths)
|
|
125
|
-
|
|
126
|
-
return lengths
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def flatten(list_to_flatten, i=0, c=0):
|
|
130
|
-
"""
|
|
131
|
-
Flatten a list containing lists that could also contain lists,
|
|
132
|
-
and so on
|
|
133
|
-
"""
|
|
134
|
-
c += 1
|
|
135
|
-
if i < len(list_to_flatten):
|
|
136
|
-
if is_list(list_to_flatten[i]):
|
|
137
|
-
temp = list_to_flatten.pop(i)
|
|
138
|
-
for x in range(len(temp)):
|
|
139
|
-
list_to_flatten.insert(i + x, temp[x])
|
|
140
|
-
return flatten(list_to_flatten, i, c)
|
|
141
|
-
else:
|
|
142
|
-
return flatten(list_to_flatten, i + 1, c)
|
|
143
|
-
else:
|
|
144
|
-
return list_to_flatten
|
|
145
|
-
|
|
146
|
-
|
|
147
78
|
def read_json(file):
|
|
148
79
|
with open(file) as json_file:
|
|
149
80
|
data = json.load(json_file)
|
|
150
|
-
json_file.close()
|
|
151
81
|
return data
|
|
152
82
|
|
|
153
83
|
|
|
@@ -163,16 +93,6 @@ def read_file(filename):
|
|
|
163
93
|
return file.read()
|
|
164
94
|
|
|
165
95
|
|
|
166
|
-
def delete_repetitions(iterable: Iterable,
|
|
167
|
-
) -> Union[list, tuple]:
|
|
168
|
-
cleansed_list = []
|
|
169
|
-
for element in iterable:
|
|
170
|
-
if element not in cleansed_list:
|
|
171
|
-
cleansed_list.append(element)
|
|
172
|
-
|
|
173
|
-
return cleansed_list
|
|
174
|
-
|
|
175
|
-
|
|
176
96
|
class IndexColumnTitle(str):
|
|
177
97
|
"""
|
|
178
98
|
The header of the index column.
|
|
@@ -638,7 +638,7 @@ def to_html(table, target=None, title: str = 'Table', paginate: int = 25,
|
|
|
638
638
|
'rows': row_texts,
|
|
639
639
|
'keys': keys,
|
|
640
640
|
'numeric': numeric_flags,
|
|
641
|
-
'perPage': max(0, int(paginate)),
|
|
641
|
+
'perPage': max(0, int(paginate or 0)),
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
head_cells = ''.join(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.1
|
|
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
|
|
@@ -31,6 +31,7 @@ flexablelib.egg-info/requires.txt
|
|
|
31
31
|
flexablelib.egg-info/top_level.txt
|
|
32
32
|
tests/conftest.py
|
|
33
33
|
tests/helpers.py
|
|
34
|
+
tests/test_align_indicators.py
|
|
34
35
|
tests/test_cells.py
|
|
35
36
|
tests/test_columns.py
|
|
36
37
|
tests/test_excel.py
|
|
@@ -38,6 +39,7 @@ tests/test_features.py
|
|
|
38
39
|
tests/test_issues.py
|
|
39
40
|
tests/test_merge_edge_matrix.py
|
|
40
41
|
tests/test_merges.py
|
|
42
|
+
tests/test_public_api_edges.py
|
|
41
43
|
tests/test_readme_examples.py
|
|
42
44
|
tests/test_stress_matrix.py
|
|
43
45
|
tests/test_style_line_widths.py
|
|
@@ -63,6 +65,7 @@ tests/test_v222_fixes.py
|
|
|
63
65
|
tests/test_v223_fixes.py
|
|
64
66
|
tests/test_v224_fixes.py
|
|
65
67
|
tests/test_v230_none.py
|
|
68
|
+
tests/test_v231_fixes.py
|
|
66
69
|
tools/benchmark.py
|
|
67
70
|
tools/generate_width_tables.py
|
|
68
71
|
tools/readme_gallery.py
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Alignment indicators on the align-sensitive styles (pipes, sticks).
|
|
2
|
+
|
|
3
|
+
Every column's separator segment must name that column's alignment and be
|
|
4
|
+
exactly as wide as the cells under it, whatever the alignment, the width or
|
|
5
|
+
the characters in the cells.
|
|
6
|
+
"""
|
|
7
|
+
import re
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from flexablelib import Table
|
|
12
|
+
from flexablelib.text_width import visible_width
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _render(rows, headers, style, align):
|
|
16
|
+
table = Table(rows=rows, headers=headers, style_name=style)
|
|
17
|
+
table.col_alignment = align
|
|
18
|
+
return str(table).splitlines()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _segments(line, sep):
|
|
22
|
+
return line.strip(sep).split(sep)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _assert_rules_match_cells(lines, rule_sep, cell_sep='|'):
|
|
26
|
+
cell_widths = [visible_width(s) for s in _segments(lines[1], cell_sep)]
|
|
27
|
+
for line in lines:
|
|
28
|
+
if line.startswith(rule_sep):
|
|
29
|
+
rule = [visible_width(s) for s in _segments(line, rule_sep)]
|
|
30
|
+
assert rule == cell_widths, line
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
ROWS = [['a', 1, 'x'], ['bbb', 22, 'yyyyyy']]
|
|
34
|
+
HEADERS = ['L', 'R', 'Center']
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_pipes_marks_left_right_and_center():
|
|
38
|
+
lines = _render(ROWS, HEADERS, 'pipes', ['l', 'r', 'c'])
|
|
39
|
+
left, right, center = _segments(lines[1], '|')
|
|
40
|
+
assert re.fullmatch(r' :-+ ', left)
|
|
41
|
+
assert re.fullmatch(r' -+: ', right)
|
|
42
|
+
assert re.fullmatch(r' :-+: ', center)
|
|
43
|
+
_assert_rules_match_cells(lines, '|')
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_sticks_marks_each_alignment():
|
|
47
|
+
lines = _render(ROWS, HEADERS, 'sticks', ['l', 'r', 'c'])
|
|
48
|
+
left, right, center = _segments(lines[0], '+')
|
|
49
|
+
assert '~<~' in left
|
|
50
|
+
assert '~>~' in right
|
|
51
|
+
assert '~^~' in center
|
|
52
|
+
_assert_rules_match_cells(lines, '+')
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@pytest.mark.parametrize('style, rule_sep', [('pipes', '|'), ('sticks', '+')])
|
|
56
|
+
def test_centered_wide_characters_keep_rules_aligned(style, rule_sep):
|
|
57
|
+
lines = _render(
|
|
58
|
+
[['漢字', 1.5], ['😀', 22.25]], ['名前', '数'], style, 'c'
|
|
59
|
+
)
|
|
60
|
+
_assert_rules_match_cells(lines, rule_sep)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@pytest.mark.parametrize('style, rule_sep', [('pipes', '|'), ('sticks', '+')])
|
|
64
|
+
def test_centered_one_char_columns_drop_margins_not_width(style, rule_sep):
|
|
65
|
+
lines = _render([['a', 'b'], ['c', 'd']], ['x', 'y'], style, 'c')
|
|
66
|
+
_assert_rules_match_cells(lines, rule_sep)
|
|
67
|
+
marker = ':-:' if style == 'pipes' else '~^~'
|
|
68
|
+
assert _segments(lines[1 if style == 'pipes' else 0], rule_sep) == [
|
|
69
|
+
marker, marker
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_column_too_narrow_for_indicator_gets_plain_rule():
|
|
74
|
+
lines = _render([['', 1], ['', 2]], ['', 'n'], 'sticks', ['l', 'r'])
|
|
75
|
+
_assert_rules_match_cells(lines, '+')
|
|
76
|
+
empty_segment = _segments(lines[0], '+')[0]
|
|
77
|
+
assert '~' not in empty_segment
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from flexablelib import Table
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _table():
|
|
7
|
+
return Table(rows=[[1, 'a'], [2, 'b'], [3, 'c']], headers=['n', 's'])
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_add_dividers_accepts_one_iterable():
|
|
11
|
+
by_iterable = _table()
|
|
12
|
+
by_iterable.add_dividers([0, 1])
|
|
13
|
+
by_args = _table()
|
|
14
|
+
by_args.add_dividers(0, 1)
|
|
15
|
+
assert by_iterable.compose() == by_args.compose()
|
|
16
|
+
assert by_iterable.compose() != _table().compose()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_hrules_true_means_all():
|
|
20
|
+
table = _table()
|
|
21
|
+
table.hrules = True
|
|
22
|
+
assert table.hrules == 'all'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_invalid_hrules_and_vrules_raise():
|
|
26
|
+
table = _table()
|
|
27
|
+
with pytest.raises(ValueError):
|
|
28
|
+
table.hrules = 'sometimes'
|
|
29
|
+
with pytest.raises(ValueError):
|
|
30
|
+
table.vrules = 'sometimes'
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_border_text_rejects_unknown_where_and_align():
|
|
34
|
+
table = _table()
|
|
35
|
+
with pytest.raises(ValueError, match='where'):
|
|
36
|
+
table.border_text('x', where='middle')
|
|
37
|
+
with pytest.raises(ValueError, match='align'):
|
|
38
|
+
table.border_text('x', align='justify')
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_clear_border_texts_restores_plain_render():
|
|
42
|
+
table = _table()
|
|
43
|
+
plain = table.compose()
|
|
44
|
+
table.border_text('hi', where='bottom')
|
|
45
|
+
assert table.compose() != plain
|
|
46
|
+
assert table.clear_border_texts() is table
|
|
47
|
+
assert table.compose() == plain
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.parametrize('name', ['row_filter', 'color_rule'])
|
|
51
|
+
def test_callable_options_reject_non_callables(name):
|
|
52
|
+
table = _table()
|
|
53
|
+
with pytest.raises(TypeError):
|
|
54
|
+
setattr(table, name, 'not callable')
|
|
55
|
+
setattr(table, name, None)
|
|
56
|
+
assert getattr(table, name) is None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_hide_columns_out_of_range_index_raises():
|
|
60
|
+
table = _table()
|
|
61
|
+
table.hide_columns = [5]
|
|
62
|
+
with pytest.raises(ValueError, match='out of range'):
|
|
63
|
+
table.compose()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from flexablelib import Table
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _table():
|
|
5
|
+
return Table(rows=[[10, 'a'], [20, 'b']], headers=['n', 's'])
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_to_html_paginate_none_shows_all_rows():
|
|
9
|
+
html = _table().to_html(paginate=None)
|
|
10
|
+
assert '"perPage": 0' in html
|
|
11
|
+
assert html == _table().to_html(paginate=0)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_index_start_none_falls_back_to_zero():
|
|
15
|
+
table = _table()
|
|
16
|
+
table.index_start = 5
|
|
17
|
+
table.index_start = None
|
|
18
|
+
assert table.index_start == 0
|
|
19
|
+
table.show_index = True
|
|
20
|
+
lines = table.compose().splitlines()
|
|
21
|
+
assert any('| 0 |' in line for line in lines)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_index_step_none_falls_back_to_one():
|
|
25
|
+
table = _table()
|
|
26
|
+
table.index_step = 3
|
|
27
|
+
table.index_step = None
|
|
28
|
+
assert table.index_step == 1
|
|
29
|
+
table.show_index = True
|
|
30
|
+
out = table.compose()
|
|
31
|
+
assert '| 0 |' in out and '| 1 |' in out
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|