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

localstack / localstack / 18363705737

08 Oct 2025 07:39PM UTC coverage: 86.912% (+0.02%) from 86.893%
18363705737

push

github

web-flow
Fix Event Bridge input transformation of booleans (#13236)

6 of 6 new or added lines in 1 file covered. (100.0%)

145 existing lines in 8 files now uncovered.

67991 of 78230 relevant lines covered (86.91%)

0.87 hits per line

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

96.77
/localstack-core/localstack/utils/numbers.py
1
from typing import Any, Union
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) -> Union[int, float]:
1✔
29
    """Cast the string representation of the given object to a number (int or float), or raise ValueError."""
30
    try:
1✔
31
        return int(str(s))
1✔
32
    except ValueError:
1✔
33
        return float(str(s))
1✔
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✔
UNCOV
49
    return count
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc