:white_check_mark: Fix tests using binary config files
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by Sebastián Ramírez · parent 2af83b0 · Browse files · 7 files·+22 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+22 added−28 removed
- tests:+22 added−28 removed
Provenance
- Commit
222765e- Tree
97dff0d- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
Sebastián Ramírez <tiangolo@gmail.com>- Parent
2af83b0
7 files changed+22 added−28 removed
modified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial001.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"17 config_file.write_text("some settings\nsome more settings")18 result = runner.invoke(app, ["--config", f"{config_file}"])19 config_file.unlink()20 assert result.exit_code == 012 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial002.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"17 if config_file.exists(): # pragma no cover18 config_file.unlink()19 result = runner.invoke(app, ["--config", f"{config_file}"])20 text = config_file.read_text()14 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial003.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-binary_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ binary_file = Path(tmpdir) / "config.txt"17 binary_file.write_bytes(b"la cig\xc3\xbce\xc3\xb1a trae al ni\xc3\xb1o")18 result = runner.invoke(app, ["--file", f"{binary_file}"])19 binary_file.unlink()20 assert result.exit_code == 011 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial004.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-binary_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ binary_file = Path(tmpdir) / "config.txt"17 if binary_file.exists(): # pragma no cover18 binary_file.unlink()19 result = runner.invoke(app, ["--file", f"{binary_file}"])20 text = binary_file.read_text()15 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial005.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"17 if config_file.exists(): # pragma no cover18 config_file.unlink()19 config_file.write_text("")20 result = runner.invoke(app, ["--config", f"{config_file}"])17 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py+6 added-5 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_no_path():15+def test_no_path(tmpdir):16+ Path(tmpdir) / "config.txt"17 result = runner.invoke(app)18 assert result.exit_code == 119 assert "No config file" in result.output20 assert "Aborted!" in result.output21 22 24-def test_not_exists():23+def test_not_exists(tmpdir):24+ config_file = Path(tmpdir) / "config.txt"25 if config_file.exists(): # pragma no cover26 config_file.unlink()27 result = runner.invoke(app, ["--config", f"{config_file}"])28 assert result.exit_code == 029 assert "The config doesn't exist" in result.output30 31 32-def test_exists():32+def test_exists(tmpdir):33+ config_file = Path(tmpdir) / "config.txt"34 config_file.write_text("some settings")35 result = runner.invoke(app, ["--config", f"{config_file}"])36 config_file.unlink()37 assert result.exit_code == 017 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py+6 added-8 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_not_exists():15+def test_not_exists(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"17 if config_file.exists(): # pragma no cover18 config_file.unlink()19 result = runner.invoke(app, ["--config", f"{config_file}"])20 assert result.exit_code != 022- assert (23- 'Error: Invalid value for "--config": File "config.txt" does not exist.'24- in result.output25- )21+ assert 'Error: Invalid value for "--config": File' in result.output22+ assert "does not exist" in result.output23 24 28-def test_exists():25+def test_exists(tmpdir):26+ config_file = Path(tmpdir) / "config.txt"27 config_file.write_text("some settings")28 result = runner.invoke(app, ["--config", f"{config_file}"])29 config_file.unlink()30 assert result.exit_code == 020 unmodified lines