From f9099c91ae9e615eb5c7150f4f20520d966967a4 Mon Sep 17 00:00:00 2001 From: Goryudyuma Date: Mon, 3 Jun 2019 21:57:07 +0900 Subject: [PATCH 1/3] fix: The correct number is displayed Signed-off-by: Kei Matsumoto --- compose/cli/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose/cli/utils.py b/compose/cli/utils.py index 4cc055cc9..bd06beef8 100644 --- a/compose/cli/utils.py +++ b/compose/cli/utils.py @@ -137,7 +137,7 @@ def human_readable_file_size(size): if order >= len(suffixes): order = len(suffixes) - 1 - return '{0:.3g} {1}'.format( + return '{0:.4g} {1}'.format( size / float(1 << (order * 10)), suffixes[order] ) From 75d41edb94d5dda7b5b7c476c1ba248d6e838755 Mon Sep 17 00:00:00 2001 From: Kei Matsumoto Date: Wed, 10 Jul 2019 12:10:19 +0900 Subject: [PATCH 2/3] fix: Add test Signed-off-by: Kei Matsumoto --- tests/unit/cli/utils_test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/cli/utils_test.py b/tests/unit/cli/utils_test.py index 26524ff37..25912f77a 100644 --- a/tests/unit/cli/utils_test.py +++ b/tests/unit/cli/utils_test.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import unittest from compose.utils import unquote_path +from compose.cli.utils import human_readable_file_size class UnquotePathTest(unittest.TestCase): @@ -21,3 +22,14 @@ class UnquotePathTest(unittest.TestCase): assert unquote_path('""hello""') == '"hello"' assert unquote_path('"hel"lo"') == 'hel"lo' assert unquote_path('"hello""') == 'hello"' + + +class HumanReadableFileSizeTest(unittest.TestCase): + def test_100b(self): + assert human_readable_file_size(100) == '100 B' + + def test_1kb(self): + assert human_readable_file_size(1024) == '1 kB' + + def test_1023b(self): + assert human_readable_file_size(1023) == '1023 B' From 59491c7d775b8a2f86532aa37fd4cc72b2b9459d Mon Sep 17 00:00:00 2001 From: Goryudyuma Date: Sun, 14 Jul 2019 03:24:18 +0900 Subject: [PATCH 3/3] add: test for units Signed-off-by: Kei Matsumoto --- tests/unit/cli/utils_test.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unit/cli/utils_test.py b/tests/unit/cli/utils_test.py index 25912f77a..b340fb947 100644 --- a/tests/unit/cli/utils_test.py +++ b/tests/unit/cli/utils_test.py @@ -3,8 +3,8 @@ from __future__ import unicode_literals import unittest -from compose.utils import unquote_path from compose.cli.utils import human_readable_file_size +from compose.utils import unquote_path class UnquotePathTest(unittest.TestCase): @@ -33,3 +33,12 @@ class HumanReadableFileSizeTest(unittest.TestCase): def test_1023b(self): assert human_readable_file_size(1023) == '1023 B' + + def test_units(self): + assert human_readable_file_size((2 ** 10) ** 0) == '1 B' + assert human_readable_file_size((2 ** 10) ** 1) == '1 kB' + assert human_readable_file_size((2 ** 10) ** 2) == '1 MB' + assert human_readable_file_size((2 ** 10) ** 3) == '1 GB' + assert human_readable_file_size((2 ** 10) ** 4) == '1 TB' + assert human_readable_file_size((2 ** 10) ** 5) == '1 PB' + assert human_readable_file_size((2 ** 10) ** 6) == '1 EB'