How to use the pytablewriter.EmptyTableDataError 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 / writer / binary / test_excel_writer.py View on Github external
expected=TableData(
            "infnan", ["inf", "nan"], [[inf, nan], [inf, nan], [inf, nan], [inf, inf]]
        ),
    ),
    Data(
        table="line breaks",
        header=["a\nb", "\nc\n\nd\n", "e\r\nf"],
        value=[["v1\nv1", "v2\n\nv2", "v3\r\nv3"]],
        expected=TableData(
            "line breaks", ["a\nb", "\nc\n\nd\n", "e\r\nf"], [["v1\nv1", "v2\n\nv2", "v3\r\nv3"]]
        ),
    ),
]

invalid_test_data_list = [
    Data(table="", header=header, value=value, expected=ptw.EmptyTableDataError)
    for header, value in itertools.product([None, [], ""], [None, [], ""])
]

table_writer_class_list = [ptw.ExcelXlsTableWriter, ptw.ExcelXlsxTableWriter]


@pytest.mark.xfail(run=False)
class Test_ExcelTableWriter_write_table(object):
    @pytest.mark.parametrize(
        ["writer_class", "table", "header", "value", "expected"],
        [
            [writer_class, data.table, data.header, data.value, data.expected]
            for writer_class, data in itertools.product(
                table_writer_class_list, normal_test_data_list
            )
        ],
github thombashi / pytablewriter / test / writer / text / test_json_writer.py View on Github external
"b": 99.9,
    "c": 0.01
},
{
    "a": 1.2,
    "b": 999999.123,
    "c": 0.001
}]}

"""
        ),
    ),
]

exception_test_data_list = [
    Data(table="", header=[], value=[], expected=pytablewriter.EmptyTableDataError),
    Data(
        table="",
        header=[],
        value=normal_test_data_list[0].value,
        expected=pytablewriter.EmptyHeaderError,
    ),
]

table_writer_class = pytablewriter.JsonTableWriter


class Test_JsonTableWriter_write_new_line(object):
    def test_normal(self, capsys):
        writer = table_writer_class()
        writer.write_null_line()
github thombashi / pytablewriter / test / writer / text / test_latex_matrix_writer.py View on Github external
table="C",
        header="",
        value=value_matrix,
        expected=r"""\begin{equation}
    C = \left( \begin{array}{rrlrl}
        1 & 123.1 & a   & 1.0 &    1 \\
        2 &   2.2 & bb  & 2.2 &  2.2 \\
        3 &   3.3 & ccc & 3.0 & cccc \\
    \end{array} \right)
\end{equation}
""",
    ),
]

exception_test_data_list = [
    Data(table=table, header=header, value=value, expected=ptw.EmptyTableDataError)
    for table, header, value in itertools.product([None, [], ""], [None, [], ""], [None, [], ""])
]

table_writer_class = ptw.LatexMatrixWriter


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

        out, _err = capsys.readouterr()

        assert out == "\n"
github thombashi / pytablewriter / test / writer / binary / test_sqlite_writer.py View on Github external
),
    Data(
        table="empty header",
        header=[],
        value=value_matrix,
        expected=TableData(
            "empty_header",
            ["A", "B", "C", "D", "E"],
            [[1, 123.1, "a", 1, 1], [2, 2.2, "bb", 2.2, 2.2], [3, 3.3, "ccc", 3, "cccc"]],
        ),
    ),
]

exception_test_data_list = [
    Data(table="", header=headers, value=value_matrix, expected=ptw.EmptyTableNameError),
    Data(table="dummy", header=[], value=[], expected=ptw.EmptyTableDataError),
    Data(table="dummy", header=headers, value=[], expected=ptw.EmptyValueError),
]


@pytest.mark.xfail(run=False)
class Test_SqliteTableWriter_write_table(object):
    @pytest.mark.parametrize(
        ["table", "header", "value", "expected"],
        [[data.table, data.header, data.value, data.expected] for data in normal_test_data_list],
    )
    def test_normal(self, tmpdir, table, header, value, expected):
        test_file_path = tmpdir.join("test.sqlite")

        writer = ptw.SqliteTableWriter()
        writer.open(str(test_file_path))
        writer.table_name = table
github thombashi / pytablewriter / test / writer / text / test_tsv_writer.py View on Github external
3\t3.3\t"ccc"\t3\t"cccc"
""",
    ),
    Data(
        header=float_header_list,
        value=float_value_matrix,
        expected=""""a"\t"b"\t"c"
0.01\t0.00125\t0
1\t99.9\t0.01
1.2\t999999.123\t0.001
""",
    ),
]

