diff --git a/pygeoapi/util.py b/pygeoapi/util.py index b60e187a0..4dce4e997 100644 --- a/pygeoapi/util.py +++ b/pygeoapi/util.py @@ -342,7 +342,7 @@ def human_size(nbytes: int) -> str: i += 1 if suffixes[i] == 'K': - f = str(int(nbytes)).rstrip('0').rstrip('.') + f = str(int(nbytes)) elif suffixes[i] == 'B': return nbytes else: diff --git a/tests/other/test_util.py b/tests/other/test_util.py index 7cb321019..2a471e21c 100644 --- a/tests/other/test_util.py +++ b/tests/other/test_util.py @@ -170,6 +170,21 @@ def test_json_serial(): util.json_serial('foo') +@pytest.mark.parametrize('nbytes,expected', [ + (500, 500), + (1024, '1K'), + (1536, '1K'), + (10240, '10K'), + (102400, '100K'), + (1048576, '1M'), + (1572864, '1.5M'), + (10485760, '10M'), + (1073741824, '1G'), +]) +def test_human_size(nbytes, expected): + assert util.human_size(nbytes) == expected + + def test_mimetype(): assert util.get_mimetype('file.xml') == 'application/xml' assert util.get_mimetype('file.yml') == 'text/plain'