• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 22709357475

05 Mar 2026 08:35AM UTC coverage: 59.732% (-27.2%) from 86.974%
22709357475

Pull #13880

github

web-flow
Merge 28fcab93c into 710618057
Pull Request #13880: Firehose: Replace TaggingService

12 of 12 new or added lines in 2 files covered. (100.0%)

20464 existing lines in 510 files now uncovered.

45290 of 75822 relevant lines covered (59.73%)

0.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/localstack-core/localstack/utils/numbers.py
1
from typing import Any
1✔
2

3

4
def format_number(number: float, decimals: int = 2):
1✔
5
    # Note: interestingly, f"{number:.3g}" seems to yield incorrect results in some cases.
6
    # The logic below seems to be the most stable/reliable.
7
    result = f"{number:.{decimals}f}"
1✔
8
    if "." in result:
1✔
9
        result = result.rstrip("0").rstrip(".")
1✔
10
    return result
1✔
11

12

13
def is_number(s: Any) -> bool:
1✔
14
    # booleans inherit from int
15
    #
16
    # >>> a.__class__.__mro__
17
    # (<class 'bool'>, <class 'int'>, <class 'object'>)
18
    if s is False or s is True:
1✔
19
        return False
1✔
20

21
    try:
1✔
22
        float(s)  # for int, long and float
1✔
23
        return True
1✔
24
    except (TypeError, ValueError):
1✔
25
        return False
1✔
26

27

28
def to_number(s: Any) -> int | float:
1✔
29
    """Cast the string representation of the given object to a number (int or float), or raise ValueError."""
UNCOV
30
    try:
×
UNCOV
31
        return int(str(s))
×
UNCOV
32
    except ValueError:
×
UNCOV
33
        return float(str(s))
×
34

35

36
def format_bytes(count: float, default: str = "n/a"):
1✔
37
    """Format a bytes number as a human-readable unit, e.g., 1.3GB or 21.53MB"""
38
    if not is_number(count):
1✔
39
        return default
1✔
40
    cnt = float(count)
1✔
41
    if cnt < 0:
1✔
42
        return default
1✔
43
    units = ("B", "KB", "MB", "GB", "TB")
1✔
44
    for unit in units:
1✔
45
        if cnt < 1000 or unit == units[-1]:
1✔
46
            # FIXME: will return '1e+03TB' for 1000TB
47
            return f"{format_number(cnt, decimals=3)}{unit}"
1✔
48
        cnt = cnt / 1000.0
1✔
49
    return count
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc