From dca030a075d2a1b12f8ca902ffb44fa1eeb6b718 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 12 May 2023 23:45:25 +0200 Subject: add unit tests for util.human_size --- tests/unit/test_util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/unit/test_util.py') diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 1a56911..6dc8e7d 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -88,6 +88,22 @@ def test_tour_metadata(gpx_file): def test_mps_to_kph(mps, kph): assert util.mps_to_kph(mps) == pytest.approx(kph, 0.1) +@pytest.mark.parametrize('num_bytes, expected', [ + (1, '1 B'), + (1023, '1023 B'), + (1024, '1.0 KiB'), + (1536, '1.5 KiB'), + (1024 ** 2, '1.0 MiB'), + (1024 ** 3, '1.0 GiB'), + (0, '0 B'), + # Negative sizes in itself are a bit weird, but they make sense as the + # difference between two size values, so they should still work. + (-1, '-1 B'), + (-1024, '-1.0 KiB'), +]) +def test_human_size(num_bytes, expected): + assert util.human_size(num_bytes) == expected + def test_tile_url(app_request): route_url = util.tile_url(app_request, "tile-proxy", provider="bobby") -- cgit v1.2.3