Skip to content

Commit 36e74b8

Browse files
committed
fix: Throw exception if no header, body, or footer
1 parent ea432b5 commit 36e74b8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

table2ascii/exceptions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ def _message(self):
128128
)
129129

130130

131+
class NoHeaderBodyOrFooterError(TableOptionError):
132+
"""Exception raised when no header, body or footer is provided
133+
134+
This class is a subclass of :class:`TableOptionError`.
135+
"""
136+
137+
def __init__(self):
138+
super().__init__(self._message())
139+
140+
def _message(self) -> str:
141+
return "At least one of header, body or footer must be provided."
142+
143+
131144
class InvalidCellPaddingError(TableOptionError):
132145
"""Exception raised when the cell padding is invalid
133146

tests/test_convert.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import pytest
22

33
from table2ascii import table2ascii as t2a
4-
from table2ascii.exceptions import BodyColumnCountMismatchError, FooterColumnCountMismatchError
4+
from table2ascii.exceptions import (
5+
BodyColumnCountMismatchError,
6+
FooterColumnCountMismatchError,
7+
NoHeaderBodyOrFooterError,
8+
)
59

610

711
def test_header_body_footer():
@@ -117,6 +121,11 @@ def test_footer():
117121
assert text == expected
118122

119123

124+
def test_no_header_body_or_footer():
125+
with pytest.raises(NoHeaderBodyOrFooterError):
126+
t2a()
127+
128+
120129
def test_header_footer_unequal():
121130
with pytest.raises(FooterColumnCountMismatchError):
122131
t2a(

0 commit comments

Comments
 (0)