flexablelib 2.2.0__tar.gz → 2.2.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.2.0 → flexablelib-2.2.1}/CHANGELOG.md +26 -0
- {flexablelib-2.2.0/flexablelib.egg-info → flexablelib-2.2.1}/PKG-INFO +1 -1
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/merges.py +68 -5
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/table.py +43 -2
- {flexablelib-2.2.0 → flexablelib-2.2.1/flexablelib.egg-info}/PKG-INFO +1 -1
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib.egg-info/SOURCES.txt +1 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/package.json +1 -1
- flexablelib-2.2.1/tests/test_v221_fixes.py +125 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/LICENSE +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/MANIFEST.in +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/README.md +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/__init__.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/_speedups.c +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/_width_tables.h +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/cells.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/colors.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/columns.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/fast.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/options.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/py.typed +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/readers.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/style_compositions.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/table_strings.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/text_width.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/utils.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib/writers.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/pytest.ini +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/setup.cfg +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/setup.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/style_examples.md +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/conftest.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/helpers.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_cells.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_columns.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_excel.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_features.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_issues.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_merges.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_readme_examples.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_style_line_widths.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_styles.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_text_width.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_upstream_issues.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v211_fixes.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v213_features.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v214_features.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v215_features.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v216_features.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v217_features.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v218_features.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v219_coverage.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v219_fixes.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tests/test_v220_exports.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tools/benchmark.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tools/generate_width_tables.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/tools/readme_gallery.py +0 -0
- {flexablelib-2.2.0 → flexablelib-2.2.1}/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.1] - 2026-11-04
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- A merge on the first or last drawn row -- often where ``sort_by`` or
|
|
9
|
+
``row_filter`` puts it -- rewrote the whole border next to it: the top
|
|
10
|
+
border under a ``title`` (with ``show_headers=False``) came out as an inner
|
|
11
|
+
rule (``├───┴───┼───┤``), the bottom border above a ``caption`` lost its
|
|
12
|
+
corners, ``markdown``/``orgtbl`` header separators turned into ``+---+``,
|
|
13
|
+
and ``*_eheader`` header separators kept a junction over the merged span.
|
|
14
|
+
Only the junctions over the merge change now, and each keeps the arms the
|
|
15
|
+
lines around it really have.
|
|
16
|
+
- A merge covering a column in ``hide_columns`` (or a hidden empty column)
|
|
17
|
+
that is left with a single drawn column printed ``.``: the column was sized
|
|
18
|
+
without the merge text. It now shrinks to that column and the column fits
|
|
19
|
+
the text, as the exports already did.
|
|
20
|
+
|
|
21
|
+
### CI
|
|
22
|
+
- Wheels: one path to PyPI. Only the ``vX.Y.Z`` tag push builds and
|
|
23
|
+
publishes; publishing the GitHub release no longer starts a second, duplicate
|
|
24
|
+
build that competed for the macOS runner. Publishing waits for all 28 wheels
|
|
25
|
+
(Linux manylinux + musllinux, Windows, macOS arm64; CPython 3.8-3.14) and
|
|
26
|
+
the sdist, checks the count and that the tag matches ``package.json``, and
|
|
27
|
+
is safe to re-run. One run per ref (``concurrency``).
|
|
28
|
+
- Actions moved off Node 20: ``checkout@v5``, ``setup-python@v6``,
|
|
29
|
+
``upload-artifact@v6``, ``download-artifact@v7``.
|
|
30
|
+
|
|
5
31
|
## [2.2.0] - 2026-11-04
|
|
6
32
|
|
|
7
33
|
### Changed (breaking)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.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
|
|
@@ -509,8 +509,44 @@ def _looks_like_rule(line: str, h_glyph: str = None) -> bool:
|
|
|
509
509
|
)
|
|
510
510
|
|
|
511
511
|
|
|
512
|
+
# Glyphs that carry a vertical arm out of their bottom / top edge.
|
|
513
|
+
_VERTICALS = set('|¦:│┃║┊┋┆┇╎╏')
|
|
514
|
+
_NO_DOWN = set('┴└┘╰╯╨╩╧╙╜╚╝╘╛┸┷┻┖┚┗┛')
|
|
515
|
+
_NO_UP = set('┬┌┐╭╮╥╦╤╓╖╔╗╒╕┰┯┳┎┒┏┓')
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
# Light verticals meeting a heavy dash ('╍', '━'): keep the rule's weight.
|
|
519
|
+
_HEAVY_H = set('╍━┅┉')
|
|
520
|
+
_LIGHT_TO_HEAVY_H = {
|
|
521
|
+
'┼': '┿', '├': '┝', '┤': '┥', '┬': '┯', '┴': '┷',
|
|
522
|
+
'┌': '┍', '┐': '┑', '└': '┕', '┘': '┙',
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def _has_arm(line, x, down):
|
|
527
|
+
"""
|
|
528
|
+
True when the glyph at ``x`` in a neighbouring line reaches this rule.
|
|
529
|
+
|
|
530
|
+
``down`` asks about the line above (does its glyph continue downwards);
|
|
531
|
+
otherwise about the line below. Text, spaces and dashes do not reach it,
|
|
532
|
+
which is what tells a top border under a title, or a bottom border over
|
|
533
|
+
a caption, that it has no arm on that side.
|
|
534
|
+
"""
|
|
535
|
+
if line is None:
|
|
536
|
+
return False
|
|
537
|
+
g = _glyph(_char_at(line, x))
|
|
538
|
+
if not g or g.isspace() or g in _H_CHARS:
|
|
539
|
+
return False
|
|
540
|
+
if g in _VERTICALS or g == '+':
|
|
541
|
+
return True
|
|
542
|
+
if g in _JUNCTIONS:
|
|
543
|
+
return g not in (_NO_DOWN if down else _NO_UP)
|
|
544
|
+
return False
|
|
545
|
+
|
|
546
|
+
|
|
512
547
|
def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=None, missing_north=None,
|
|
513
|
-
no_south=False, no_north=False
|
|
548
|
+
no_south=False, no_north=False, above=False, below=False,
|
|
549
|
+
only=None):
|
|
514
550
|
"""
|
|
515
551
|
Rebuild every junction on a horizontal rule from the arms that remain.
|
|
516
552
|
|
|
@@ -519,6 +555,16 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
|
|
|
519
555
|
|
|
520
556
|
``no_south`` / ``no_north`` force every junction to drop that arm — used for
|
|
521
557
|
the table's outer end/start rules, which never continue past the border.
|
|
558
|
+
|
|
559
|
+
``above`` / ``below``, when not False, are the lines next to this rule (None
|
|
560
|
+
past either end of the table). An arm is then kept only where that line
|
|
561
|
+
really reaches the rule, so a top border under a title, a bottom border
|
|
562
|
+
over a caption, or a header separator under a header drawn without
|
|
563
|
+
column rules keep their own shape. A junction drawn as a plain vertical
|
|
564
|
+
(markdown's ``|---|``) stays as it is unless it becomes a pure dash.
|
|
565
|
+
|
|
566
|
+
``only``, when given, limits the rewrite to those x positions; every other
|
|
567
|
+
junction keeps the style's own glyph (corners such as ``O`` or ``╔``).
|
|
522
568
|
"""
|
|
523
569
|
missing_south = missing_south or set()
|
|
524
570
|
missing_north = missing_north or set()
|
|
@@ -531,6 +577,8 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
|
|
|
531
577
|
for x, v_glyph in _junction_positions(layout, composition):
|
|
532
578
|
if visible_width(rewritten) <= x:
|
|
533
579
|
continue
|
|
580
|
+
if only is not None and x not in only:
|
|
581
|
+
continue
|
|
534
582
|
here = _char_at(rewritten, x)
|
|
535
583
|
# Interior of a multi-column vertical blank: junction was wiped to space.
|
|
536
584
|
if _glyph(here) in ('', ' '):
|
|
@@ -541,10 +589,23 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
|
|
|
541
589
|
east = _is_h(right)
|
|
542
590
|
north = (not no_north) and (x not in missing_north)
|
|
543
591
|
south = (not no_south) and (x not in missing_south)
|
|
592
|
+
if above is not False:
|
|
593
|
+
north = north and _has_arm(above, x, down=True)
|
|
594
|
+
if below is not False:
|
|
595
|
+
south = south and _has_arm(below, x, down=False)
|
|
544
596
|
glyph = _pick_junction(
|
|
545
597
|
v_glyph, h_glyph, north, south, east, west,
|
|
546
598
|
round_corners=round_corners,
|
|
547
599
|
)
|
|
600
|
+
if h_glyph in _HEAVY_H and glyph in _LIGHT_TO_HEAVY_H:
|
|
601
|
+
glyph = _LIGHT_TO_HEAVY_H[glyph]
|
|
602
|
+
if (above is not False and _glyph(here) in _VERTICALS
|
|
603
|
+
and (north or south)):
|
|
604
|
+
glyph = here
|
|
605
|
+
if only is not None and south and not north and _glyph(here) in _NO_UP:
|
|
606
|
+
glyph = here # already has no arm upwards, e.g. a header box top
|
|
607
|
+
if only is not None and north and not south and _glyph(here) in _NO_DOWN:
|
|
608
|
+
glyph = here # already closed below, e.g. ╚═══╩═══╝
|
|
548
609
|
rewritten = _repaint(rewritten, x, x + 1, glyph)
|
|
549
610
|
return rewritten
|
|
550
611
|
|
|
@@ -769,8 +830,10 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
769
830
|
line, layout, composition, line_h,
|
|
770
831
|
missing_south=missing_south_by_line.get(line_index),
|
|
771
832
|
missing_north=missing_north_by_line.get(line_index),
|
|
772
|
-
|
|
773
|
-
|
|
833
|
+
above=lines[line_index - 1] if line_index > 0 else None,
|
|
834
|
+
below=lines[line_index + 1] if line_index + 1 < len(lines) else None,
|
|
835
|
+
only=(missing_south_by_line.get(line_index, set())
|
|
836
|
+
| missing_north_by_line.get(line_index, set())),
|
|
774
837
|
)
|
|
775
838
|
|
|
776
839
|
# --- Pass 4: synthetic caps for column-only styles ----------------------
|
|
@@ -798,8 +861,8 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
798
861
|
line, layout, composition, line_h,
|
|
799
862
|
missing_south=plan['s'] or None,
|
|
800
863
|
missing_north=plan['n'] or None,
|
|
801
|
-
|
|
802
|
-
|
|
864
|
+
above=lines[existing - 1] if existing > 0 else None,
|
|
865
|
+
below=lines[existing + 1] if existing + 1 < len(lines) else None,
|
|
803
866
|
)
|
|
804
867
|
continue
|
|
805
868
|
|
|
@@ -3617,7 +3617,7 @@ class Table(object):
|
|
|
3617
3617
|
)
|
|
3618
3618
|
self.__get_column_widths(semi=False)
|
|
3619
3619
|
# Raise floors from column_min_width and re-assert max budgets.
|
|
3620
|
-
self.__clamp_column_widths()
|
|
3620
|
+
self.__clamp_column_widths(merge_floors=True)
|
|
3621
3621
|
table_width = self.__get_string_table_width()
|
|
3622
3622
|
# Grow first when asked, then shrink if still over budget.
|
|
3623
3623
|
if self.__expand_to_window:
|
|
@@ -4164,13 +4164,51 @@ class Table(object):
|
|
|
4164
4164
|
return None
|
|
4165
4165
|
return int(bounds)
|
|
4166
4166
|
|
|
4167
|
-
def
|
|
4167
|
+
def __collapsed_merge_floors(self):
|
|
4168
|
+
"""
|
|
4169
|
+
Width each drawn column needs for merges left with only that column.
|
|
4170
|
+
|
|
4171
|
+
A merge across several columns, with all but one of them in
|
|
4172
|
+
``hide_columns`` (or hidden as empty), shrinks to the column still
|
|
4173
|
+
drawn -- the same thing the exports do. Its text then has that one
|
|
4174
|
+
column to itself, so the column has to fit it, as it would an
|
|
4175
|
+
ordinary cell; sized by its own content alone it printed ``.``.
|
|
4176
|
+
Merges still spanning two or more drawn columns are untouched: a merge
|
|
4177
|
+
never widens the table.
|
|
4178
|
+
"""
|
|
4179
|
+
if not self.__merged_regions:
|
|
4180
|
+
return {}
|
|
4181
|
+
offset = 1 if self.__show_index else 0
|
|
4182
|
+
hidden = set(self.__effective_hidden_columns(self.__show_index))
|
|
4183
|
+
if not hidden:
|
|
4184
|
+
return {}
|
|
4185
|
+
floors = {}
|
|
4186
|
+
for region in self.__merged_regions:
|
|
4187
|
+
if region.value is None:
|
|
4188
|
+
continue
|
|
4189
|
+
columns = range(region.first_column + offset,
|
|
4190
|
+
region.last_column + offset + 1)
|
|
4191
|
+
drawn = [c for c in columns if c not in hidden]
|
|
4192
|
+
if len(drawn) != 1 or len(drawn) == len(columns):
|
|
4193
|
+
continue
|
|
4194
|
+
needed = max(
|
|
4195
|
+
visible_width(strip_ansi(part))
|
|
4196
|
+
for part in str(region.value).split('\n')
|
|
4197
|
+
)
|
|
4198
|
+
floors[drawn[0]] = max(floors.get(drawn[0], 0), needed)
|
|
4199
|
+
return floors
|
|
4200
|
+
|
|
4201
|
+
def __clamp_column_widths(self, merge_floors=False):
|
|
4168
4202
|
"""
|
|
4169
4203
|
Enforce column_min_width / column_max_width on the measured widths.
|
|
4170
4204
|
|
|
4171
4205
|
Only the width numbers are changed here. Content that still exceeds a
|
|
4172
4206
|
max is reduced by :meth:`__enforce_column_max_widths`, which walks the
|
|
4173
4207
|
same wrap/trim path as a terminal fit.
|
|
4208
|
+
|
|
4209
|
+
``merge_floors`` also widens a column holding a merge that hiding left
|
|
4210
|
+
with that one column (:meth:`__collapsed_merge_floors`). Only the
|
|
4211
|
+
first clamp does it, so a terminal fit can still narrow it afterwards.
|
|
4174
4212
|
"""
|
|
4175
4213
|
if self.__show_index:
|
|
4176
4214
|
headers = list(self.__headers_with_i)
|
|
@@ -4184,6 +4222,7 @@ class Table(object):
|
|
|
4184
4222
|
if not widths:
|
|
4185
4223
|
return
|
|
4186
4224
|
|
|
4225
|
+
collapsed = self.__collapsed_merge_floors() if merge_floors else {}
|
|
4187
4226
|
for column_i, header in enumerate(headers):
|
|
4188
4227
|
# Index column (position 0 with show_index) is not user-facing.
|
|
4189
4228
|
user_i = None if (self.__show_index and column_i == 0) else (
|
|
@@ -4203,6 +4242,8 @@ class Table(object):
|
|
|
4203
4242
|
# clamping the number anyway drew a frame narrower than the text.
|
|
4204
4243
|
content = widths[column_i]
|
|
4205
4244
|
width = content
|
|
4245
|
+
if merge_floors and column_i in collapsed:
|
|
4246
|
+
width = max(width, collapsed[column_i])
|
|
4206
4247
|
if lo is not None:
|
|
4207
4248
|
width = max(width, int(lo))
|
|
4208
4249
|
if hi is not None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.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
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""2.2.1 regressions: merges on the first/last drawn row, and merges that
|
|
2
|
+
hiding leaves with a single column."""
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from flexablelib import Table
|
|
8
|
+
from flexablelib.style_compositions import __style_compositions as catalogue
|
|
9
|
+
from flexablelib.text_width import visible_width
|
|
10
|
+
|
|
11
|
+
ROWS = [['a', 3, 'x'], ['b', 1, 'y'], ['c', 2, 'z'], ['d', 4, 'w']]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def make(rows=ROWS, **options):
|
|
15
|
+
table = Table(rows=[list(r) for r in rows], headers=['N', 'V', 'T'])
|
|
16
|
+
table.use_colors = False
|
|
17
|
+
for key, value in options.items():
|
|
18
|
+
setattr(table, key, value)
|
|
19
|
+
return table
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# -- merge on the first visible row (after row_filter / sort_by) ------------
|
|
23
|
+
|
|
24
|
+
ORDERINGS = [
|
|
25
|
+
('sort_by', lambda t: setattr(t, 'sort_by', 'V')),
|
|
26
|
+
('sort_reverse', lambda t: (setattr(t, 'sort_by', 'V'),
|
|
27
|
+
setattr(t, 'sort_reverse', True))),
|
|
28
|
+
('row_filter', lambda t: setattr(t, 'row_filter', lambda r: r[0] != 'a')),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.mark.parametrize('name,order', ORDERINGS)
|
|
33
|
+
def test_top_border_under_title_survives_first_row_merge(name, order):
|
|
34
|
+
table = make(style_name='rounded', show_headers=False, title='T')
|
|
35
|
+
table.merge_cells(0, 0, last_column=1, value='M')
|
|
36
|
+
order(table)
|
|
37
|
+
lines = table.compose().split('\n')
|
|
38
|
+
assert lines[1] == '╭───────┬───╮', lines
|
|
39
|
+
assert lines[-1].startswith('╰')
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.parametrize('name,order', ORDERINGS)
|
|
43
|
+
def test_bottom_border_over_caption_survives_last_row_merge(name, order):
|
|
44
|
+
table = make(style_name='modern', caption='cap')
|
|
45
|
+
order(table)
|
|
46
|
+
last = 3 if name != 'row_filter' else 2
|
|
47
|
+
table.merge_cells(last, 0, last_column=1, value='M')
|
|
48
|
+
lines = table.compose().split('\n')
|
|
49
|
+
assert lines[-2] == '└───────┴───┘', lines
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_eheader_separator_drops_junction_over_first_row_merge():
|
|
53
|
+
table = make(sort_by='V') # default grid_eheader
|
|
54
|
+
table.merge_cells(0, 0, last_column=1, value='M')
|
|
55
|
+
lines = table.compose().split('\n')
|
|
56
|
+
assert lines[2] == '+=======+===+'
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_markdown_header_separator_kept_over_first_row_merge():
|
|
60
|
+
table = make(style_name='markdown', row_filter=lambda r: r[0] != 'a')
|
|
61
|
+
table.merge_cells(0, 0, last_column=1, value='M')
|
|
62
|
+
assert table.compose().split('\n')[1] == '|---|---|---|'
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.mark.parametrize('style', catalogue._fields)
|
|
66
|
+
@pytest.mark.parametrize('options', [
|
|
67
|
+
{'show_headers': False, 'title': 'Title'},
|
|
68
|
+
{'caption': 'caption'},
|
|
69
|
+
{'sort_by': 'V', 'title': 'Title', 'caption': 'caption'},
|
|
70
|
+
])
|
|
71
|
+
def test_outer_borders_unchanged_by_edge_merges(style, options):
|
|
72
|
+
"""A merge on the first or last drawn row never rewrites the frame."""
|
|
73
|
+
def frame(lines):
|
|
74
|
+
head = 1 if options.get('title') else 0
|
|
75
|
+
tail = 1 if options.get('caption') else 0
|
|
76
|
+
return lines[head:len(lines) - tail]
|
|
77
|
+
|
|
78
|
+
plain = frame(make(style_name=style, **options).compose().split('\n'))
|
|
79
|
+
for first in (0, 3):
|
|
80
|
+
table = make(style_name=style, **options)
|
|
81
|
+
table.merge_cells(first, 0, last_column=1, value='M')
|
|
82
|
+
lines = frame(table.compose().split('\n'))
|
|
83
|
+
assert len({visible_width(line) for line in lines}) == 1, lines
|
|
84
|
+
# The top and bottom lines keep their outer corners.
|
|
85
|
+
for got, want in ((lines[0], plain[0]), (lines[-1], plain[-1])):
|
|
86
|
+
if re.search(r'\w', want):
|
|
87
|
+
continue # frameless style: this is a row, not a border
|
|
88
|
+
assert (got[:1], got[-1:]) == (want[:1], want[-1:]), (
|
|
89
|
+
style, options, first, '\n'.join(lines))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# -- merge covering a hidden column ----------------------------------------
|
|
93
|
+
|
|
94
|
+
@pytest.mark.parametrize('hidden', [['T'], ['V'], [2]])
|
|
95
|
+
def test_merge_over_hidden_column_shows_its_text(hidden):
|
|
96
|
+
table = make(hide_columns=hidden)
|
|
97
|
+
table.merge_cells(0, 1, last_column=2, value='Merged')
|
|
98
|
+
out = table.compose()
|
|
99
|
+
assert 'Merged' in out
|
|
100
|
+
assert '| . |' not in out
|
|
101
|
+
assert len({visible_width(line) for line in out.split('\n')}) == 1
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_merge_over_hidden_column_matches_export():
|
|
105
|
+
table = make(hide_columns=['T'], style_name='ascii')
|
|
106
|
+
table.merge_cells(0, 1, last_column=2, value='Merged')
|
|
107
|
+
(region,) = table._export_view().merges
|
|
108
|
+
assert (region.first_column, region.last_column) == (1, 1)
|
|
109
|
+
row = table.compose().split('\n')[3]
|
|
110
|
+
assert re.fullmatch(r'\| a \| +Merged +\|', row), row
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_merge_over_hidden_column_with_index_and_rows():
|
|
114
|
+
table = make(hide_columns=['V'], show_index=True, style_name='rounded')
|
|
115
|
+
table.merge_cells(1, 1, last_row=2, last_column=2, value='Total')
|
|
116
|
+
out = table.compose()
|
|
117
|
+
assert 'Total' in out
|
|
118
|
+
assert len({visible_width(line) for line in out.split('\n')}) == 1
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_merge_still_spanning_two_columns_does_not_widen():
|
|
122
|
+
table = make(hide_columns=['N'])
|
|
123
|
+
table.merge_cells(0, 0, last_column=2, value='Much longer text')
|
|
124
|
+
widths = {visible_width(line) for line in table.compose().split('\n')}
|
|
125
|
+
assert widths == {9}
|
|
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
|