Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
)
],
"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()
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"
),
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
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"
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"
),
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):
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"
| 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
{"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(