Skip to content

Commit

Permalink
Complete test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Jul 5, 2018
1 parent 622c02a commit 67c5d25
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/test_bad_width.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from txtble import Txtble, IndeterminateWidthError

BAD_STRING = '\033[31mRed\033[0m'
ERRMSG = repr(BAD_STRING) + ': string has indeterminate width'

def test_indeterminate_cell():
tbl = Txtble(
Expand All @@ -11,6 +12,7 @@ def test_indeterminate_cell():
with pytest.raises(IndeterminateWidthError) as excinfo:
str(tbl)
assert excinfo.value.string == BAD_STRING
assert str(excinfo.value) == ERRMSG

def test_indeterminate_header():
tbl = Txtble(
Expand All @@ -20,6 +22,7 @@ def test_indeterminate_header():
with pytest.raises(IndeterminateWidthError) as excinfo:
str(tbl)
assert excinfo.value.string == BAD_STRING
assert str(excinfo.value) == ERRMSG

def test_indeterminate_header_fill():
tbl = Txtble(
Expand All @@ -30,6 +33,7 @@ def test_indeterminate_header_fill():
with pytest.raises(IndeterminateWidthError) as excinfo:
str(tbl)
assert excinfo.value.string == BAD_STRING
assert str(excinfo.value) == ERRMSG

def test_indeterminate_row_fill():
tbl = Txtble(
Expand All @@ -40,6 +44,7 @@ def test_indeterminate_row_fill():
with pytest.raises(IndeterminateWidthError) as excinfo:
str(tbl)
assert excinfo.value.string == BAD_STRING
assert str(excinfo.value) == ERRMSG

def test_indeterminate_none_str():
tbl = Txtble(
Expand All @@ -50,6 +55,7 @@ def test_indeterminate_none_str():
with pytest.raises(IndeterminateWidthError) as excinfo:
str(tbl)
assert excinfo.value.string == BAD_STRING
assert str(excinfo.value) == ERRMSG

def test_indeterminate_padding():
tbl = Txtble(
Expand All @@ -60,3 +66,4 @@ def test_indeterminate_padding():
with pytest.raises(IndeterminateWidthError) as excinfo:
str(tbl)
assert excinfo.value.string == BAD_STRING
assert str(excinfo.value) == ERRMSG
12 changes: 12 additions & 0 deletions test/test_plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ def test_headers_not_matching_columns(columns):
tbl = Txtble(DATA, headers=HEADERS, columns=columns)
with pytest.raises(ValueError):
str(tbl)

@pytest.mark.parametrize('columns', [0, -1])
def test_bad_columns(columns):
with pytest.raises(ValueError, match='columns must be at least 1'):
Txtble(DATA, columns=columns)

@pytest.mark.parametrize('columns', [0, -1])
def test_bad_columns_attr(columns):
tbl = Txtble(DATA)
tbl.columns = columns
with pytest.raises(ValueError, match='columns must be at least 1'):
str(tbl)
10 changes: 10 additions & 0 deletions test/test_ragged.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,14 @@ def test_empty_headers_header_fill():
'+------+------+------+------+------+------+------+'
)

def test_bad_row_fill():
with pytest.raises(ValueError, match='row_fill cannot be None'):
Txtble(DATA, row_fill=None)

def test_bad_row_fill_attr():
tbl = Txtble(DATA)
tbl.row_fill = None
with pytest.raises(ValueError, match='row_fill cannot be None'):
str(tbl)

# vim:set nowrap:

0 comments on commit 67c5d25

Please sign in to comment.