`.
@@ -359,6 +367,7 @@ def table2ascii(
last_col_heading=last_col_heading,
column_widths=column_widths,
alignments=alignments,
+ cell_padding=cell_padding,
style=style,
),
).to_ascii()
diff --git a/tests/test_cell_padding.py b/tests/test_cell_padding.py
new file mode 100644
index 0000000..6190053
--- /dev/null
+++ b/tests/test_cell_padding.py
@@ -0,0 +1,82 @@
+import pytest
+
+from table2ascii import Alignment, table2ascii as t2a
+
+
+def test_without_cell_padding():
+ text = t2a(
+ header=["#", "G", "H", "R", "S"],
+ body=[[1, 2, 3, 4, 5]],
+ footer=["A", "B", 1, 2, 3],
+ first_col_heading=True,
+ cell_padding=0,
+ )
+ expected = (
+ "āāā¦āāāāāāāā\n"
+ "ā#āG H R Sā\n"
+ "āāā«āāāāāāāā¢\n"
+ "ā1ā2 3 4 5ā\n"
+ "āāā«āāāāāāāā¢\n"
+ "āAāB 1 2 3ā\n"
+ "āāā©āāāāāāāā"
+ )
+ assert text == expected
+
+
+def test_column_width_and_alignment_without_cell_padding():
+ text = t2a(
+ header=["#", "G", "H", "R", "S"],
+ body=[[1, 2, 3, 4, 5]],
+ footer=["A", "B", 1, 2, 3],
+ column_widths=[4, 8, 5, 4, 5],
+ alignments=[
+ Alignment.LEFT,
+ Alignment.CENTER,
+ Alignment.RIGHT,
+ Alignment.LEFT,
+ Alignment.RIGHT,
+ ],
+ first_col_heading=True,
+ cell_padding=0,
+ )
+ expected = (
+ "āāāāāā¦āāāāāāāāāāāāāāāāāāāāāāāāāā\n"
+ "ā# ā G H R Sā\n"
+ "āāāāāā«āāāāāāāāāāāāāāāāāāāāāāāāāā¢\n"
+ "ā1 ā 2 3 4 5ā\n"
+ "āāāāāā«āāāāāāāāāāāāāāāāāāāāāāāāāā¢\n"
+ "āA ā B 1 2 3ā\n"
+ "āāāāāā©āāāāāāāāāāāāāāāāāāāāāāāāāā"
+ )
+ assert text == expected
+
+
+def test_cell_padding_more_than_one():
+ text = t2a(
+ header=["#", "G", "H", "R", "S"],
+ body=[[1, 2, 3, 4, 5]],
+ footer=["A", "B", 1, 2, 3],
+ first_col_heading=True,
+ cell_padding=2,
+ )
+ expected = (
+ "āāāāāāā¦āāāāāāāāāāāāāāāāāāāāāāāā\n"
+ "ā # ā G H R S ā\n"
+ "āāāāāāā«āāāāāāāāāāāāāāāāāāāāāāāā¢\n"
+ "ā 1 ā 2 3 4 5 ā\n"
+ "āāāāāāā«āāāāāāāāāāāāāāāāāāāāāāāā¢\n"
+ "ā A ā B 1 2 3 ā\n"
+ "āāāāāāā©āāāāāāāāāāāāāāāāāāāāāāāā"
+ )
+ assert text == expected
+
+
+def test_negative_cell_padding():
+ with pytest.raises(ValueError):
+ t2a(
+ header=["#", "G", "H", "R", "S"],
+ body=[[1, 2, 3, 4, 5]],
+ footer=["A", "B", 1, 2, 3],
+ first_col_heading=True,
+ cell_padding=-1,
+ )
diff --git a/tests/test_styles.py b/tests/test_styles.py
index 30e1670..422f0c1 100644
--- a/tests/test_styles.py
+++ b/tests/test_styles.py
@@ -649,3 +649,21 @@ def test_markdown():
"| SUM | 130 | 140 | 135 | 130 |"
)
assert text == expected
+
+
+def test_plain():
+ text = t2a(
+ header=["#", "G", "H", "R", "S"],
+ body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
+ footer=["SUM", "130", "140", "135", "130"],
+ first_col_heading=True,
+ last_col_heading=False,
+ style=PresetStyle.plain,
+ )
+ expected = (
+ " # G H R S \n"
+ " 1 30 40 35 30 \n"
+ " 2 30 40 35 30 \n"
+ " SUM 130 140 135 130 "
+ )
+ assert text == expected
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy