Skip to content

Commit

Permalink
Apply formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Aug 30, 2020
1 parent 1f70528 commit 8e3dc51
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 42 deletions.
3 changes: 1 addition & 2 deletions pytablewriter/style/_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ def __ne__(self, other):
return NotImplemented if equal is NotImplemented else not equal

def update(self, **kwargs) -> None:
"""Update specified style attributes.
"""
"""Update specified style attributes."""
self.__update(initialize=False, **kwargs)

def __update(self, initialize: bool, **kwargs) -> None:
Expand Down
15 changes: 5 additions & 10 deletions pytablewriter/writer/_table_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def header_list(self, value):

@property
def value_matrix(self) -> List:
"""Data of a table to be outputted.
"""
"""Data of a table to be outputted."""

return self.__value_matrix_org

Expand Down Expand Up @@ -315,8 +314,7 @@ def __clear_preprocess_data(self) -> None:

@property
def headers(self) -> Sequence[str]:
"""Headers of a table to be outputted.
"""
"""Headers of a table to be outputted."""

return self._dp_extractor.headers

Expand Down Expand Up @@ -346,8 +344,7 @@ def max_workers(self, value: Optional[int]) -> None:

@property
def table_name(self) -> str:
"""Name of a table.
"""
"""Name of a table."""

return self._table_name

Expand Down Expand Up @@ -407,8 +404,7 @@ def type_hints(self, value: Sequence) -> None:

@property
def default_style(self) -> Style:
"""Default |Style| of table cells.
"""
"""Default |Style| of table cells."""

return self.__default_style

Expand Down Expand Up @@ -508,8 +504,7 @@ def add_col_separator_style_filter(self, style_filter: ColSeparatorStyleFilterFu
raise NotImplementedError("this method only implemented in text format writer classes")

def clear_theme(self) -> None:
"""Remove all of the style filters.
"""
"""Remove all of the style filters."""

if not self._style_filters:
return
Expand Down
26 changes: 16 additions & 10 deletions pytablewriter/writer/text/_text_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ def add_col_separator_style_filter(self, style_filter: ColSeparatorStyleFilterFu
self._clear_preprocess()

def clear_theme(self) -> None:
"""Remove all of the style filters.
"""
"""Remove all of the style filters."""

super().clear_theme()

Expand Down Expand Up @@ -359,7 +358,8 @@ def __get_row_separator_items(self, margin_format: str, separator_char: str) ->

def _get_header_format_string(self, col_dp: ColumnDataProperty, value_dp: DataProperty) -> str:
return "{{:{:s}{:s}}}".format(
get_align_char(Align.CENTER), str(self._get_padding_len(col_dp, value_dp)),
get_align_char(Align.CENTER),
str(self._get_padding_len(col_dp, value_dp)),
)

def _to_header_item(self, col_dp: ColumnDataProperty, value_dp: DataProperty) -> str:
Expand Down Expand Up @@ -420,7 +420,9 @@ def __to_column_delimiter(
)

style = self._fetch_col_separator_style(
left_cell=left_cell, right_cell=right_cell, default_style=self.default_style,
left_cell=left_cell,
right_cell=right_cell,
default_style=self.default_style,
)

return self._styler.apply_terminal_style(col_delimiter, style=style)
Expand All @@ -432,7 +434,10 @@ def _write_row(self, row: int, values: Sequence[str]) -> None:
col_delimiters = (
[
self.__to_column_delimiter(
row, None, self._column_dp_list[0], self.char_left_side_row,
row,
None,
self._column_dp_list[0],
self.char_left_side_row,
)
]
+ [
Expand All @@ -446,7 +451,10 @@ def _write_row(self, row: int, values: Sequence[str]) -> None:
]
+ [
self.__to_column_delimiter(
row, self._column_dp_list[-1], None, self.char_right_side_row,
row,
self._column_dp_list[-1],
None,
self.char_right_side_row,
)
]
)
Expand Down Expand Up @@ -556,14 +564,12 @@ def set_indent_level(self, indent_level: int) -> None:
self._indent_level = indent_level

def inc_indent_level(self) -> None:
"""Increment the indentation level.
"""
"""Increment the indentation level."""

self._indent_level += 1

def dec_indent_level(self) -> None:
"""Decrement the indentation level.
"""
"""Decrement the indentation level."""

self._indent_level -= 1

Expand Down
3 changes: 2 additions & 1 deletion pytablewriter/writer/text/_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def __init__(self, _dict=dict, preserve=False):
row = {}

for header, value in zip(
self.headers, [serialize_dp(value_dp) for value_dp in value_dp_list],
self.headers,
[serialize_dp(value_dp) for value_dp in value_dp_list],
):
if typepy.is_null_string(value):
continue
Expand Down
56 changes: 48 additions & 8 deletions test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@
"time",
]
mix_value_matrix = [
[1, 1.1, "aa", 1, 1, True, INF, NAN, 1.0, TIME,],
[
1,
1.1,
"aa",
1,
1,
True,
INF,
NAN,
1.0,
TIME,
],
[
2,
2.2,
Expand All @@ -55,7 +66,18 @@
INF,
"2017-01-02 03:04:05+09:00",
],
[3, 3.33, "cccc", -3, "ccc", True, float("infinity"), float("NAN"), NAN, TIME,],
[
3,
3.33,
"cccc",
-3,
"ccc",
True,
float("infinity"),
float("NAN"),
NAN,
TIME,
],
]
mix_tabledata = TableData(table_name="mix data", headers=mix_header_list, rows=mix_value_matrix)

Expand All @@ -70,15 +92,33 @@
)

