-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_script.py
49 lines (36 loc) · 1.18 KB
/
test_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# type: ignore
"""Tests of running `python google_voice_history.py`."""
import pathlib
import re
import subprocess
TESTS_PATH = pathlib.Path(__file__).parent.resolve()
SRC_PATH = (TESTS_PATH / ".." / "src").resolve()
def run_script(*args):
"""Run the script and return the result with captured output."""
return subprocess.run(
["python", "google_voice_history.py", *[str(x) for x in args]],
cwd=SRC_PATH,
capture_output=True,
text=True,
)
def test_required_path():
"""Show usage when missing file path."""
process = run_script()
assert process.returncode != 0
assert "PATH" in process.stderr
def test_help_message():
"""Show a help message."""
process = run_script("-h")
assert process.returncode == 0
assert re.match(
r"^usage.+^Generate.+^ PATH.+^CSV columns",
process.stdout,
re.DOTALL | re.MULTILINE,
)
def test_example():
"""Generate example CSV from example takeout."""
process = run_script(TESTS_PATH / "takeout.zip")
with open(TESTS_PATH / "history.csv") as f:
example_csv = f.read()
assert process.returncode == 0
assert process.stdout == example_csv