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

rjfarmer / gfModParser / 18542693371

15 Oct 2025 09:07PM UTC coverage: 88.199% (-0.6%) from 88.811%
18542693371

push

github

rjfarmer
Fix string test

1009 of 1144 relevant lines covered (88.2%)

0.88 hits per line

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

63.0
/gfModParser/utils.py
1
# SPDX-License-Identifier: GPL-2.0+
2

3
import numpy as np
1✔
4
from packaging.version import Version
1✔
5
from typing import Any, Union
1✔
6

7
try:
1✔
8
    import pyquadp as pyq  # type: ignore[import-not-found]
1✔
9

10
    PYQ_IMPORTED = True
×
11
except ImportError:
1✔
12
    PYQ_IMPORTED = False
1✔
13

14

15
def gfortran_mod_map(version: Version) -> Version:
1✔
16
    """
17
    Map gfortran version to Mod file version
18
    """
19
    if version < Version("4.8.1"):
×
20
        return Version("9")
×
21
    elif version < Version("4.9.2"):
×
22
        return Version("10")
×
23
    elif version < Version("5.1.0"):
×
24
        return Version("12")
×
25
    elif version < Version("8.0.0"):
×
26
        return Version("14")
×
27
    elif version < Version("15.0.0"):
×
28
        return Version("15")
×
29
    elif version.major == 15:
×
30
        return Version("16")
×
31
    else:
32
        raise ValueError(f"Unknown gfortran version {version}")
×
33

34

35
def string_clean(string: str) -> str:
1✔
36
    if string is None:
1✔
37
        return ""
1✔
38
    if string.startswith("'") or string.startswith('"'):
1✔
39
        string = string[1:]
1✔
40
    if string.endswith("'") or string.endswith('"'):
1✔
41
        string = string[:-1]
1✔
42

43
    return string
1✔
44

45

46
def hextofloat(s: str, kind: int = 4) -> Union[float, np.double, "pyq.qfloat"]:
1✔
47
    # Given hex like parameter '0.12decde@9' returns 5065465344.0
48
    if "@" in s:
1✔
49
        man, e = s.split("@")
1✔
50
        exp = int(e)
1✔
51
    else:
52
        man = s
1✔
53
        exp = 0
1✔
54

55
    if kind == 16:
1✔
56
        if PYQ_IMPORTED:
×
57
            return pyq.qfloat.fromhex(man) * 16**exp
×
58
        else:
59
            raise ValueError("Please install pyQuadp to handle quad precision numbers")
×
60
    elif kind == 8:
1✔
61
        return np.double.fromhex(man) * 16**exp  # type: ignore[attr-defined]
1✔
62
    else:
63
        return float.fromhex(man) * 16**exp
1✔
64

65

66
def dtype(type, kind, len=-1) -> np.dtype:
1✔
67
    if type == "REAL":
1✔
68
        if kind == 4:
1✔
69
            return np.dtype(np.float32)
1✔
70
        elif kind == 8:
1✔
71
            return np.dtype(np.float64)
1✔
72
        elif kind == 16:
×
73
            return np.dtype(np.float128)
×
74
    elif type == "INTEGER":
1✔
75
        if kind == 4:
1✔
76
            return np.dtype(np.int32)
1✔
77
        elif kind == 8:
×
78
            return np.dtype(np.int64)
×
79
        elif kind == 16:
×
80
            return np.dtype(np.int128)
×
81
    elif type == "UNSIGNED":
1✔
82
        if kind == 4:
×
83
            return np.dtype(np.uint32)
×
84
        elif kind == 8:
×
85
            return np.dtype(np.uint64)
×
86
        elif kind == 16:
×
87
            return np.dtype(np.uint128)
×
88
    elif type == "CHARACTER":
1✔
89
        return np.dtype(f"S{len}")
1✔
90
    elif type == "COMPLEX":
1✔
91
        if kind == 4:
×
92
            return np.dtype(np.complex64)
×
93
        elif kind == 8:
×
94
            return np.dtype(np.complex128)
×
95
        elif kind == 16:
×
96
            return np.dtype(np.complex256)
×
97
    elif type == "LOGICAL":
1✔
98
        return np.dtype(np.int32)
1✔
99

100
    raise NotImplementedError(f"Type={type} kind={kind}")
×
101

102

103
def bracket_split(string) -> list[Any]:
1✔
104
    def _helper(substring):
1✔
105
        items = []
1✔
106
        tmp = []
1✔
107
        for item in substring:
1✔
108
            if item == "(":
1✔
109
                result, closeparen = _helper(substring)
1✔
110
                if not closeparen:
1✔
111
                    raise ValueError("Unbalanced parentheses")
×
112
                items.append(result)
1✔
113
            elif item == ")":
1✔
114
                t = "".join(tmp).strip()
1✔
115
                if len(t):
1✔
116
                    items.append(t)
1✔
117
                return items, True
1✔
118
            else:
119
                if item != " ":
1✔
120
                    tmp.append(item)
1✔
121
                else:
122
                    t = "".join(tmp).strip()
1✔
123
                    if len(t):
1✔
124
                        items.append(t)
1✔
125
                        tmp = []
1✔
126
        return items, False
1✔
127

128
    return _helper(iter(string))[0]
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