Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Gattis <[email protected]>
  • Loading branch information
BryceGattis committed Mar 29, 2024
1 parent 0716cd8 commit a24403c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/rez/tests/test_utils_formatting.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 3 additions & 1 deletion src/rez/utils/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a24403c

Please sign in to comment.