diff --git a/.coveragerc b/.coveragerc index cabc6a7..4c1aeb1 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 diff --git a/stringparser.py b/stringparser.py index 8c8b329..be0b1ab 100644 --- a/stringparser.py +++ b/stringparser.py @@ -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}") ( @@ -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: @@ -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 @@ -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 @@ -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 @@ -234,7 +234,7 @@ 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] @@ -242,11 +242,11 @@ def append_to_hierarchy( 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))