diff --git a/src/rez/tests/test_utils_formatting.py b/src/rez/tests/test_utils_formatting.py new file mode 100644 index 000000000..43ad97345 --- /dev/null +++ b/src/rez/tests/test_utils_formatting.py @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright Contributors to the Rez Project + + +""" +unit tests for 'utils.formatting' module +""" +from rez.tests.util import TestBase +from rez.utils import formatting + + +class TestFormatting(TestBase): + def test_readable_units(self): + readable_units = formatting._readable_units( + 0, + formatting.memory_divs + ) + self.assertEqual(readable_units, "0 bytes") + + readable_units = formatting._readable_units( + 1024, + formatting.memory_divs + ) + self.assertEqual(readable_units, "1 Kb") + + readable_units = formatting._readable_units( + 1200, + formatting.memory_divs + ) + self.assertEqual(readable_units, "1.2 Kb") + + readable_units = formatting._readable_units( + -30000, + formatting.memory_divs + ) + self.assertEqual(readable_units, "-29 Kb") diff --git a/src/rez/utils/formatting.py b/src/rez/utils/formatting.py index 87d428909..aa8aad41c 100644 --- a/src/rez/utils/formatting.py +++ b/src/rez/utils/formatting.py @@ -364,7 +364,9 @@ def readable_time_duration(secs): def readable_memory_size(bytes_): - """Convert number of bytes into human readable form, eg '1.2 Kb'. + """Convert number of bytes into human-readable form. + + This method rounds to 1 decimal place eg '1.2 Kb'. """ return _readable_units(bytes_, memory_divs)