Skip to content

Commit 7e5d95b

Browse files
committed
BetterTestCov: Tests for shape
Signed-off-by: Gabe Goodhart <[email protected]>
1 parent 50a4133 commit 7e5d95b

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

scriptit/shape.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ def progress_bar(
4949
Returns:
5050
progress_bar_str (str): String for the progress bar
5151
"""
52-
assert len(done_char) == 1
53-
assert len(undone_char) == 1
54-
assert len(head_char) == 1
52+
if len(done_char) != 1 or len(undone_char) != 1 or len(head_char) != 1:
53+
raise ValueError("All char args must have length 1")
54+
# Flatten to [0, 1]. This is done instead of raising since this may be
55+
# computed and should not break
56+
complete_pct = max(min(1.0, complete_pct), 0.0)
5557
if width is None:
5658
width = shutil.get_terminal_size().columns
5759
n_done = int((width - 3) * complete_pct)

tests/test_shape.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Tests for the shape module
3+
"""
4+
# Standard
5+
import re
6+
7+
# Third Party
8+
import pytest
9+
10+
# Local
11+
from scriptit import shape
12+
13+
14+
def test_progress_bar():
15+
"""Test various progress_bar configurations"""
16+
assert shape.progress_bar(0.5, 10) == "[===>----]"
17+
assert (
18+
shape.progress_bar(0.5, 10, done_char=">", undone_char=".", head_char="|")
19+
== "[>>>|....]"
20+
)
21+
assert shape.progress_bar(-1, 10) == "[>-------]"
22+
assert shape.progress_bar(2, 10) == "[=======>]"
23+
match = re.match(r"\[(=+)>(-)+\]", shape.progress_bar(0.75))
24+
assert match
25+
assert len(match.group(1)) > len(match.group(2))
26+
with pytest.raises(ValueError):
27+
shape.progress_bar(0.5, 10, done_char="xx")
28+
29+
30+
def test_box():
31+
"""Test various"""

0 commit comments

Comments
 (0)