Coverage for src / local_deep_research / utilities / formatting.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-14 23:55 +0000

1"""Shared formatting utilities.""" 

2 

3 

4def human_size(size_bytes: float) -> str: 

5 """Convert bytes to human-readable size string. 

6 

7 Args: 

8 size_bytes: Size in bytes. 

9 

10 Returns: 

11 Human-readable string like "247.0 MB" or "1.5 GB". 

12 """ 

13 for unit in ("B", "KB", "MB", "GB"): 

14 if abs(size_bytes) < 1024: 

15 return f"{size_bytes:.1f} {unit}" 

16 size_bytes /= 1024 

17 return f"{size_bytes:.1f} TB"