From 007ec1b92a04ae0dba53abd05b7dc2799b44e8c0 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Mon, 23 Jul 2018 09:34:50 -0400 Subject: [PATCH] Test & document a corner case --- README.rst | 3 ++ TODO.md | 2 +- test/test_border_style.py | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 3496304..5132a19 100644 --- a/README.rst +++ b/README.rst @@ -405,6 +405,9 @@ constructor or as attributes on a ``Txtble`` instance:: set to a ``BorderStyle`` instance to set the characters used for drawing the horizontal rule above the data rows. + If ``headers`` is `None` and ``top_border`` is set to a true value (or + inherits a true value from ``border``), the header border will not be drawn. + ``header_fill=None`` When ``headers`` is non-`None` and ``columns`` is `None`, this option determines how rows with more columns than there are headers are handled. diff --git a/TODO.md b/TODO.md index bc5345b..05372db 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,7 @@ - Don't break in the middle of combining character sequences - Don't break on a space or hyphen followed by combining characters - Break on more than just spaces and hyphens? - - cf. the Unicode line breaking algorithm + - cf. the Unicode line breaking algorithm and Unicode TR 29 - cf. `uniseg` package Features to Add diff --git a/test/test_border_style.py b/test/test_border_style.py index 45a8441..2c39e15 100644 --- a/test/test_border_style.py +++ b/test/test_border_style.py @@ -311,3 +311,78 @@ def test_bad_border_style(border_style): match='border_style must be a BorderStyle instance', ): str(tbl) + +def test_border_vs_header_border_style(): + tbl = Txtble(DATA, border=HEAVY_BORDERS, header_border=DOUBLE_BORDERS) + assert text_type(tbl) == ( + u'┏━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓\n' + u'┃January |Garnet |Carnation ┃\n' + u'┃February |Amethyst |Violet ┃\n' + u'┃March |Aquamarine|Jonquil ┃\n' + u'┃April |Diamond |Sweetpea ┃\n' + u'┃May |Emerald |Lily Of The Valley┃\n' + u'┃June |Pearl |Rose ┃\n' + u'┃July |Ruby |Larkspur ┃\n' + u'┃August |Peridot |Gladiolus ┃\n' + u'┃September|Sapphire |Aster ┃\n' + u'┃October |Opal |Calendula ┃\n' + u'┃November |Topaz |Chrysanthemum ┃\n' + u'┃December |Turquoise |Narcissus ┃\n' + u'┗━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━┛' + ) + +def test_top_border_vs_header_border_style(): + tbl = Txtble(DATA, top_border=HEAVY_BORDERS, header_border=DOUBLE_BORDERS) + assert text_type(tbl) == ( + u'┏━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓\n' + u'|January |Garnet |Carnation |\n' + u'|February |Amethyst |Violet |\n' + u'|March |Aquamarine|Jonquil |\n' + u'|April |Diamond |Sweetpea |\n' + u'|May |Emerald |Lily Of The Valley|\n' + u'|June |Pearl |Rose |\n' + u'|July |Ruby |Larkspur |\n' + u'|August |Peridot |Gladiolus |\n' + u'|September|Sapphire |Aster |\n' + u'|October |Opal |Calendula |\n' + u'|November |Topaz |Chrysanthemum |\n' + u'|December |Turquoise |Narcissus |\n' + u'+---------+----------+------------------+' + ) + +def test_no_border_header_border_style(): + tbl = Txtble(DATA, border=False, header_border=DOUBLE_BORDERS) + assert text_type(tbl) == ( + u'═════════╦══════════╦══════════════════\n' + u'January |Garnet |Carnation\n' + u'February |Amethyst |Violet\n' + u'March |Aquamarine|Jonquil\n' + u'April |Diamond |Sweetpea\n' + u'May |Emerald |Lily Of The Valley\n' + u'June |Pearl |Rose\n' + u'July |Ruby |Larkspur\n' + u'August |Peridot |Gladiolus\n' + u'September|Sapphire |Aster\n' + u'October |Opal |Calendula\n' + u'November |Topaz |Chrysanthemum\n' + u'December |Turquoise |Narcissus' + ) + +def test_no_top_border_header_border_style(): + tbl = Txtble(DATA, top_border=False, header_border=DOUBLE_BORDERS) + assert text_type(tbl) == ( + u'╔═════════╦══════════╦══════════════════╗\n' + u'|January |Garnet |Carnation |\n' + u'|February |Amethyst |Violet |\n' + u'|March |Aquamarine|Jonquil |\n' + u'|April |Diamond |Sweetpea |\n' + u'|May |Emerald |Lily Of The Valley|\n' + u'|June |Pearl |Rose |\n' + u'|July |Ruby |Larkspur |\n' + u'|August |Peridot |Gladiolus |\n' + u'|September|Sapphire |Aster |\n' + u'|October |Opal |Calendula |\n' + u'|November |Topaz |Chrysanthemum |\n' + u'|December |Turquoise |Narcissus |\n' + u'+---------+----------+------------------+' + )