habitmove/tests/test_cli.py

46 lines
1.3 KiB
Python

from click.testing import CliRunner
import pytest
# for integration tests
from pathlib import Path
from shutil import copyfile
from subprocess import run
from habitmove import cli
@pytest.fixture
def runner():
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):
result = runner.invoke(cli.main)
assert result.exit_code == 2
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""