Coverage for tests/output/formatting/test_bytes.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-09 12:09 +0100

1from __future__ import annotations 

2 

3import pytest 

4 

5from harbor_cli.output.formatting.bytes import bytesize_str 

6 

7 

8@pytest.mark.parametrize( 

9 "b, expected", 

10 [ 

11 (0, "0.0B"), 

12 (1, "1.0B"), 

13 (1000, "1.0KB"), 

14 (1023, "1.0KB"), 

15 (1024, "1.0KB"), 

16 (1000 * 1000, "1.0MB"), 

17 (1000 * 1000 * 1000, "1.0GB"), 

18 (1000 * 1000 * 1000 * 1000, "1.0TB"), 

19 (1000 * 1000 * 1000 * 1000 * 1000, "1.0PB"), 

20 (1000 * 1000 * 1000 * 1000 * 1000 * 1000, "1.0EB"), 

21 (500000000000, "500.0GB"), 

22 ], 

23) 

24def test_bytesize_str_decimal(b: int, expected: str) -> None: 

25 """Test bytesize_str in decimal auto mode.""" 

26 assert bytesize_str(b, decimal=True) == expected 

27 

28 

29@pytest.mark.parametrize( 

30 "b, expected", 

31 [ 

32 (0, "0.0B"), 

33 (1, "1.0B"), 

34 (1023, "1023.0B"), 

35 (1024, "1.0KiB"), 

36 (1024 * 1024, "1.0MiB"), 

37 (1024 * 1024 * 1024, "1.0GiB"), 

38 (1024 * 1024 * 1024 * 1024, "1.0TiB"), 

39 (1024 * 1024 * 1024 * 1024 * 1024, "1.0PiB"), 

40 (1024 * 1024 * 1024 * 1024 * 1024 * 1024, "1.0EiB"), 

41 (500000000000, "465.7GiB"), 

42 ], 

43) 

44def test_bytesize_str_binary(b: int, expected: str) -> None: 

45 """Test bytesize_str in binary auto mode.""" 

46 assert bytesize_str(b, decimal=False) == expected