From 222765eacf7cd956ca1b557b905e65b851abbeaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 18 Jan 2020 19:50:57 +0100 Subject: [PATCH] :white_check_mark: Fix tests using binary config files --- .../test_file/test_tutorial001.py | 5 ++--- .../test_file/test_tutorial002.py | 5 ++--- .../test_file/test_tutorial003.py | 5 ++--- .../test_file/test_tutorial004.py | 5 ++--- .../test_file/test_tutorial005.py | 5 ++--- .../test_path/test_tutorial001.py | 11 ++++++----- .../test_path/test_tutorial002.py | 14 ++++++-------- 7 files changed, 22 insertions(+), 28 deletions(-) diff --git a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial001.py b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial001.py index 86368a7..3e77ab3 100644 --- a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial001.py +++ b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial001.py @@ -11,10 +11,9 @@ runner = CliRunner() app = typer.Typer() app.command()(mod.main) -config_file = Path("./config.txt") - -def test_main(): +def test_main(tmpdir): + config_file = Path(tmpdir) / "config.txt" config_file.write_text("some settings\nsome more settings") result = runner.invoke(app, ["--config", f"{config_file}"]) config_file.unlink() diff --git a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial002.py b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial002.py index 17a9696..d936212 100644 --- a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial002.py +++ b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial002.py @@ -11,10 +11,9 @@ runner = CliRunner() app = typer.Typer() app.command()(mod.main) -config_file = Path("./config.txt") - -def test_main(): +def test_main(tmpdir): + config_file = Path(tmpdir) / "config.txt" if config_file.exists(): # pragma no cover config_file.unlink() result = runner.invoke(app, ["--config", f"{config_file}"]) diff --git a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial003.py b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial003.py index 702e7e0..be02506 100644 --- a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial003.py +++ b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial003.py @@ -11,10 +11,9 @@ runner = CliRunner() app = typer.Typer() app.command()(mod.main) -binary_file = Path("./config.txt") - -def test_main(): +def test_main(tmpdir): + binary_file = Path(tmpdir) / "config.txt" binary_file.write_bytes(b"la cig\xc3\xbce\xc3\xb1a trae al ni\xc3\xb1o") result = runner.invoke(app, ["--file", f"{binary_file}"]) binary_file.unlink() diff --git a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial004.py b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial004.py index 3a704b6..5b20e90 100644 --- a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial004.py +++ b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial004.py @@ -11,10 +11,9 @@ runner = CliRunner() app = typer.Typer() app.command()(mod.main) -binary_file = Path("./config.txt") - -def test_main(): +def test_main(tmpdir): + binary_file = Path(tmpdir) / "config.txt" if binary_file.exists(): # pragma no cover binary_file.unlink() result = runner.invoke(app, ["--file", f"{binary_file}"]) diff --git a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial005.py b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial005.py index f2541ed..9257229 100644 --- a/tests/test_tutorial/test_parameter_types/test_file/test_tutorial005.py +++ b/tests/test_tutorial/test_parameter_types/test_file/test_tutorial005.py @@ -11,10 +11,9 @@ runner = CliRunner() app = typer.Typer() app.command()(mod.main) -config_file = Path("./config.txt") - -def test_main(): +def test_main(tmpdir): + config_file = Path(tmpdir) / "config.txt" if config_file.exists(): # pragma no cover config_file.unlink() config_file.write_text("") diff --git a/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py b/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py index 9ef0cec..0c4dae2 100644 --- a/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py +++ b/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py @@ -11,17 +11,17 @@ runner = CliRunner() app = typer.Typer() app.command()(mod.main) -config_file = Path("./config.txt") - -def test_no_path(): +def test_no_path(tmpdir): + Path(tmpdir) / "config.txt" result = runner.invoke(app) assert result.exit_code == 1 assert "No config file" in result.output assert "Aborted!" in result.output -def test_not_exists(): +def test_not_exists(tmpdir): + config_file = Path(tmpdir) / "config.txt" if config_file.exists(): # pragma no cover config_file.unlink() result = runner.invoke(app, ["--config", f"{config_file}"]) @@ -29,7 +29,8 @@ def test_not_exists(): assert "The config doesn't exist" in result.output -def test_exists(): +def test_exists(tmpdir): + config_file = Path(tmpdir) / "config.txt" config_file.write_text("some settings") result = runner.invoke(app, ["--config", f"{config_file}"]) config_file.unlink() diff --git a/tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py b/tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py index cbdf2b6..f524511 100644 --- a/tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py +++ b/tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py @@ -11,21 +11,19 @@ runner = CliRunner() app = typer.Typer() app.command()(mod.main) -config_file = Path("./config.txt") - -def test_not_exists(): +def test_not_exists(tmpdir): + config_file = Path(tmpdir) / "config.txt" if config_file.exists(): # pragma no cover config_file.unlink() result = runner.invoke(app, ["--config", f"{config_file}"]) assert result.exit_code != 0 - assert ( - 'Error: Invalid value for "--config": File "config.txt" does not exist.' - in result.output - ) + assert 'Error: Invalid value for "--config": File' in result.output + assert "does not exist" in result.output -def test_exists(): +def test_exists(tmpdir): + config_file = Path(tmpdir) / "config.txt" config_file.write_text("some settings") result = runner.invoke(app, ["--config", f"{config_file}"]) config_file.unlink()