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

binbashar / leverage / 15472282000

05 Jun 2025 04:26PM UTC coverage: 61.435%. First build
15472282000

Pull #307

github

exequielrafaela
Add casting helpers and comprehensive tests
Pull Request #307: Implement typed argument casting

212 of 476 branches covered (44.54%)

Branch coverage included in aggregate %.

30 of 32 new or added lines in 3 files covered. (93.75%)

2630 of 4150 relevant lines covered (63.37%)

0.63 hits per line

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

93.33
/leverage/_casting.py
1
"""
2
Value casting utilities.
3
"""
4

5
from typing import Any
1✔
6

7
import yaml
1✔
8

9

10
def as_bool(value: str) -> Any:
1✔
11
    """Return the boolean representation of ``value`` if possible."""
12
    try:
1✔
13
        parsed = yaml.safe_load(value)
1✔
14
        if isinstance(parsed, bool):
1✔
15
            return parsed
1✔
NEW
16
    except yaml.YAMLError:
×
NEW
17
        pass
×
18
    return value
1✔
19

20

21
def as_int(value: str) -> Any:
1✔
22
    """Return the integer representation of ``value`` if possible."""
23
    try:
1✔
24
        return int(value)
1✔
25
    except ValueError:
1✔
26
        return value
1✔
27

28

29
def as_float(value: str) -> Any:
1✔
30
    """Return the float representation of ``value`` if possible."""
31
    try:
1✔
32
        return float(value)
1✔
33
    except ValueError:
1✔
34
        return value
1✔
35

36

37
def cast_value(value: str) -> Any:
1✔
38
    """Try to cast ``value`` to bool, int or float using the helper functions
39
    :func:`as_bool`, :func:`as_int` and :func:`as_float`.
40

41
    Args:
42
        value (str): Value to cast.
43

44
    Returns:
45
        Any: The value converted to its apparent type or the original string.
46
    """
47
    value = as_bool(value)
1✔
48
    if isinstance(value, str):
1✔
49
        value = as_int(value)
1✔
50
    if isinstance(value, str):
1✔
51
        value = as_float(value)
1✔
52

53
    return value
1✔
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