exception_test_data_list = [
    Data(header=header, value=value, expected=ptw.EmptyTableDataError)
    for header, value in itertools.product([None, [], ""], [None, [], ""])
]

table_writer_class = ptw.TsvTableWriter


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

        out, _err = capsys.readouterr()

        assert out == "\n"

github thombashi / pytablewriter / test / writer / text / test_latex_table_writer.py View on Github external
Data(
        header=float_header_list,
        value=float_value_matrix,
        expected=r"""\begin{array}{r | r | r} \hline
    \verb| a  | & \verb|     b     | & \verb|  c  | \\ \hline
    \hline
    0.01 &      0.0012 & 0.000 \\ \hline
    1.00 &     99.9000 & 0.010 \\ \hline
    1.20 & 999999.1230 & 0.001 \\ \hline
\end{array}
""",
    ),
]

exception_test_data_list = [
    Data(header=header, value=value, expected=ptw.EmptyTableDataError)
    for header, value in itertools.product([None, [], ""], [None, [], ""])
]

table_writer_class = ptw.LatexTableWriter


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

        out, _err = capsys.readouterr()

        assert out == "\n"
github thombashi / pytablewriter / test / writer / text / test_ltsv_writer.py View on Github external
),
    Data(
        header=float_header_list,
        value=float_value_matrix,
        expected=dedent(
            """\
            a:0.01\tb:0.00125\tc:0
            a:1\tb:99.9\tc:0.01
            a:1.2\tb:999999.123\tc:0.001
            """
        ),
    ),
]

exception_test_data_list = [
    Data(header=header, value=value, expected=ptw.EmptyTableDataError)
    for header, value in itertools.product([None, [], ""], [None, [], ""])
] + [Data(header=None, value=value_matrix, expected=ptw.EmptyHeaderError)]

table_writer_class = ptw.LtsvTableWriter


class Test_LtsvTableWriter_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_LtsvTableWriter_write_table(object):
github thombashi / pytablewriter / test / writer / text / test_toml_writer.py View on Github external
c = 0
[[float]]
a = 1
b = 99.9
c = 0.01
[[float]]
a = 1.2
b = 999999.123
c = 0.001

""",
    ),
]

exception_test_data_list = [
    Data(table_name="dummy", header=header, value=value, expected=ptw.EmptyTableDataError)
    for header, value in itertools.product([None, [], ""], [None, [], ""])
] + [
    Data(table_name="empty_header", header=None, value=value_matrix, expected=ptw.EmptyHeaderError),
    Data(table_name=None, header=headers, value=value_matrix, expected=ptw.EmptyTableNameError),
]

table_writer_class = ptw.TomlTableWriter


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

        out, _err = capsys.readouterr()
        assert out == "\n"
github thombashi / pytablewriter / test / writer / text / test_markdown_writer.py View on Github external
|  0| 0.1|foo |
            |   |    |    |
            | -1|-0.1|bar |
            """
        ),
    ),
]

exception_test_data_list = [
    Data(
        table="",
        indent=0,
        header=[],
        value=[],
        is_formatting_float=True,
        expected=ptw.EmptyTableDataError,
    )
]

table_writer_class = ptw.MarkdownTableWriter


def trans_func(value):
    if value is None:
        return ""
    if value is True:
        return "X"
    if value is False:
        return ""
    return value

github thombashi / pytablewriter / test / writer / text / test_jsonlines_writer.py View on Github external
{"a": 3, "b": 3.3, "c": "ccc", "dd": "null", "e": "cccc"},
            {"a": "null", "b": "null", "c": "null", "dd": "null", "e": "null"},
        ],
    ),
    Data(
        header=float_header_list,
        value=float_value_matrix,
        expected_list=[
            {"a": 0.01, "b": 0.00125, "c": 0},
            {"a": 1, "b": 99.9, "c": 0.01},
            {"a": 1.2, "b": 999999.123, "c": 0.001},
        ],
    ),
]
exception_test_data_list = [
    Data(header=header, value=value, expected_list=ptw.EmptyTableDataError)
    for header, value in itertools.product([None, [], ""], [None, [], ""])
] + [Data(header=None, value=value_matrix, expected_list=ptw.EmptyHeaderError)]
table_writer_class = ptw.JsonLinesTableWriter


class Test_JsonLinesTableWriter_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_JsonLinesTableWriter_write_table(object):
    @pytest.mark.parametrize(