Skip to content

Commit

Permalink
Add a few # pragma: no cover
Browse files Browse the repository at this point in the history
The flag code is never reached if the functions are used through
the Parser class
  • Loading branch information
hgrecco committed Nov 12, 2023
1 parent 8dc0259 commit f652202
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ omit =
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
@overload
# Have to re-enable the standard pragma
pragma: no cover

Expand Down
18 changes: 9 additions & 9 deletions stringparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def fmt_to_regex(fmt: str) -> REGEX2CONVERTER:

matched = _FMT.search(fmt)

if matched is None:
if matched is None: # pragma: no cover
raise ValueError(f"Could not parse the formatting string {fmt}")

(
Expand All @@ -137,13 +137,13 @@ def fmt_to_regex(fmt: str) -> REGEX2CONVERTER:

try:
reg, fun = _REG[ctype] # typing: ignore
except KeyError:
except KeyError: # pragma: no cover
raise ValueError("{} is not an valid type".format(ctype))

if alternate:
if ctype in ("o", "x", "X", "b"):
reg = "0" + ctype + reg
else:
else: # pragma: no cover
raise ValueError("Alternate form (#) not allowed in {} type".format(ctype))

if sign == "-" or sign is None:
Expand All @@ -152,7 +152,7 @@ def fmt_to_regex(fmt: str) -> REGEX2CONVERTER:
reg = "[-+]" + reg
elif sign == " ":
reg = "[- ]" + reg
else:
else: # pragma: no cover
raise ValueError("{} is not a valid sign".format(sign))

return reg, fun
Expand All @@ -177,7 +177,7 @@ def split_field_name(name: str) -> Generator[ITEM_ATTR, None, None]:
key = keyparts[0]

# Empty strings are not allowed as field names
if key == "":
if key == "": # pragma: no cover
raise ValueError("empty field name in {}".format(name))

# The first name in the sequence is used to index
Expand All @@ -193,7 +193,7 @@ def split_field_name(name: str) -> Generator[ITEM_ATTR, None, None]:
# the first part.
for key in keyparts[1:]:
endbracket = key.find("]")
if endbracket < 0 or endbracket != len(key) - 1:
if endbracket < 0 or endbracket != len(key) - 1: # pragma: no cover
raise ValueError("Invalid field syntax in {}".format(name))

# Strip off the closing bracket and try to coerce to int
Expand Down Expand Up @@ -234,19 +234,19 @@ def append_to_hierarchy(
"""
for typ_, name in field_parts:
if isinstance(bottom, dict):
if not typ_ == "item":
if not typ_ == "item": # pragma: no cover
raise ValueError("Incompatible {}, {}".format(typ_, name))
try:
bottom = bottom[name]
except KeyError:
bottom[name] = build_hierarchy(field_parts, top)

elif isinstance(bottom, Dummy):
if not typ_ == "attribute":
if not typ_ == "attribute": # pragma: no cover
raise ValueError("Incompatible {}, {}".format(typ_, name))
try:
bottom = getattr(bottom, name)
except AttributeError:
except AttributeError: # pragma: no cover
setattr(bottom, name, build_hierarchy(field_parts, top))
else:
raise ValueError("Incompatible {}, {}".format(typ_, name))
Expand Down

0 comments on commit f652202

Please sign in to comment.