use click.echo(), not print() for better testing

This commit is contained in:
Manuel Barkhau 2019-07-09 10:05:57 +02:00
parent ae8baa541e
commit a3d1a559b8
2 changed files with 13 additions and 18 deletions

View file

@ -113,8 +113,8 @@ def test(
pep440_version = version.to_pep440(new_version) pep440_version = version.to_pep440(new_version)
print("New Version:", new_version) click.echo(f"New Version: {new_version}")
print("PEP440 :", pep440_version) click.echo(f"PEP440 : {pep440_version}")
def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config: def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
@ -164,8 +164,8 @@ def show(verbose: int = 0, fetch: bool = True) -> None:
cfg = _update_cfg_from_vcs(cfg, fetch=fetch) cfg = _update_cfg_from_vcs(cfg, fetch=fetch)
print(f"Current Version: {cfg.current_version}") click.echo(f"Current Version: {cfg.current_version}")
print(f"PEP440 : {cfg.pep440_version}") click.echo(f"PEP440 : {cfg.pep440_version}")
@cli.command() @cli.command()
@ -185,9 +185,9 @@ def init(verbose: int = 0, dry: bool = False) -> None:
sys.exit(1) sys.exit(1)
if dry: if dry:
print(f"Exiting because of '--dry'. Would have written to {ctx.config_filepath}:") click.echo(f"Exiting because of '--dry'. Would have written to {ctx.config_filepath}:")
cfg_text: str = config.default_config(ctx) cfg_text: str = config.default_config(ctx)
print("\n " + "\n ".join(cfg_text.splitlines())) click.echo("\n " + "\n ".join(cfg_text.splitlines()))
sys.exit(0) sys.exit(0)
config.write_content(ctx) config.write_content(ctx)
@ -267,17 +267,17 @@ def _print_diff(cfg: config.Config, new_version: str) -> None:
if sys.stdout.isatty(): if sys.stdout.isatty():
for line in diff.splitlines(): for line in diff.splitlines():
if line.startswith("+++") or line.startswith("---"): if line.startswith("+++") or line.startswith("---"):
print(line) click.echo(line)
elif line.startswith("+"): elif line.startswith("+"):
print("\u001b[32m" + line + "\u001b[0m") click.echo("\u001b[32m" + line + "\u001b[0m")
elif line.startswith("-"): elif line.startswith("-"):
print("\u001b[31m" + line + "\u001b[0m") click.echo("\u001b[31m" + line + "\u001b[0m")
elif line.startswith("@"): elif line.startswith("@"):
print("\u001b[36m" + line + "\u001b[0m") click.echo("\u001b[36m" + line + "\u001b[0m")
else: else:
print(line) click.echo(line)
else: else:
print(diff) click.echo(diff)
def _try_print_diff(cfg: config.Config, new_version: str) -> None: def _try_print_diff(cfg: config.Config, new_version: str) -> None:

View file

@ -190,7 +190,7 @@ def test_nocfg(runner, caplog):
) )
def test_novcs_nocfg_init(runner, caplog, capsys): def test_novcs_nocfg_init(runner, caplog):
_add_project_files("README.md") _add_project_files("README.md")
# dry mode test # dry mode test
result = runner.invoke(cli.cli, ['init', "-vv", "--dry"]) result = runner.invoke(cli.cli, ['init', "-vv", "--dry"])
@ -203,11 +203,6 @@ def test_novcs_nocfg_init(runner, caplog, capsys):
assert log.levelname == 'WARNING' assert log.levelname == 'WARNING'
assert "File not found" in log.message assert "File not found" in log.message
# print("moep")
# captured = capsys.readouterr()
# assert not captured.err
# assert "Would have written to pycalver.toml:" in captured.out
# non dry mode # non dry mode
result = runner.invoke(cli.cli, ['init', "-vv"]) result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0 assert result.exit_code == 0