Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
["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)
"""\
.. 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]
#!/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")
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")``',
}
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")