value_matrix_iter = [
[[1, 2, 3], [11, 12, 13],],
[[1, 2, 3], [11, 12, 13],],
[[101, 102, 103], [1001, 1002, 1003],],
[
[1, 2, 3],
[11, 12, 13],
],
[
[1, 2, 3],
[11, 12, 13],
],
[
[101, 102, 103],
[1001, 1002, 1003],
],
]

value_matrix_iter_1 = [
[["a b c d e f g h i jklmn", 2.1, 3], ["aaaaa", 12.1, 13],],
[["bbb", 2, 3], ["cc", 12, 13],],
[["a", 102, 103], ["", 1002, 1003],],
[
["a b c d e f g h i jklmn", 2.1, 3],
["aaaaa", 12.1, 13],
],
[
["bbb", 2, 3],
["cc", 12, 13],
],
[
["a", 102, 103],
["", 1002, 1003],
],
]

Data = collections.namedtuple("Data", "table indent header value expected")
Expand Down
3 changes: 2 additions & 1 deletion test/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

class Test_Cell_is_header_row:
@pytest.mark.parametrize(
["row", "expected"], [[-1, True], [0, False], [sys.maxsize, False]],
["row", "expected"],
[[-1, True], [0, False], [sys.maxsize, False]],
)
def test_normal(self, row, expected):
cell = Cell(row=row, col=0, value=None, default_style=None)
Expand Down
6 changes: 5 additions & 1 deletion test/test_table_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def test_normal(self, value, expected):
class Test_TableFormat_from_name:
@pytest.mark.parametrize(
["value", "expected"],
[["csv", TableFormat.CSV], ["CSV", TableFormat.CSV], ["excel", TableFormat.EXCEL_XLSX],],
[
["csv", TableFormat.CSV],
["CSV", TableFormat.CSV],
["excel", TableFormat.EXCEL_XLSX],
],
)
def test_normal(self, value, expected):
assert TableFormat.from_name(value) == expected
Expand Down
7 changes: 6 additions & 1 deletion test/writer/text/test_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@
]

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

table_writer_class = pytablewriter.JsonTableWriter
Expand Down
6 changes: 5 additions & 1 deletion test/writer/text/test_latex_table_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@
\end{array}
""",
),
Data(header=[], value=[], expected="",),
Data(
header=[],
value=[],
expected="",
),
]


Expand Down
14 changes: 12 additions & 2 deletions test/writer/text/test_markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,14 @@
"""
),
),
Data(table="", indent=0, header=[], value=[], is_formatting_float=True, expected="",),
Data(
table="",
indent=0,
header=[],
value=[],
is_formatting_float=True,
expected="",
),
]

table_writer_class = ptw.MarkdownTableWriter
Expand Down Expand Up @@ -422,7 +429,10 @@ def test_normal_kwargs(self):
writer = table_writer_class(
headers=["w/ strike", "w/ line through"],
value_matrix=[["strike", "line-through"]],
column_styles=[Style(decoration_line="strike"), Style(decoration_line="line-through"),],
column_styles=[
Style(decoration_line="strike"),
Style(decoration_line="line-through"),
],
)

expected = dedent(
Expand Down
8 changes: 7 additions & 1 deletion test/writer/text/test_numpy_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ def test_exception(self, table, indent, header, value, expected):
[
[data.table, data.indent, data.header, data.value, data.expected]
for data in [
Data(table=None, indent=0, header=headers, value=value_matrix, expected="",)
Data(
table=None,
indent=0,
header=headers,
value=value_matrix,
expected="",
)
]
],
)
Expand Down
8 changes: 7 additions & 1 deletion test/writer/text/test_pandas_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@
"""
),
),
Data(table="empty", indent=0, header=[], value=[], expected="",),
Data(
table="empty",
indent=0,
header=[],
value=[],
expected="",
),
]

exception_test_data_list = [
Expand Down
6 changes: 5 additions & 1 deletion test/writer/text/test_unicode_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

class Test_UnicodeTableWriter_write_new_line:
@pytest.mark.parametrize(
["table_writer_class"], [[UnicodeTableWriter], [BoldUnicodeTableWriter],]
["table_writer_class"],
[
[UnicodeTableWriter],
[BoldUnicodeTableWriter],
],
)
def test_normal(self, capsys, table_writer_class):
writer = table_writer_class()
Expand Down
9 changes: 7 additions & 2 deletions test/writer/text/test_yaml_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
),
),
Data(
tabledata=TableData(table_name=None, headers=[], rows=value_matrix,),
tabledata=TableData(
table_name=None,
headers=[],
rows=value_matrix,
),
expected=dedent(
"""\
- - 1
Expand Down Expand Up @@ -118,7 +122,8 @@ def test_normal(self, capsys):

class Test_YamlTableWriter_write_table:
@pytest.mark.parametrize(
["value", "expected"], [[data.tabledata, data.expected] for data in normal_test_data_list],
["value", "expected"],
[[data.tabledata, data.expected] for data in normal_test_data_list],
)
def test_normal(self, capsys, value, expected):
writer = table_writer_class()
Expand Down

0 comments on commit 8e3dc51

Please sign in to comment.