summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-07-01 09:03:51 +1200
committerLars Wirzenius <liw@liw.fi>2010-07-01 09:03:51 +1200
commitd5a5ffe6754f04cc9c315fae585ca967ed1f4316 (patch)
tree5b247832a131c8535d53174036b184c2e1f9577b
parentfdd66e3f94b3feb6a54a07c3bb5c67d559d1a136 (diff)
downloadpython-ttystatus-d5a5ffe6754f04cc9c315fae585ca967ed1f4316.tar.gz
Handle zero speed correctly.
-rw-r--r--ttystatus/remtime.py10
-rw-r--r--ttystatus/remtime_tests.py5
2 files changed, 12 insertions, 3 deletions
diff --git a/ttystatus/remtime.py b/ttystatus/remtime.py
index 98a8643..fa83030 100644
--- a/ttystatus/remtime.py
+++ b/ttystatus/remtime.py
@@ -27,7 +27,8 @@ class RemainingTime(ttystatus.Widget):
self.done_name = done_name
self.total_name = total_name
self.started = None
- self.value = '--h--m--s'
+ self.default = '--h--m--s'
+ self.value = self.default
def get_time(self): # pragma: no cover
'''Return current time.
@@ -55,5 +56,8 @@ class RemainingTime(ttystatus.Widget):
total = float(master[self.total_name])
speed = done / duration
remaining = total - done
- secs = remaining / speed
- self.value = self.format(secs)
+ if speed > 0:
+ secs = remaining / speed
+ self.value = self.format(secs)
+ else:
+ self.value = self.default
diff --git a/ttystatus/remtime_tests.py b/ttystatus/remtime_tests.py
index 817048b..5ddd8bb 100644
--- a/ttystatus/remtime_tests.py
+++ b/ttystatus/remtime_tests.py
@@ -40,3 +40,8 @@ class RemainingTimeTests(unittest.TestCase):
self.w.update({ 'done': 80, 'total': 100 }, 999)
self.assertEqual(str(self.w), '00h00m05s')
+ def test_handles_zero_speed(self):
+ self.w.update({ 'done': 0, 'total': 100 }, 999)
+ self.w.get_time = lambda: 5.0
+ self.w.update({ 'done': 0, 'total': 100 }, 999)
+ self.assertEqual(str(self.w), '--h--m--s')