Fix tests using binary config files

This commit is contained in:
Sebastián Ramírez 2020-01-18 19:50:57 +01:00
parent 2af83b0be5
commit 222765eacf
7 changed files with 22 additions and 28 deletions

View file

@ -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()

View file

@ -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}"])

View file

@ -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()

View file

@ -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}"])

View file

@ -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("")

View file

@ -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()

View file

@ -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()