2021-12-16 12:12:27 +00:00
|
|
|
from click.testing import CliRunner
|
2021-12-06 22:36:24 +00:00
|
|
|
import pytest
|
2021-12-06 22:20:18 +00:00
|
|
|
|
2021-12-16 12:12:27 +00:00
|
|
|
# for integration tests
|
|
|
|
from pathlib import Path
|
|
|
|
from shutil import copyfile
|
|
|
|
from subprocess import run
|
|
|
|
|
2021-12-06 22:20:18 +00:00
|
|
|
from habitmove import cli
|
|
|
|
|
|
|
|
|
2021-12-06 22:36:24 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def runner():
|
2021-12-16 12:12:27 +00:00
|
|
|
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
|
2021-12-06 22:36:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_cli_fails_without_file(runner):
|
2021-12-06 22:20:18 +00:00
|
|
|
result = runner.invoke(cli.main)
|
|
|
|
assert result.exit_code == 2
|
|
|
|
assert "Missing argument" in result.output
|
2021-12-16 12:12:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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""
|