Skip to content

Commit

Permalink
div by 0 error
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Sep 24, 2018
1 parent 4d2c991 commit efc2795
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -5,6 +5,8 @@ matrix:
include:
- python: 2.6
env: PYV=2.6
before_install:
- pip install pycparser==2.17
- python: 2.7
env: PYV=2.7
- python: 3.4
Expand Down
6 changes: 5 additions & 1 deletion plumbum/cli/progress.py
Expand Up @@ -139,8 +139,12 @@ def done(self):
print()

def __str__(self):
percent = max(self.value, 0) / self.length
width = get_terminal_size(default=(0, 0))[0]
if self.length == 0:
self.width = 0
return "0/0 complete"

percent = max(self.value, 0) / self.length
ending = ' ' + (self.str_time_remaining()
if self.timer else '{0} of {1} complete'.format(
self.value, self.length))
Expand Down
13 changes: 10 additions & 3 deletions tests/test_terminal.py
Expand Up @@ -44,7 +44,7 @@ def test_str(self):
def test_default(self, capsys):
with send_stdin(""):
assert prompt("Enter nothing", default='hi') == 'hi'
assert capsys.readouterr()[0] == "Enter nothing [hi]: "
assert capsys.readouterr()[0] == "Enter nothing [hi]: "

def test_typefail(self, capsys):
with send_stdin("1.2\n13"):
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_choose(self, capsys):
with send_stdin("foo\n\n"):
assert choose("What is your favorite color?", ["blue", "yellow", "green"], default = "yellow") == "yellow"
assert capsys.readouterr()[0] == "What is your favorite color?\n(1) blue\n(2) yellow\n(3) green\nChoice [2]: Invalid choice, please try again\nChoice [2]: "

def test_choose_dict(self):
with send_stdin("23\n1"):
value = choose("Pick", dict(one="a",two="b"))
Expand All @@ -104,7 +104,7 @@ def test_choose_dict_default(self, capsys):
with send_stdin():
assert choose("Pick", dic, default="a") == "a"
assert "[1]" in capsys.readouterr()[0]


def test_hexdump(self):
data = "hello world my name is queen marry" + "A" * 66 + "foo bar"
Expand Down Expand Up @@ -137,3 +137,10 @@ def test_progress(self, capsys):
"""
assert stdout == output

def test_progress_empty(self, capsys):
for i in Progress.range(0, has_output=True, timer=False):
print('hi')
stdout, stderr = capsys.readouterr()
output = '0/0 complete'
assert output in stdout

0 comments on commit efc2795

Please sign in to comment.