Example #1
0
 def test_max(self):
     # Test the max range for "convert" for errors.
     prefix = ('geop', 'bronto', 'yotta', 'zetta', 'exa',
               'peta', 'tera', 'giga', 'mega', 'kilo', '')
     suffix = map(lambda s: '1023 ' + (s + 'bytes').capitalize(), prefix)
     self.assertEqual(byt2str.convert((1 << 110) - 1), ', '.join(suffix))
     with self.assertRaises(AssertionError):
         byt2str.convert(1 << 110)
Example #2
0
 def test_max(self):
     # Test the max range for "convert" for errors.
     prefix = ('geop', 'bronto', 'yotta', 'zetta', 'exa',
               'peta', 'tera', 'giga', 'mega', 'kilo', '')
     suffix = map(lambda s: '1023 ' + (s + 'bytes').capitalize(), prefix)
     self.assertEqual(byt2str.convert((1 << 110) - 1), ', '.join(suffix))
     with self.assertRaises(AssertionError):
         byt2str.convert(1 << 110)
Example #3
0
 def test_min(self):
     # Check that the "convert" min range is correct.
     self.assertEqual(byt2str.convert(1), '1 Byte')
     with self.assertRaises(AssertionError):
         byt2str.convert(0)
Example #4
0
 def test_binary(self):
     # Observe if two non-contiguous numbers render well.
     string = byt2str.convert(789 * (1 << 30) + (1 << 10))
     self.assertEqual(string, '789 Gigabytes, 1 Kilobyte')
Example #5
0
 def test_ternary(self):
     # Ensure that three separate components validate.
     string = byt2str.convert((1 << 40) + (1 << 20) * 123 + 456)
     self.assertEqual(string, '1 Terabyte, 123 Megabytes, 456 Bytes')
Example #6
0
 def test_min(self):
     # Check that the "convert" min range is correct.
     self.assertEqual(byt2str.convert(1), '1 Byte')
     with self.assertRaises(AssertionError):
         byt2str.convert(0)
Example #7
0
 def test_binary(self):
     # Observe if two non-contiguous numbers render well.
     string = byt2str.convert(789 * (1 << 30) + (1 << 10))
     self.assertEqual(string, '789 Gigabytes, 1 Kilobyte')
Example #8
0
 def test_ternary(self):
     # Ensure that three separate components validate.
     string = byt2str.convert((1 << 40) + (1 << 20) * 123 + 456)
     self.assertEqual(string, '1 Terabyte, 123 Megabytes, 456 Bytes')