def test_normal_set_style(self): writer = table_writer_class() writer.table_name = "set style method" writer.headers = ["normal", "style by idx", "style by header"] writer.value_matrix = [[11, 11, 11], [123456, 123456, 123456]] writer.set_style(1, Style(font_weight="bold", thousand_separator=",")) writer.set_style( "style by header", Style(align="center", font_weight="bold", thousand_separator=" ")) expected = dedent("""\ # set style method |normal|style by idx|style by header| |-----:|-----------:|:-------------:| | 11| **11**| **11** | |123456| **123,456**| **123 456** | """) output = writer.dumps() print_test_result(expected=expected, actual=output) assert regexp_ansi_escape.search(output) assert regexp_ansi_escape.sub("", output) == expected writer.table_name = "change style" writer.set_style(1, Style(align="right", font_style="italic")) writer.set_style("style by header", Style()) expected = dedent("""\ # change style |normal|style by idx|style by header| |-----:|-----------:|--------------:| | 11| _11_| 11| |123456| _123456_| 123456| """) output = writer.dumps() print_test_result(expected=expected, actual=output) assert regexp_ansi_escape.sub("", output) == expected
def test_normal_style_thousand_separator(self, capsys): writer = table_writer_class() writer.from_tabledata( TableData( "", [ "none_format", "thousand_separator_i", "thousand_separator_f", "f", "wo_f" ], [ [1000, 1234567, 1234567.8, 1234.5678, 1234567.8], [1000, 1234567, 1234567.8, 1234.5678, 1234567.8], ], )) writer.column_styles = [ Style(thousand_separator=ThousandSeparator.NONE), Style(thousand_separator=ThousandSeparator.COMMA), Style(thousand_separator=ThousandSeparator.UNDERSCORE), Style(thousand_separator=ThousandSeparator.SPACE), ] out = writer.dumps() expected = dedent("""\ |none_format|thousand_separator_i|thousand_separator_f| f | wo_f | |----------:|-------------------:|-------------------:|------:|--------:| | 1000| 1,234,567| 1_234_567.8|1 234.6|1234567.8| | 1000| 1,234,567| 1_234_567.8|1 234.6|1234567.8| """) print_test_result(expected=expected, actual=out) assert out == expected
def test_normal(self, tmpdir): test_filepath = str(tmpdir.join("test.sqlite")) writer = table_writer_class() writer.headers = ["a", "b"] writer.value_matrix = [["foo", "bar"]] writer.column_styles = [ Style(color="red"), Style(bg_color="white"), ] writer.dump(test_filepath) expected = dedent( """\ | a | b | |---|---| |foo|bar| """ ) with open(test_filepath) as f: output = f.read() print_test_result(expected=expected, actual=output) assert output == expected
def print(self): writer = MarkdownTableWriter() writer.headers = self._make_headers() writer.value_matrix = self._make_value_matrix() writer.styles = [Style(align="left")] + [Style(align="center") for _ in range(len(writer.headers) - 1)] writer.write_table() print("\n" + self._make_versions_text())
def gen_group(group, parameters, output): parameter_fields = ["name", "description", "default"] display_name = group.get("displayName", group.get("name")) output.write(f'## <a name="{group.get("name")}"></a> {display_name} \n') if "description" in group: output.write(f'{group.get("description")}\n') output.write('\n\n') paramTable = MarkdownTableWriter() # paramTable.table_name = group["displayName"] paramTable.styles = [ Style(align="left", font_weight="bold"), Style(align="left"), Style(align="left"), ] paramTable.headers = [field.capitalize() for field in parameter_fields] paramTable.margin = 1 paramTable.value_matrix = [ list([parameter.get(field) for field in parameter_fields]) for parameter in parameters if parameter.get("group", "") == group.get("name") ] paramTable.stream = output paramTable.write_table() return 0
class Test_Style_repr: @pytest.mark.parametrize( ["value", "expected"], [ [ Style( align="left", padding=1, vertical_align="bottom", color="red", bg_color="#2f2f2f", decoration_line="line-through", font_size="tiny", font_style="italic", font_weight="bold", thousand_separator=",", ), "(align=left, padding=1, valign=bottom, " "color=Color(code=#cd3131, rgb=(205, 49, 49), name=RED), " "bg_color=Color(code=#2f2f2f, rgb=(47, 47, 47)), " "decoration_line=line_through, " "font_size=tiny, font_style=italic, font_weight=bold, " "thousand_separator=comma)", ], [ Style(), "(align=auto, valign=baseline, font_style=normal, font_weight=normal)" ], ], ) def test_normal(self, value, expected): out = str(value) print_test_result(expected=expected, actual=out) assert out == expected
def test_normal_style_list(self, capsys): from pytablewriter.style import Style, FontSize writer = table_writer_class() writer.table_name = "style test: font size will not be affected" writer.header_list = [ "none", "empty_style", "tiny", "small", "medium", "large" ] writer.value_matrix = [[111, 111, 111, 111, 111, 111], [1234, 1234, 1234, 1234, 1234, 1234]] writer.style_list = [ None, Style(), Style(font_size=FontSize.TINY), Style(font_size=FontSize.SMALL), Style(font_size=FontSize.MEDIUM), Style(font_size=FontSize.LARGE), ] writer.write_table() expected = dedent("""\ # style test: font size will not be affected |none|empty_style|tiny|small|medium|large| |---:|----------:|---:|----:|-----:|----:| | 111| 111| 111| 111| 111| 111| |1234| 1234|1234| 1234| 1234| 1234| """) out, err = capsys.readouterr() print_test_result(expected=expected, actual=out, error=err) assert out == expected
def test_normal_flavor_kramdown(self): writer = table_writer_class( table_name="kramdown/Jeklly", enable_ansi_escape=False, column_styles=[ None, Style(decoration_line="strike"), Style(decoration_line="line-through"), ], headers=["w/o style", "w/ strike", "w/ line through"], value_matrix=[["no", "strike", "line-through"]], flavor="kramdown", ) expected = dedent("""\ # kramdown/Jeklly |w/o style|w/ strike|w/ line through| |---------|---------|---------------| |no |strike |line-through | """) output = writer.dumps() print_test_result(expected=expected, actual=output) assert output == expected assert output != writer.dumps(flavor="gfm")
def test_normal_style_font_weight(self): writer = table_writer_class() writer.table_name = "style test: bold" writer.headers = ["normal", "bold"] writer.value_matrix = [ [11, 11], [123456, 123456], ] writer.column_styles = [ Style(font_weight="normal"), Style(font_weight="bold") ] expected = dedent("""\ # style test: bold |normal| bold | |-----:|---------:| | 11| **11**| |123456|**123456**| """) out = writer.dumps() print_test_result(expected=expected, actual=out) assert regexp_ansi_escape.search(out) assert strip_ansi_escape(out) == expected
def test_normal_colorize_terminal(self): column_styles = [ Style(color="red"), Style(bg_color="white"), ] writer = table_writer_class() writer.column_styles = column_styles writer.headers = ["fg color", "bg color"] writer.value_matrix = [["hoge", "foo"]] writer.colorize_terminal = True out = writer.dumps() assert regexp_ansi_escape.search(out) assert (table_writer_class( headers=["fg color", "bg color"], value_matrix=[["hoge", "foo"]], column_styles=column_styles, colorize_terminal=True, ).dumps() == out) writer.colorize_terminal = False out = writer.dumps() assert regexp_ansi_escape.search(out) is None assert (table_writer_class( headers=["fg color", "bg color"], value_matrix=[["hoge", "foo"]], column_styles=column_styles, colorize_terminal=False, ).dumps() == out)
def test_normal_style_list(self, capsys): from pytablewriter.style import Style, FontSize writer = table_writer_class() writer.table_name = "style test: font size" writer.header_list = ["none", "empty_style", "tiny", "small", "medium", "large"] writer.value_matrix = [[111, 111, 111, 111, 111, 111], [1234, 1234, 1234, 1234, 1234, 1234]] writer.style_list = [ None, Style(), Style(font_size=FontSize.TINY), Style(font_size=FontSize.SMALL), Style(font_size=FontSize.MEDIUM), Style(font_size=FontSize.LARGE), ] writer.write_table() expected = r"""\begin{equation} style test: font size = \left( \begin{array}{rrrrrr} 111 & 111 & \tiny 111 & \small 111 & \normalsize 111 & \large 111 \\ 1234 & 1234 & \tiny 1234 & \small 1234 & \normalsize 1234 & \large 1234 \\ \end{array} \right) \end{equation} """ out, err = capsys.readouterr() print_test_result(expected=expected, actual=out, error=err) assert out == expected
def test_normal_style_font_size(self): writer = table_writer_class() writer.table_name = "style test: font size will not be affected" writer.headers = [ "none", "empty_style", "tiny", "small", "medium", "large" ] writer.value_matrix = [[111, 111, 111, 111, 111, 111], [1234, 1234, 1234, 1234, 1234, 1234]] writer.styles = [ None, Style(), Style(font_size=FontSize.TINY), Style(font_size=FontSize.SMALL), Style(font_size=FontSize.MEDIUM), Style(font_size=FontSize.LARGE), ] expected = dedent("""\ # style test: font size will not be affected |none|empty_style|tiny|small|medium|large| |---:|----------:|---:|----:|-----:|----:| | 111| 111| 111| 111| 111| 111| |1234| 1234|1234| 1234| 1234| 1234| """) out = writer.dumps() print_test_result(expected=expected, actual=out) assert out == expected
def print_starred_info(starred_info_set, repo_depth_map, verbosity): records = [] for info in sorted(starred_info_set): record = [ info.pypi_pkg_name, info.github_repo_id, _star_status_map[info.star_status], info.is_owned if info.star_status in [StarStatus.STARRED, StarStatus.NOT_STARRED] else _NA, repo_depth_map[info.pypi_pkg_name.lower()], info.url, ] records.append(record) writer = MarkdownTableWriter() writer.headers = ["Package", "Repository", "Starred", "Owner"] if verbosity is not None: if verbosity >= 1: writer.headers += ["Depth"] if verbosity >= 2: writer.headers += ["URL"] writer.value_matrix = sorted(records, key=itemgetter(4, 0)) # sorted by depth writer.margin = 1 writer.register_trans_func(bool_to_checkmark) writer.set_style("Starred", Style(align="center")) writer.set_style("Owner", Style(align="center")) pager(writer.dumps())
def _pytablewriter(headers, data, format: str): from pytablewriter import ( HtmlTableWriter, NumpyTableWriter, PandasDataFrameWriter, RstSimpleTableWriter, String, TsvTableWriter, ) from pytablewriter.style import Align, Style, ThousandSeparator format_writers = { "html": HtmlTableWriter, "numpy": NumpyTableWriter, "pandas": PandasDataFrameWriter, "rst": RstSimpleTableWriter, "tsv": TsvTableWriter, } writer = format_writers[format]() if format != "html": writer.margin = 1 if isinstance(data, dict): writer.value_matrix = [data] else: # isinstance(data, list): writer.value_matrix = data writer.headers = headers # Custom alignment and format if headers[0] in ["last_day", "last_month", "last_week"]: # Special case for 'recent' writer.column_styles = len(headers) * [Style(thousand_separator=",")] else: column_styles = [] type_hints = [] for header in headers: align = Align.AUTO thousand_separator = ThousandSeparator.NONE type_hint = None if header == "percent": align = Align.RIGHT elif header == "downloads" and (format not in ["numpy", "pandas"]): thousand_separator = "," elif header == "category": type_hint = String style = Style(align=align, thousand_separator=thousand_separator) column_styles.append(style) type_hints.append(type_hint) writer.column_styles = column_styles writer.type_hints = type_hints if format == "numpy": return writer.tabledata.as_dataframe().values elif format == "pandas": return writer.tabledata.as_dataframe() return writer.dumps()
def _tabulate(data, format="markdown"): """Return data in specified format""" format_writers = { "html": HtmlTableWriter, "markdown": MarkdownTableWriter, "numpy": NumpyTableWriter, "pandas": PandasDataFrameWriter, "rst": RstSimpleTableWriter, "tsv": TsvTableWriter, } writer = format_writers[format]() if format != "html": writer.margin = 1 if isinstance(data, dict): headers = list(data.keys()) writer.value_matrix = [data] else: # isinstance(data, list): headers = sorted(set().union(*(d.keys() for d in data))) writer.value_matrix = data # Move downloads last headers.append("downloads") headers.remove("downloads") writer.headers = headers # Custom alignment and format if headers[0] in ["last_day", "last_month", "last_week"]: # Special case for 'recent' writer.column_styles = len(headers) * [Style(thousand_separator=",")] else: column_styles = [] type_hints = [] for header in headers: align = Align.AUTO thousand_separator = ThousandSeparator.NONE type_hint = None if header == "percent": align = Align.RIGHT elif header == "downloads" and (format not in ["numpy", "pandas"]): thousand_separator = "," elif header == "category": type_hint = String style = Style(align=align, thousand_separator=thousand_separator) column_styles.append(style) type_hints.append(type_hint) writer.column_styles = column_styles writer.type_hints = type_hints if format == "numpy": return writer.tabledata.as_dataframe().values elif format == "pandas": return writer.tabledata.as_dataframe() return writer.dumps()
def generate_markdown_table(input_params_yaml, output_markdown_file_path): try: with open(input_params_yaml, "r") as input: yamlData = yaml.safe_load(input) groups = yamlData["groups"] parameters = yamlData["parameters"] groupTable = MarkdownTableWriter() groupTable.table_name = "Groups" groupTable.styles = [ Style(align="left"), Style(align="left"), ] groupTable.headers = [ "Group", "Description" ] #"[field.capitalize() for field in group_fields] groupTable.margin = 1 groupTable.value_matrix = [ # list([group.get(field) for field in group_fields]) gen_group_header(group) for group in groups ] emptyGroup = { 'name': '', 'displayName': 'Ungrouped Parameters', 'description': 'All parameters that are not assigned to a specific group.' } if output_markdown_file_path: try: with open(output_markdown_file_path, "w") as output: groupTable.stream = output groupTable.write_table() for group in groups: gen_group(group, parameters, output) gen_group(emptyGroup, parameters, output) except Exception as e: logging.error( f"Failed to output Markdown to {output_markdown_file_path}", e, ) return 1 else: logging.error(f"Required markdown output") return 0 except Exception as e: logging.error(f"Failed to generate Markdown from {input_params_yaml}", e) return 1
def test_normal_style_list(self, capsys): from pytablewriter.style import Style, FontSize writer = table_writer_class() writer.table_name = "style test: font size" writer.header_list = ["none", "empty_style", "tiny", "small", "medium", "large"] writer.value_matrix = [[111, 111, 111, 111, 111, 111], [1234, 1234, 1234, 1234, 1234, 1234]] writer.style_list = [ None, Style(), Style(font_size=FontSize.TINY), Style(font_size=FontSize.SMALL), Style(font_size=FontSize.MEDIUM), Style(font_size=FontSize.LARGE), ] writer.write_table() expected = dedent( """\ <table id="styletestfontsize"> <caption>style test: font size</caption> <thead> <tr> <th>none</th> <th>empty_style</th> <th>tiny</th> <th>small</th> <th>medium</th> <th>large</th> </tr> </thead> <tbody> <tr> <td align="right">111</td> <td align="right">111</td> <td align="right" style="font-size:x-small">111</td> <td align="right" style="font-size:small">111</td> <td align="right" style="font-size:medium">111</td> <td align="right" style="font-size:large">111</td> </tr> <tr> <td align="right">1234</td> <td align="right">1234</td> <td align="right" style="font-size:x-small">1234</td> <td align="right" style="font-size:small">1234</td> <td align="right" style="font-size:medium">1234</td> <td align="right" style="font-size:large">1234</td> </tr> </tbody> </table> """ ) out, err = capsys.readouterr() print_test_result(expected=expected, actual=out, error=err) assert out == expected
def style_filter(cell: Cell, **kwargs) -> Optional[Style]: if isinstance(cell.value, int): return Style(align="left") if cell.value == "c": return Style(align="center") if cell.value == "r": return Style(align="right") return None
def test_normal_style_align(self): writer = table_writer_class() writer.from_tabledata( TableData( table_name="auto align", header_list=[ "left", "right", "center", "auto", "auto", "None" ], row_list=[ [0, "r", "center align", 0, "a", "n"], [11, "right align", "bb", 11, "auto", "none (auto)"], ], )) expected = dedent("""\ # auto align |left| right | center |auto|auto| None | |---:|-----------|------------|---:|----|-----------| | 0|r |center align| 0|a |n | | 11|right align|bb | 11|auto|none (auto)| """) out = writer.dumps() print_test_result(expected=expected, actual=out) assert out == expected writer.table_name = "specify alignment for each column manually" writer.style_list = [ Style(align=Align.LEFT), Style(align=Align.RIGHT), Style(align=Align.CENTER), Style(align=Align.AUTO), Style(align=Align.AUTO), None, ] expected = dedent("""\ # specify alignment for each column manually |left| right | center |auto|auto| None | |----|----------:|:----------:|---:|----|-----------| |0 | r|center align| 0|a |n | |11 |right align| bb | 11|auto|none (auto)| """) out = writer.dumps() print_test_result(expected=expected, actual=out) assert out == expected # test for backward compatibility writer.style_list = None writer.align_list = [ Align.LEFT, Align.RIGHT, Align.CENTER, Align.AUTO, Align.AUTO, None ] out = writer.dumps() print_test_result(expected=expected, actual=out) assert out == expected
def _tabulate(data, format="markdown"): """Return data in specified format""" format_writers = { "markdown": MarkdownTableWriter, "rst": RstSimpleTableWriter, "html": HtmlTableWriter, } writer = format_writers[format]() if format != "html": writer.margin = 1 if isinstance(data, dict): header_list = list(data.keys()) writer.value_matrix = [data] else: # isinstance(data, list): header_list = sorted(set().union(*(d.keys() for d in data))) writer.value_matrix = data # Move downloads last header_list.append("downloads") header_list.remove("downloads") writer.header_list = header_list # Custom alignment and format if header_list[0] in ["last_day", "last_month", "last_week"]: # Special case for 'recent' writer.style_list = len(header_list) * [Style(thousand_separator=",")] else: style_list = [] type_hints = [] for item in header_list: align = None thousand_separator = None type_hint = None if item == "percent": align = Align.RIGHT elif item == "downloads": thousand_separator = "," elif item == "category": type_hint = String style = Style(align=align, thousand_separator=thousand_separator) style_list.append(style) type_hints.append(type_hint) writer.style_list = style_list writer.type_hints = type_hints return writer.dumps()
def test_normal_style_thousand_separator(self, capsys): writer = table_writer_class() writer.from_tabledata( TableData( table_name="", header_list=[ "none_format", "thousand_separator_i", "thousand_separator_f", "f", "wo_f", ], row_list=[ [1000, 1234567, 1234567.8, 1234.5678, 1234567.8], [1000, 1234567, 1234567.8, 1234.5678, 1234567.8], ], )) writer.style_list = [ Style(thousand_separator=ThousandSeparator.NONE), Style(thousand_separator=ThousandSeparator.COMMA), Style(thousand_separator=ThousandSeparator.COMMA), Style(thousand_separator=ThousandSeparator.SPACE), ] out = writer.dumps() expected = dedent("""\ |none_format|thousand_separator_i|thousand_separator_f| f | wo_f | |----------:|-------------------:|-------------------:|------:|--------:| | 1000| 1,234,567| 1,234,567.8|1 234.6|1234567.8| | 1000| 1,234,567| 1,234,567.8|1 234.6|1234567.8| """) print_test_result(expected=expected, actual=out) assert out == expected writer.style_list = None writer.format_list = [ ptw.Format.NONE, ptw.Format.THOUSAND_SEPARATOR, ptw.Format.THOUSAND_SEPARATOR, ptw.Format.THOUSAND_SEPARATOR, ] out = writer.dumps() expected = dedent("""\ |none_format|thousand_separator_i|thousand_separator_f| f | wo_f | |----------:|-------------------:|-------------------:|------:|--------:| | 1000| 1,234,567| 1,234,567.8|1,234.6|1234567.8| | 1000| 1,234,567| 1,234,567.8|1,234.6|1234567.8| """) print_test_result(expected=expected, actual=out) assert out == expected
def generate_md_table(data, headers): writer = MarkdownTableWriter() writer.headers = headers writer.column_styles = [Style(align="center", font_weight="bold") ] * len(headers) writer.value_matrix = data return writer.dumps()
def debug(self): parallel_matches = self._parallelize() writer = MarkdownTableWriter() writer.table_name = "debug" writer.headers = ["Src slice", "Index src", "Text src", "", "Text tgt", "Index tgt", "Tgt slice"] writer.column_styles = [Style(align='center')]*7 rows = [] for source_sequence, target_sequence in parallel_matches: source_sequence.context = self._source.context target_sequence.context = self._target.context col1 = source_sequence.slice_representation() col2 = "\n".join([str(i) for i in source_sequence.iter_index()]) col3 = "\n".join([s.context.get_sequence_text(s) for s in source_sequence]) col4 = '--->' col5 = "\n".join([s.context.get_sequence_text(s) for s in target_sequence]) col6 = "\n".join([str(i) for i in target_sequence.iter_index()]) col7 = target_sequence.slice_representation() for a, b, c, d, e, f, g in zip_longest( [col1], col2.split('\n'), col3.split('\n'), [col4], col5.split('\n'), col6.split('\n'), [col7]): rows.append([ a, b, c, d, e, f, g ]) rows.append([""]*7) rows.pop() writer.value_matrix = rows writer.write_table()
def create_writer(cls, table_name, headers, values): writer = RstSimpleTableWriter() writer.table_name = table_name writer.headers = headers writer.value_matrix = values writer.margin = 1 [writer.set_style(header, Style(align="center")) for header in headers] return writer
def args_to_md(model,args_dict): writer = MarkdownTableWriter() writer.table_name = model writer.headers=list(args_dict.keys()) # print('headers: ',writer.headers) writer.value_matrix=[list(args_dict.values())] # print('value_matrix: ',writer.value_matrix) writer.column_styles = [Style(align="center") for _ in range(len(writer.headers))] print(writer.write_table())
def test_normal(self, value, expected): style = Style(**value) print("expected: {}\nactual: {}".format(expected, style), file=sys.stderr) assert style.align is expected.get("align") assert style.font_size is expected.get("font_size") assert style.font_weight is expected.get("font_weight") assert style.thousand_separator is expected.get("thousand_separator")
def test_normal_valign(self, capsys): writer = table_writer_class( table_name="vertical-align", headers=[ "", "top", "middle", "bottom", "top-right", "middle-right", "bottom-right", ], value_matrix=[ ["te\nst", "x", "x", "x", "x", "x", "x"], ], column_styles=[ Style(vertical_align="baseline"), Style(vertical_align="top"), Style(vertical_align="middle"), Style(vertical_align="bottom"), Style(align="right", vertical_align="top"), Style(align="right", vertical_align="middle"), Style(align="right", vertical_align="bottom"), ], ) writer.write_table() expected = """\ <table id="verticalalign"> <caption>vertical-align</caption> <thead> <tr> <th></th> <th>top</th> <th>middle</th> <th>bottom</th> <th>top-right</th> <th>middle-right</th> <th>bottom-right</th> </tr> </thead> <tbody> <tr> <td align="left">te<br>st</td> <td align="left" valign="top">x</td> <td align="left" valign="middle">x</td> <td align="left" valign="bottom">x</td> <td align="right" valign="top">x</td> <td align="right" valign="middle">x</td> <td align="right" valign="bottom">x</td> </tr> </tbody> </table> """ out, err = capsys.readouterr() print_test_result(expected=expected, actual=out, error=err) assert out == expected
class Test_Style_repr(object): @pytest.mark.parametrize( ["value", "expected"], [ [ Style( align="left", font_size="tiny", font_style="italic", font_weight="bold", thousand_separator=",", ), "(align=left, font_size=tiny, font_style=italic, font_weight=bold, thousand_separator=comma)", ], [Style(), "(align=auto, font_style=normal, font_weight=normal)"], ], ) def test_normal(self, value, expected): assert str(value) == expected
def test_normal_flavor(self): writer = table_writer_class() writer.table_name = "decoration line" writer.column_styles = [ Style(decoration_line="underline"), Style(decoration_line="strike"), Style(decoration_line="line-through"), ] writer.headers = ["w/o style", "w/ strike", "w/ line through"] writer.value_matrix = [["u", "s", "lt"]] expected = """\ .decoration-line thead th:nth-child(1) { text-align: left; text-decoration-line: underline; } .decoration-line thead th:nth-child(2) { text-align: left; text-decoration-line: line-through; } .decoration-line thead th:nth-child(3) { text-align: left; text-decoration-line: line-through; } .decoration-line tbody tr:nth-child(1) td:nth-child(1) { text-align: left; text-decoration-line: underline; } .decoration-line tbody tr:nth-child(1) td:nth-child(2) { text-align: left; text-decoration-line: line-through; } .decoration-line tbody tr:nth-child(1) td:nth-child(3) { text-align: left; text-decoration-line: line-through; } """ output = writer.dumps() print_test_result(expected=expected, actual=output) assert output == expected
def test_normal_ansi_style(self): writer = table_writer_class() writer.column_styles = [ Style(decoration_line="strike"), Style(decoration_line="line-through"), ] writer.headers = ["w/ strike", "w/ line through"] writer.value_matrix = [["strike", "line-through"]] expected = dedent("""\ |w/ strike|w/ line through| |---------|---------------| |strike |line-through | """) out = writer.dumps() print_test_result(expected=expected, actual=out) assert regexp_ansi_escape.search(out) assert regexp_ansi_escape.sub("", out) == expected