Coverage for src/types/humanize.py: 14.29%

21 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-21 21:33 +0000

1#!/usr/bin/env python3 

2 

3# Humanize class, pylint: disable=too-few-public-methods 

4class Humanize: 

5 

6 # Size 

7 @staticmethod 

8 def size(value_in_bytes: int) -> str: 

9 

10 # Variables 

11 unit: str = 'B' 

12 value: int = value_in_bytes 

13 

14 # Return bytes string 

15 if value < 1024: 

16 return f"{value} {unit}" 

17 

18 # Return kilobytes string 

19 value = int(value / 1024) 

20 if value < 1024: 

21 return f"{value} K{unit}" 

22 

23 # Return megabytes string 

24 value = int(value / 1024) 

25 if value < 1024: 

26 return f"{value} M{unit}" 

27 

28 # Return gigabytes string 

29 value = int(value / 1024) 

30 if value < 1024: 

31 return f"{value} G{unit}" 

32 

33 # Return terabytes string 

34 value = int(value / 1024) 

35 if value < 1024: 

36 return f"{value} T{unit}" 

37 

38 # Return petabytes string 

39 value = int(value / 1024) 

40 return f"{value} P{unit}"