improve test coverage

This commit is contained in:
Manuel Barkhau 2020-10-04 12:10:38 +00:00
parent d23689634c
commit 6b1a3e45d3
8 changed files with 118 additions and 162 deletions

View file

@ -303,19 +303,24 @@ def show(verbose: int = 0, fetch: bool = True) -> None:
click.echo(f"PEP440 : {cfg.pep440_version}")
def _colored_diff_lines(diff: str) -> typ.Iterable[str]:
for line in diff.splitlines():
if line.startswith("+++") or line.startswith("---"):
yield line
elif line.startswith("+"):
yield "\u001b[32m" + line + "\u001b[0m"
elif line.startswith("-"):
yield "\u001b[31m" + line + "\u001b[0m"
elif line.startswith("@"):
yield "\u001b[36m" + line + "\u001b[0m"
else:
yield line
def _print_diff_str(diff: str) -> None:
colored_diff = "\n".join(_colored_diff_lines(diff))
if sys.stdout.isatty():
for line in diff.splitlines():
if line.startswith("+++") or line.startswith("---"):
click.echo(line)
elif line.startswith("+"):
click.echo("\u001b[32m" + line + "\u001b[0m")
elif line.startswith("-"):
click.echo("\u001b[31m" + line + "\u001b[0m")
elif line.startswith("@"):
click.echo("\u001b[36m" + line + "\u001b[0m")
else:
click.echo(line)
click.echo(colored_diff)
else:
click.echo(diff)
@ -331,11 +336,6 @@ def _print_diff(cfg: config.Config, new_version: str) -> None:
except rewrite.NoPatternMatch as ex:
logger.error(str(ex))
sys.exit(1)
except Exception as ex:
# pylint:disable=broad-except; Mostly we expect IOError here, but
# could be other things and there's no option to recover anyway.
logger.error(str(ex), exc_info=True)
sys.exit(1)
def incr_dispatch(
@ -417,10 +417,6 @@ def _bump(
except rewrite.NoPatternMatch as ex:
logger.error(str(ex))
sys.exit(1)
except Exception as ex:
# TODO (mb 2020-09-18): Investigate error messages
logger.error(str(ex))
sys.exit(1)
if vcs_api:
vcs.commit(cfg, vcs_api, filepaths, new_version, commit_message)

View file

@ -26,8 +26,6 @@ def update_cfg_from_vcs(cfg: config.Config, all_tags: typ.List[str]) -> config.C
logger.debug("no vcs tags found")
return cfg
# TODO (mb 2020-10-03): This codepath is not tested since switch to
# v2 as default version_pattern.
version_tags.sort(reverse=True)
_debug_tags = ", ".join(version_tags[:3])
logger.debug(f"found tags: {_debug_tags} ... ({len(version_tags)} in total)")

View file

@ -141,6 +141,7 @@ def _parse_version_info(field_values: FieldValues) -> version.V2VersionInfo:
>>> (vinfo.year_y, vinfo.week_w, vinfo.year_y, vinfo.week_u,vinfo.year_g, vinfo.week_v)
(2021, 0, 2021, 1, 2020, 53)
"""
# pylint:disable=dangerous-default-value; We don't mutate args, mypy would fail if we did.
for key in field_values:
assert key in VALID_FIELD_KEYS, key

View file

@ -77,9 +77,7 @@ class VCSAPI:
cmd_parts = shlex.split(cmd_str)
output_data: bytes = sp.check_output(cmd_parts, env=env, stderr=sp.STDOUT)
# TODO (mb 2018-11-15): Detect encoding of output? Use chardet?
_encoding = "utf-8"
return output_data.decode(_encoding)
return output_data.decode("utf-8")
@property
def is_usable(self) -> bool: