diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-04-15 19:35:56 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-04-15 19:35:56 +0100 |
commit | 394d6f5401cd79eb7b1624d23f3d8f4804144c78 (patch) | |
tree | 7861532a671a3c5e629e8242bc607648826aef85 /ttystatus/bytesize_tests.py | |
parent | 1623d3599bd057677158bfd2167798585d2afc44 (diff) | |
parent | 1a4675e03b42fcf276cf6a160480010cb36ca88c (diff) | |
download | python-ttystatus-394d6f5401cd79eb7b1624d23f3d8f4804144c78.tar.gz |
Fix a lot of rendering bugs by fixing internal abstration
Previously, we told update() how much width there was, but that
meant update() also had to render. That was slow. Then we fixed
that by only updating when it was time to update the display,
but that obviously doesn't work either. And when I say obviously,
I didn't think of it at the time. Now, this should work, since
we always update the values, so counters etc get incremented
correctly, but then only do the actual rendering when it's actually
time to actually write actual text to actual output. Actually.
Diffstat (limited to 'ttystatus/bytesize_tests.py')
-rw-r--r-- | ttystatus/bytesize_tests.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/ttystatus/bytesize_tests.py b/ttystatus/bytesize_tests.py index 11958f4..15a0ff5 100644 --- a/ttystatus/bytesize_tests.py +++ b/ttystatus/bytesize_tests.py @@ -24,34 +24,37 @@ class ByteSizeTests(unittest.TestCase): def setUp(self): self.w = ttystatus.ByteSize('foo') + def test_is_not_static_width(self): + self.assertFalse(self.w.static_width) + def test_formats_zero_bytes_without_update(self): - self.assertEqual(str(self.w), '0 B') + self.assertEqual(self.w.render(0), '0 B') def test_formats_zero_bytes_correctly(self): - self.w.update({ 'foo': 0 }, 999) - self.assertEqual(str(self.w), '0 B') + self.w.update({ 'foo': 0 }) + self.assertEqual(self.w.render(0), '0 B') def test_formats_one_bytes_correctly(self): - self.w.update({ 'foo': 1 }, 999) - self.assertEqual(str(self.w), '1 B') + self.w.update({ 'foo': 1 }) + self.assertEqual(self.w.render(0), '1 B') def test_formats_1023_bytes_correctly(self): - self.w.update({ 'foo': 1023 }, 999) - self.assertEqual(str(self.w), '1023 B') + self.w.update({ 'foo': 1023 }) + self.assertEqual(self.w.render(0), '1023 B') def test_formats_1024_bytes_correctly(self): - self.w.update({ 'foo': 1024 }, 999) - self.assertEqual(str(self.w), '1.0 KiB') + self.w.update({ 'foo': 1024 }) + self.assertEqual(self.w.render(0), '1.0 KiB') def test_formats_1_MiB_bytes_correctly(self): - self.w.update({ 'foo': 1024**2 }, 999) - self.assertEqual(str(self.w), '1.00 MiB') + self.w.update({ 'foo': 1024**2 }) + self.assertEqual(self.w.render(0), '1.00 MiB') def test_formats_1_GiB_bytes_correctly(self): - self.w.update({ 'foo': 1024**3 }, 999) - self.assertEqual(str(self.w), '1.00 GiB') + self.w.update({ 'foo': 1024**3 }) + self.assertEqual(self.w.render(0), '1.00 GiB') def test_formats_1_TiB_bytes_correctly(self): - self.w.update({ 'foo': 1024**4 }, 999) - self.assertEqual(str(self.w), '1.00 TiB') + self.w.update({ 'foo': 1024**4 }) + self.assertEqual(self.w.render(0), '1.00 TiB') |