Coverage for src/local_deep_research/utilities/formatting.py: 100%
6 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-03 23:15 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-03 23:15 +0000
1"""Shared formatting utilities."""
4def human_size(size_bytes: float) -> str:
5 """Convert bytes to human-readable size string.
7 Args:
8 size_bytes: Size in bytes.
10 Returns:
11 Human-readable string like "247.0 MB" or "1.5 GB".
12 """
13 for unit in ("B", "KB", "MB", "GB", "TB", "PB"):
14 if abs(size_bytes) < 1024:
15 return f"{size_bytes:.1f} {unit}"
16 size_bytes /= 1024
17 return f"{size_bytes:.1f} EB"