How to use the pytablewriter.RstSimpleTableWriter function in pytablewriter

To help you get started, we’ve selected a few pytablewriter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / pytablewriter / test / test_writer_factory.py View on Github external
            ["rst_simple_table", ptw.RstSimpleTableWriter],
            ["rst_csv_table", ptw.RstCsvTableWriter],
            ["space_aligned", ptw.SpaceAlignedTableWriter],
            ["SPACE_ALIGNED", ptw.SpaceAlignedTableWriter],
            ["sqlite", ptw.SqliteTableWriter],
            ["SQLite", ptw.SqliteTableWriter],
            ["tsv", ptw.TsvTableWriter],
            ["TSV", ptw.TsvTableWriter],
            ["toml", ptw.TomlTableWriter],
            ["TOML", ptw.TomlTableWriter],
            ["unicode", ptw.UnicodeTableWriter],
            ["Unicode", ptw.UnicodeTableWriter],
        ],
    )
    def test_normal(self, format_name, expected):
        writer = ptw.TableWriterFactory.create_from_format_name(format_name)
github thombashi / pytablewriter / test / writer / text / test_rst_simple_writer.py View on Github external
"""\
            .. table:: table name

                =  ====  ====  ====  ===  =====  ========  ===  ========  =========================
                i   f     c     if   ifc  bool     inf     nan  mix_num             time           
                =  ====  ====  ====  ===  =====  ========  ===  ========  =========================
                1  1.10  aa     1.0    1  True   Infinity  NaN         1  2017-01-01T00:00:00      
                2  2.20  bbb    2.2  2.2  False  Infinity  NaN  Infinity  2017-01-02 03:04:05+09:00
                3  3.33  cccc  -3.0  ccc  True   Infinity  NaN       NaN  2017-01-01T00:00:00      
                =  ====  ====  ====  ===  =====  ========  ===  ========  =========================
            """
        ),
    ),
]

table_writer_class = pytablewriter.RstSimpleTableWriter


class Test_RstSimpleTableWriter_write_new_line(object):
    def test_normal(self, capsys):
        writer = table_writer_class()
        writer.write_null_line()

        out, _err = capsys.readouterr()
        assert out == "\n"


class Test_RstSimpleTableWriter_write_table(object):
    @pytest.mark.parametrize(
        ["table", "indent", "header", "value", "expected"],
        [
            [data.table, data.indent, data.header, data.value, data.expected]
github thombashi / pytablewriter / examples / py / multi_byte_table.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi 
"""

import pytablewriter


writer = pytablewriter.RstSimpleTableWriter()
writer.table_name = "生成に関するパターン"
writer.headers = ["パターン名", "概要", "GoF", "Code Complete[1]"]
writer.value_matrix = [
    ["Abstract Factory", "関連する一連のインスタンスを状況に応じて、適切に生成する方法を提供する。", "Yes", "Yes"],
    ["Builder", "複合化されたインスタンスの生成過程を隠蔽する。", "Yes", "No"],
    ["Factory Method", "実際に生成されるインスタンスに依存しない、インスタンスの生成方法を提供する。", "Yes", "Yes"],
    ["Prototype", "同様のインスタンスを生成するために、原型のインスタンスを複製する。", "Yes", "No"],
    ["Singleton", "あるクラスについて、インスタンスが単一であることを保証する。", "Yes", "Yes"],
]
writer.dump("multibyte_table_output.txt")
github thombashi / typepy / docs / make_result_matrix.py View on Github external
def __init__(self):
        self.typeclass = None
        self.strict_level = None
        self.headers = None
        self.value_list = None

        self.__table_writer = ptw.RstSimpleTableWriter()
        self.__table_writer._dp_extractor.type_value_map = {
            NullString(None).typecode: '``""``',
            NoneType(None).typecode: "``None``",
            Infinity(None).typecode: '``Decimal("inf")``',
            Nan(None).typecode: '``Decimal("nan")``',
        }
        self.__table_writer.value_map = {
            True: "``True``",
            False: "``False``",
            '``"127.0.0.1"``': '``ip_address("127.0.0.1")``',
        }
github hugovk / pypistats / src / pypistats / __init__.py View on Github external
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")