nancy/tests/cli/test_record.py
2022-10-11 13:43:43 -04:00

55 lines
1.3 KiB
Python

from click.testing import CliRunner
from nancy.cli import main
import pytest
import os
from pathlib import Path
import tempfile
from typing import Iterator
@pytest.fixture
def junk_dir() -> Iterator[Path]:
"""Create a temp directory with a few files"""
with tempfile.TemporaryDirectory(prefix="nancy_junkdir") as d:
root = Path(d)
open(root / "empty.txt", "w").close() # touch a file
open(root / "full.txt", "w").write("something") # touch a file
os.mkdir(root / "d")
open(root / "foo.txt", "w").write("bar") # touch a file
yield root
def test_record(junk_dir: Path) -> None:
runner = CliRunner()
result = runner.invoke(
main,
[
"record",
"-s",
str(junk_dir),
"-m",
"This is just a test recording",
"--yes", # don't ask for confirmation
],
)
print(result.output)
assert result.exit_code == 0
assert "ERROR" not in result.output
# test again with confirmation
result = runner.invoke(
main,
[
"record",
"-s",
str(junk_dir),
"-m",
"This is just a test recording",
],
input="y\n",
)
print(result.output)
assert result.exit_code == 0
assert "ERROR" not in result.output