diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-06-09 16:07:19 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-06-10 08:46:11 +0200 |
| commit | e065b293878b1e3ea56655aa9d33e87576cd77ff (patch) | |
| tree | 7d0bfab0a0280f7005ff26f955ad8eab2e6fe275 /tests/template_tests | |
| parent | dcb8f00d06eec99072b78d54215c9a3dc04acb99 (diff) | |
Refs #27804 -- Used subTest() in filesizeformat tests and HumanizeTests.
Diffstat (limited to 'tests/template_tests')
| -rw-r--r-- | tests/template_tests/filter_tests/test_filesizeformat.py | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/tests/template_tests/filter_tests/test_filesizeformat.py b/tests/template_tests/filter_tests/test_filesizeformat.py index 2e425af8ac..2d2aa6743c 100644 --- a/tests/template_tests/filter_tests/test_filesizeformat.py +++ b/tests/template_tests/filter_tests/test_filesizeformat.py @@ -6,38 +6,53 @@ from django.utils import translation class FunctionTests(SimpleTestCase): def test_formats(self): - self.assertEqual(filesizeformat(1023), '1023\xa0bytes') - self.assertEqual(filesizeformat(1024), '1.0\xa0KB') - self.assertEqual(filesizeformat(10 * 1024), '10.0\xa0KB') - self.assertEqual(filesizeformat(1024 * 1024 - 1), '1024.0\xa0KB') - self.assertEqual(filesizeformat(1024 * 1024), '1.0\xa0MB') - self.assertEqual(filesizeformat(1024 * 1024 * 50), '50.0\xa0MB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 - 1), '1024.0\xa0MB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024), '1.0\xa0GB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024), '1.0\xa0TB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024 * 1024), '1.0\xa0PB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024 * 1024 * 2000), '2000.0\xa0PB') - self.assertEqual(filesizeformat(complex(1, -1)), '0\xa0bytes') - self.assertEqual(filesizeformat(""), '0\xa0bytes') - self.assertEqual(filesizeformat("\N{GREEK SMALL LETTER ALPHA}"), '0\xa0bytes') + tests = [ + (1023, '1023\xa0bytes'), + (1024, '1.0\xa0KB'), + (10 * 1024, '10.0\xa0KB'), + (1024 * 1024 - 1, '1024.0\xa0KB'), + (1024 * 1024, '1.0\xa0MB'), + (1024 * 1024 * 50, '50.0\xa0MB'), + (1024 * 1024 * 1024 - 1, '1024.0\xa0MB'), + (1024 * 1024 * 1024, '1.0\xa0GB'), + (1024 * 1024 * 1024 * 1024, '1.0\xa0TB'), + (1024 * 1024 * 1024 * 1024 * 1024, '1.0\xa0PB'), + (1024 * 1024 * 1024 * 1024 * 1024 * 2000, '2000.0\xa0PB'), + (complex(1, -1), '0\xa0bytes'), + ('', '0\xa0bytes'), + ('\N{GREEK SMALL LETTER ALPHA}', '0\xa0bytes'), + ] + for value, expected in tests: + with self.subTest(value=value): + self.assertEqual(filesizeformat(value), expected) def test_localized_formats(self): + tests = [ + (1023, '1023\xa0Bytes'), + (1024, '1,0\xa0KB'), + (10 * 1024, '10,0\xa0KB'), + (1024 * 1024 - 1, '1024,0\xa0KB'), + (1024 * 1024, '1,0\xa0MB'), + (1024 * 1024 * 50, '50,0\xa0MB'), + (1024 * 1024 * 1024 - 1, '1024,0\xa0MB'), + (1024 * 1024 * 1024, '1,0\xa0GB'), + (1024 * 1024 * 1024 * 1024, '1,0\xa0TB'), + (1024 * 1024 * 1024 * 1024 * 1024, '1,0\xa0PB'), + (1024 * 1024 * 1024 * 1024 * 1024 * 2000, '2000,0\xa0PB'), + (complex(1, -1), '0\xa0Bytes'), + ('', '0\xa0Bytes'), + ('\N{GREEK SMALL LETTER ALPHA}', '0\xa0Bytes'), + ] with self.settings(USE_L10N=True), translation.override('de'): - self.assertEqual(filesizeformat(1023), '1023\xa0Bytes') - self.assertEqual(filesizeformat(1024), '1,0\xa0KB') - self.assertEqual(filesizeformat(10 * 1024), '10,0\xa0KB') - self.assertEqual(filesizeformat(1024 * 1024 - 1), '1024,0\xa0KB') - self.assertEqual(filesizeformat(1024 * 1024), '1,0\xa0MB') - self.assertEqual(filesizeformat(1024 * 1024 * 50), '50,0\xa0MB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 - 1), '1024,0\xa0MB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024), '1,0\xa0GB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024), '1,0\xa0TB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024 * 1024), '1,0\xa0PB') - self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024 * 1024 * 2000), '2000,0\xa0PB') - self.assertEqual(filesizeformat(complex(1, -1)), '0\xa0Bytes') - self.assertEqual(filesizeformat(""), '0\xa0Bytes') - self.assertEqual(filesizeformat("\N{GREEK SMALL LETTER ALPHA}"), '0\xa0Bytes') + for value, expected in tests: + with self.subTest(value=value): + self.assertEqual(filesizeformat(value), expected) def test_negative_numbers(self): - self.assertEqual(filesizeformat(-100), '-100\xa0bytes') - self.assertEqual(filesizeformat(-1024 * 1024 * 50), '-50.0\xa0MB') + tests = [ + (-100, '-100\xa0bytes'), + (-1024 * 1024 * 50, '-50.0\xa0MB'), + ] + for value, expected in tests: + with self.subTest(value=value): + self.assertEqual(filesizeformat(value), expected) |
