Add end-to-end test for nomie->loop

This commit is contained in:
Marty Oehme 2021-12-16 13:12:27 +01:00
parent 5d8bde959e
commit d525d7c584
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 34 additions and 2 deletions

BIN
tests/data/loop/output.db Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -1,15 +1,46 @@
import click.testing from click.testing import CliRunner
import pytest import pytest
# for integration tests
from pathlib import Path
from shutil import copyfile
from subprocess import run
from habitmove import cli from habitmove import cli
@pytest.fixture @pytest.fixture
def runner(): def runner():
return click.testing.CliRunner() return CliRunner()
# Create an isolated environment to test the output file in
@pytest.fixture
def runner_with_nomie_input(tmp_path):
runner = CliRunner()
fname_input_data = Path("tests/data/nomie/input.json").resolve()
fname_target_data = Path("tests/data/loop/output.db").resolve()
with runner.isolated_filesystem(temp_dir=tmp_path):
copyfile(fname_input_data.resolve(), f"input.json")
copyfile(fname_target_data.resolve(), f"target")
yield runner
def test_cli_fails_without_file(runner): def test_cli_fails_without_file(runner):
result = runner.invoke(cli.main) result = runner.invoke(cli.main)
assert result.exit_code == 2 assert result.exit_code == 2
assert "Missing argument" in result.output assert "Missing argument" in result.output
@pytest.mark.e2e
def test_produces_output_file(runner_with_nomie_input):
result = runner_with_nomie_input.invoke(cli.main, "input.json")
assert result.exit_code == 0
assert Path("output.db").exists()
@pytest.mark.e2e
def test_produces_correct_output(runner_with_nomie_input):
runner_with_nomie_input.invoke(cli.main, "input.json")
result = run(["sqldiff", "output.db", "target"], capture_output=True)
assert result.stdout == b""