diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-07-01 09:05:26 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-07-01 09:05:26 +1200 |
commit | 9aee5a84d88e6f027c516311c763d1571e53317b (patch) | |
tree | a3ac190a33c3a80ffc7e8726d525a2b71e0d8cac | |
parent | d5a5ffe6754f04cc9c315fae585ca967ed1f4316 (diff) | |
download | python-ttystatus-9aee5a84d88e6f027c516311c763d1571e53317b.tar.gz |
Handle empty string for done, total values.
-rw-r--r-- | ttystatus/remtime.py | 4 | ||||
-rw-r--r-- | ttystatus/remtime_tests.py | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/ttystatus/remtime.py b/ttystatus/remtime.py index fa83030..b1cffe5 100644 --- a/ttystatus/remtime.py +++ b/ttystatus/remtime.py @@ -52,8 +52,8 @@ class RemainingTime(ttystatus.Widget): self.started = self.get_time() duration = self.get_time() - self.started if duration >= 1.0: - done = float(master[self.done_name]) - total = float(master[self.total_name]) + done = float(master.get(self.done_name, 0) or 0) + total = float(master.get(self.total_name, 0) or 0) speed = done / duration remaining = total - done if speed > 0: diff --git a/ttystatus/remtime_tests.py b/ttystatus/remtime_tests.py index 5ddd8bb..6c6f452 100644 --- a/ttystatus/remtime_tests.py +++ b/ttystatus/remtime_tests.py @@ -45,3 +45,10 @@ class RemainingTimeTests(unittest.TestCase): self.w.get_time = lambda: 5.0 self.w.update({ 'done': 0, 'total': 100 }, 999) self.assertEqual(str(self.w), '--h--m--s') + + def test_handles_empty_strings_for_done_and_total(self): + self.w.update({ 'done': '', 'total': '' }, 999) + self.w.get_time = lambda: 5.0 + self.w.update({ 'done': '', 'total': '' }, 999) + self.assertEqual(str(self.w), '--h--m--s') + |