Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[Style(align=Align.RIGHT), Style(align=Align.RIGHT, font_size=FontSize.TINY), False],
[Style(font_size=FontSize.TINY), Style(font_size=FontSize.TINY), True],
[Style(font_size=FontSize.TINY), Style(font_size="tiny"), True],
[Style(font_size=FontSize.TINY), Style(font_size=FontSize.LARGE), False],
[Style(font_weight="bold"), Style(font_weight=FontWeight.BOLD), True],
[Style(font_weight="bold"), Style(font_weight="normal"), False],
[Style(font_style="italic"), Style(font_style=FontStyle.ITALIC), True],
[Style(font_style="italic"), Style(font_style="normal"), False],
[Style(thousand_separator=","), Style(thousand_separator=","), True],
[Style(thousand_separator=","), Style(thousand_separator="comma"), True],
[Style(thousand_separator=""), Style(thousand_separator=","), False],
[
Style(thousand_separator=ThousandSeparator.COMMA),
Style(thousand_separator=ThousandSeparator.COMMA),
True,
],
[
)
expected = dedent(
"""\
# set style method
|normal|style by idx|style by header|
|-----:|-----------:|:-------------:|
| 11| **11**| **11** |
|123456| **123,456**| **123 456** |
"""
)
output = writer.dumps()
print_test_result(expected=expected, actual=output)
assert output == expected
writer.table_name = "change style"
writer.set_style(1, Style(align="right", font_style="italic"))
writer.set_style("style by header", Style())
expected = dedent(
"""\
# change style
|normal|style by idx|style by header|
|-----:|-----------:|--------------:|
| 11| _11_| 11|
|123456| _123456_| 123456|
"""
)
output = writer.dumps()
print_test_result(expected=expected, actual=output)
assert output == expected
expected = dedent(
"""\
# auto align
|left| right | center |auto|auto| None |
|---:|-----------|------------|---:|----|-----------|
| 0|r |center align| 0|a |n |
| 11|right align|bb | 11|auto|none (auto)|
"""
)
out = writer.dumps()
print_test_result(expected=expected, actual=out)
assert out == expected
writer.table_name = "specify alignment for each column manually"
writer.styles = [
Style(align=Align.LEFT),
Style(align=Align.RIGHT),
Style(align=Align.CENTER),
Style(align=Align.AUTO),
Style(align=Align.AUTO),
None,
]
expected = dedent(
"""\
# specify alignment for each column manually
|left| right | center |auto|auto| None |
|----|----------:|:----------:|---:|----|-----------|
|0 | r|center align| 0|a |n |
|11 |right align| bb | 11|auto|none (auto)|
"""
)
out = writer.dumps()
writer.styles = styles
expected = r"""\begin{equation}
style test = \left( \begin{array}{rrrrrrlrrr}
111 & 111 & \tiny 111 & \small 111 & \normalsize 111 & \large 111 & & \large \bf 111 & \small \it 111 & \large \bf \it 111 \\
1234 & 1234 & \tiny 1234 & \small 1234 & \normalsize 1,234 & \large 1 234 & & \large \bf 1234 & \small \it 1234 & \large \bf \it 1234 \\
\end{array} \right)
\end{equation}
"""
out = writer.dumps()
print_test_result(expected=expected, actual=out)
assert out == expected
writer.styles = [
None,
Style(align="auto"),
Style(align="auto", font_size="tiny", thousand_separator=","),
Style(align="left", font_size="small", thousand_separator=" "),
Style(align="right", font_size="medium"),
Style(align="center", font_size="large"),
Style(font_size="large", font_weight="bold"),
]
out = writer.dumps()
expected = r"""\begin{equation}
style test = \left( \begin{array}{rrrlrclrrr}
111 & 111 & \tiny 111 & \small 111 & \normalsize 111 & \large 111 & & 111 & 111 & 111 \\
1234 & 1234 & \tiny 1,234 & \small 1 234 & \normalsize 1234 & \large 1234 & & 1234 & 1234 & 1234 \\
\end{array} \right)
\end{equation}
"""
print_test_result(expected=expected, actual=out)
assert out == expected
"medium",
"large",
"null w/ bold",
"L bold",
"S italic",
"L bold italic",
],
[
[111, 111, 111, 111, 111, 111, "", 111, 111, 111],
[1234, 1234, 1234, 1234, 1234, 1234, "", 1234, 1234, 1234],
])
styles = [
None,
Style(),
Style(font_size="TINY"),
Style(font_size="SMALL"),
Style(font_size="MEDIUM", thousand_separator=","),
Style(font_size="LARGE", thousand_separator=" "),
Style(font_weight="bold", thousand_separator=","),
Style(font_size="LARGE", font_weight="bold"),
Style(font_size="SMALL", font_style="italic"),
Style(font_size="LARGE", font_weight="bold", font_style="italic"),
]
[Style(font_weight="bold"), Style(font_weight="normal"), False],
[Style(font_style="italic"), Style(font_style=FontStyle.ITALIC), True],
[Style(font_style="italic"), Style(font_style="normal"), False],
[Style(thousand_separator=","), Style(thousand_separator=","), True],
[Style(thousand_separator=","), Style(thousand_separator="comma"), True],
[Style(thousand_separator=""), Style(thousand_separator=","), False],
[
Style(thousand_separator=ThousandSeparator.COMMA),
Style(thousand_separator=ThousandSeparator.COMMA),
True,
],
[
Style(thousand_separator="space"),
Style(thousand_separator=ThousandSeparator.SPACE),
True,
],
[
[Style(font_style="italic"), Style(font_style="normal"), False],
[Style(thousand_separator=","), Style(thousand_separator=","), True],
[Style(thousand_separator=","), Style(thousand_separator="comma"), True],
[Style(thousand_separator=""), Style(thousand_separator=","), False],
[
Style(thousand_separator=ThousandSeparator.COMMA),
Style(thousand_separator=ThousandSeparator.COMMA),
True,
],
[
Style(thousand_separator="space"),
Style(thousand_separator=ThousandSeparator.SPACE),
True,
],
[
Style(thousand_separator=ThousandSeparator.COMMA),
Style(thousand_separator=ThousandSeparator.COMMA, font_size=FontSize.TINY),
def _preprocess_styler(self):
if self._is_complete_styler_proprocess:
return
self._styler_list = []
for col_dp in self._column_dp_list:
style = self.__get_style(col_dp.column_index)
if style is None:
style = Style()
self._styler_list.append(self._create_styler(style, self))
self._is_complete_styler_proprocess = True
def print(self):
writer = MarkdownTableWriter()
writer.headers = self._make_headers()
writer.value_matrix = self._make_value_matrix()
writer.styles = [Style(align="left")] + [Style(align="center") for _ in range(len(writer.headers) - 1)]
writer.write_table()
print("\n" + self._make_versions_text())