Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Nov 19, 2017
1 parent 57676a1 commit 27eb610
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 81 deletions.
91 changes: 36 additions & 55 deletions test/test_csv_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,80 +32,71 @@
Data = collections.namedtuple("Data", "col_delim header value expected")

normal_test_data_list = [
Data(
col_delim=",",
header=header_list,
value=value_matrix,
expected=""""a","b","c","dd","e"
Data(col_delim=",",
header=header_list,
value=value_matrix,
expected=""""a","b","c","dd","e"
1,123.1,"a",1,1
2,2.2,"bb",2.2,2.2
3,3.3,"ccc",3,"cccc"
"""),
Data(
col_delim=",",
header=header_list,
value=[],
expected=""""a","b","c","dd","e"
Data(col_delim=",",
header=header_list,
value=[],
expected=""""a","b","c","dd","e"
"""),
Data(
col_delim=",",
header=[],
value=value_matrix,
expected="""1,123.1,"a",1,1
Data(col_delim=",",
header=[],
value=value_matrix,
expected="""1,123.1,"a",1,1
2,2.2,"bb",2.2,2.2
3,3.3,"ccc",3,"cccc"
"""),
Data(
col_delim="\t",
header=None,
value=value_matrix,
expected="""1\t123.1\t"a"\t1\t1
Data(col_delim="\t",
header=None,
value=value_matrix,
expected="""1\t123.1\t"a"\t1\t1
2\t2.2\t"bb"\t2.2\t2.2
3\t3.3\t"ccc"\t3\t"cccc"
"""),
Data(
col_delim=",",
header=header_list,
value=value_matrix_with_none,
expected=""""a","b","c","dd","e"
Data(col_delim=",",
header=header_list,
value=value_matrix_with_none,
expected=""""a","b","c","dd","e"
1,,"a",1,
,2.2,,2.2,2.2
3,3.3,"ccc",,"cccc"
,,,,
"""),
Data(
col_delim=",",
header=mix_header_list,
value=mix_value_matrix,
expected=""""i","f","c","if","ifc","bool","inf","nan","mix_num","time"
Data(col_delim=",",
header=mix_header_list,
value=mix_value_matrix,
expected=""""i","f","c","if","ifc","bool","inf","nan","mix_num","time"
1,1.1,"aa",1,1,True,Infinity,NaN,1,"2017-01-01T00:00:00"
2,2.2,"bbb",2.2,2.2,False,Infinity,NaN,Infinity,"2017-01-02 03:04:05+09:00"
3,3.33,"cccc",-3,"ccc",True,Infinity,NaN,NaN,"2017-01-01T00:00:00"
"""),
Data(
col_delim=",",
header=float_header_list,
value=float_value_matrix,
expected=""""a","b","c"
Data(col_delim=",",
header=float_header_list,
value=float_value_matrix,
expected=""""a","b","c"
0.01,0.00125,0
1,99.9,0.01
1.2,999999.123,0.001
"""),
Data(
col_delim=",",
header=["a\nb", "c\n\nd", "e\r\nf"],
value=[["v1\nv1", "v2\n\nv2", "v3\r\nv3"]],
expected=""""a b","c d","e f"
Data(col_delim=",",
header=["a\nb", "c\n\nd", "e\r\nf"],
value=[["v1\nv1", "v2\n\nv2", "v3\r\nv3"]],
expected=""""a b","c d","e f"
"v1 v1","v2 v2","v3 v3"
"""),
]

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

Expand Down Expand Up @@ -145,11 +136,6 @@ def test_normal_from_text(self, capsys):

assert writer.table_name == "csv1"
assert writer.header_list == ["a", "b", "c", "dd", "e"]
assert writer.value_matrix == [
[1, Decimal('1.1'), 'a', Decimal('1.0'), ''],
[2, Decimal('2.2'), '', Decimal('2.2'), Decimal('2.2')],
[3, Decimal('3.3'), 'ccc', '', 'cc\ncc']
]

print("[expected]\n{}".format(self.__CSV_EXPECTED))
print("[actual]\n{}".format(out))
Expand All @@ -169,11 +155,6 @@ def test_normal_from_file(self, capsys, tmpdir):

assert writer.table_name == "test_data"
assert writer.header_list == ["a", "b", "c", "dd", "e"]
assert writer.value_matrix == [
[1, Decimal('1.1'), 'a', Decimal('1'), ''],
[2, Decimal('2.2'), '', Decimal('2.2'), Decimal('2.2')],
[3, Decimal('3.3'), 'ccc', '', 'cc\ncc']
]

print("[expected]\n{}".format(self.__CSV_EXPECTED))
print("[actual]\n{}".format(out))
Expand Down
24 changes: 1 addition & 23 deletions test/test_markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from decimal import Decimal

import pytest
from tabledata import TableData

import pytablewriter as ptw
from tabledata import TableData

from .data import (
header_list,
Expand Down Expand Up @@ -321,28 +321,6 @@ def test_normal(self, capsys):
assert out == "\n"


class Test_MarkdownTableWriter_set_table_data(object):

def test_normal(self):
writer = table_writer_class()
writer.from_tabledata(TableData(
"tmp",
["attr_a", "attr_b", "attr_c"],
[
["1", "4", "a"],
["2", "2.1", "bb"],
["3", "120.9", "ccc"],
]))

assert writer.table_name == "tmp"
assert writer.header_list == ["attr_a", "attr_b", "attr_c"]
assert writer.value_matrix == [
[1, 4, "a"],
[2, Decimal("2.1"), "bb"],
[3, Decimal("120.9"), "ccc"],
]


class Test_MarkdownTableWriter_write_table(object):

@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions test/test_sqlite_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from decimal import Decimal

import pytest
from tabledata import TableData

import pytablereader as ptr
import pytablewriter as ptw
from tabledata import TableData

from .data import (
header_list,
Expand Down Expand Up @@ -57,15 +57,15 @@
[
[
1, "1.1", 'aa', 1, 1, 1, inf,
nan, 1, '2017-01-01T00:00:00',
nan, 1, '2017-01-01 00:00:00',
],
[
2, "2.2", 'bbb', "2.2", "2.2", 0, inf, nan,
inf, '2017-01-02 03:04:05+09:00',
],
[
3, "3.33", 'cccc', -3, 'ccc', 1, inf,
nan, nan, '2017-01-01T00:00:00',
nan, nan, '2017-01-01 00:00:00',
],
])),
Data(
Expand Down

0 comments on commit 27eb610

Please sign in to comment.