# Copyright 2010 Lars Wirzenius # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import unittest import ttystatus class ByteSpeedTests(unittest.TestCase): def setUp(self): self.w = ttystatus.ByteSpeed('foo') def test_is_not_static_width(self): self.assertFalse(self.w.static_width) def test_formats_zero_speed_without_update(self): self.assertEqual(self.w.render(0), '0 B/s') def test_formats_zero_bytes_correctly(self): self.w.now = lambda: 1 self.w.update({'foo': 0}) self.w.now = lambda: 2 self.w.update({'foo': 0}) self.assertEqual(self.w.render(0), '0 B/s') def test_formats_one_byte_per_second_correctly(self): self.w.now = lambda: 1 self.w.update({'foo': 0}) self.w.now = lambda: 2 self.w.update({'foo': 1}) self.assertEqual(self.w.render(0), '1 B/s') def test_formats_ten_bytes_per_second_correctly(self): self.w.now = lambda: 1 self.w.update({'foo': 0}) self.w.now = lambda: 11 self.w.update({'foo': 100}) self.assertEqual(self.w.render(0), '10 B/s') def test_formats_ten_tibs_per_second_correctly(self): self.w.now = lambda: 1 self.w.update({'foo': 0}) self.w.now = lambda: 2 self.w.update({'foo': 10 * 1024 ** 4}) self.assertEqual(self.w.render(0), '10.00 TiB/s') def test_keeps_only_two_data_points_with_infinite_duration(self): for when in range(100): self.w.now = lambda: when self.w.update({'foo': 0}) self.assertEqual(self.w.render(0), '0 B/s') def test_shows_current_speed_when_requested(self): items = [ (0, 0), (1, 1024), (10, 1024), (11, 1024), ] w = ttystatus.ByteSpeed('foo', duration=5) for when, num_bytes in items: w.now = lambda: when w.update({'foo': num_bytes}) self.assertEqual(w.render(0), '0 B/s')
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__init__.py | File | 1.29 KB | 0644 |
|
__init__.pyc | File | 1.25 KB | 0644 |
|
area.py | File | 3.41 KB | 0644 |
|
area.pyc | File | 3.9 KB | 0644 |
|
bytesize.py | File | 1.39 KB | 0644 |
|
bytesize.pyc | File | 1.37 KB | 0644 |
|
bytesize_tests.py | File | 1.95 KB | 0644 |
|
bytesize_tests.pyc | File | 3.11 KB | 0644 |
|
bytespeed.py | File | 2.26 KB | 0644 |
|
bytespeed.pyc | File | 2.17 KB | 0644 |
|
bytespeed_tests.py | File | 2.54 KB | 0644 |
|
bytespeed_tests.pyc | File | 4.77 KB | 0644 |
|
counter.py | File | 1.1 KB | 0644 |
|
counter.pyc | File | 1.13 KB | 0644 |
|
counter_tests.py | File | 1.42 KB | 0644 |
|
counter_tests.pyc | File | 1.97 KB | 0644 |
|
elapsed.py | File | 1.35 KB | 0644 |
|
elapsed.pyc | File | 1.43 KB | 0644 |
|
elapsed_tests.py | File | 1.38 KB | 0644 |
|
elapsed_tests.pyc | File | 2.14 KB | 0644 |
|
fmt.py | File | 2.15 KB | 0644 |
|
fmt.pyc | File | 1.74 KB | 0644 |
|
fmt_tests.py | File | 2.39 KB | 0644 |
|
fmt_tests.pyc | File | 2.78 KB | 0644 |
|
index.py | File | 1.25 KB | 0644 |
|
index.pyc | File | 1.24 KB | 0644 |
|
index_tests.py | File | 1.27 KB | 0644 |
|
index_tests.pyc | File | 1.7 KB | 0644 |
|
integer.py | File | 1.06 KB | 0644 |
|
integer.pyc | File | 1.12 KB | 0644 |
|
integer_tests.py | File | 1.22 KB | 0644 |
|
integer_tests.pyc | File | 1.64 KB | 0644 |
|
literal.py | File | 877 B | 0644 |
|
literal.pyc | File | 791 B | 0644 |
|
literal_tests.py | File | 984 B | 0644 |
|
literal_tests.pyc | File | 1.09 KB | 0644 |
|
messager.py | File | 4.52 KB | 0644 |
|
messager.pyc | File | 4.61 KB | 0644 |
|
pathname.py | File | 1.07 KB | 0644 |
|
pathname.pyc | File | 1.12 KB | 0644 |
|
pathname_tests.py | File | 1.36 KB | 0644 |
|
pathname_tests.pyc | File | 1.92 KB | 0644 |
|
percent.py | File | 1.4 KB | 0644 |
|
percent.pyc | File | 1.35 KB | 0644 |
|
percent_tests.py | File | 1.42 KB | 0644 |
|
percent_tests.pyc | File | 2 KB | 0644 |
|
progressbar.py | File | 1.46 KB | 0644 |
|
progressbar.pyc | File | 1.41 KB | 0644 |
|
progressbar_tests.py | File | 2.33 KB | 0644 |
|
progressbar_tests.pyc | File | 3.77 KB | 0644 |
|
remtime.py | File | 1.89 KB | 0644 |
|
remtime.pyc | File | 1.81 KB | 0644 |
|
remtime_tests.py | File | 2.08 KB | 0644 |
|
remtime_tests.pyc | File | 3.26 KB | 0644 |
|
speed.py | File | 1.94 KB | 0644 |
|
speed.pyc | File | 1.83 KB | 0644 |
|
speed_tests.py | File | 1001 B | 0644 |
|
speed_tests.pyc | File | 1.1 KB | 0644 |
|
status.py | File | 6.15 KB | 0644 |
|
status.pyc | File | 8.2 KB | 0644 |
|
status_tests.py | File | 5.18 KB | 0644 |
|
status_tests.pyc | File | 8.97 KB | 0644 |
|
string.py | File | 998 B | 0644 |
|
string.pyc | File | 1.02 KB | 0644 |
|
string_tests.py | File | 1.2 KB | 0644 |
|
string_tests.pyc | File | 1.61 KB | 0644 |
|
tty.py | File | 2.87 KB | 0644 |
|
tty.pyc | File | 3.33 KB | 0644 |
|
version.py | File | 48 B | 0644 |
|
version.pyc | File | 225 B | 0644 |
|
widget.py | File | 2.22 KB | 0644 |
|
widget.pyc | File | 2.13 KB | 0644 |
|