4from pathlib import Path
11def test_gets_empty_result_if_no_text(bin_path: Path) -> None:
13 If you pass an image without any text, you get empty output.
15 proc = subprocess.Popen(
16 [bin_path, "tests/fixtures/checkerboard.png"],
17 stdout=subprocess.PIPE,
18 stderr=subprocess.PIPE,
20 stdout, stderr = proc.communicate()
22 assert proc.returncode == 0
23 assert stdout == b"\n"
25 if os.environ.get("GITHUB_ACTIONS") != "true":
29def test_gets_text_from_image(bin_path: Path) -> None:
31 If you pass an image that contains text, it gets printed to stdout.
33 proc = subprocess.Popen(
34 [bin_path, "tests/fixtures/with_text.png"],
35 stdout=subprocess.PIPE,
36 stderr=subprocess.PIPE,
38 stdout, stderr = proc.communicate()
40 assert proc.returncode == 0
41 assert stdout == b"This is an image with more than one block of text\n"
43 if os.environ.get("GITHUB_ACTIONS") != "true":
47def test_gives_useful_error_if_no_such_file(bin_path: Path) -> None:
49 If you pass a path that doesn't exist, you get a useful error.
51 proc = subprocess.Popen(
52 [bin_path, "tests/fixtures/doesnotexist.gif"],
53 stdout=subprocess.PIPE,
54 stderr=subprocess.PIPE,
56 stdout, stderr = proc.communicate()
58 assert proc.returncode == 1
60 assert stderr == b"Cannot find file at path: tests/fixtures/doesnotexist.gif\n"
63def test_gives_useful_error_if_cannot_recognize_image(bin_path: Path) -> None:
65 If you pass a path that doesn't look like an image, you get a useful error.
67 proc = subprocess.Popen(
68 [bin_path, "README.md"],
69 stdout=subprocess.PIPE,
70 stderr=subprocess.PIPE,
72 stdout, stderr = proc.communicate()
74 assert proc.returncode == 1
76 assert stderr.startswith(b"Unable to recognise text:")
79@pytest.mark.parametrize(
82 pytest.param([], id="no_arguments"),
84 ["example.png", "example.gif", "--debug"], id="too_many_arguments"
88def test_it_fails_if_you_supply_the_wrong_arguments(
89 bin_path: Path, argv: list[str]
92 If you pass the wrong arguments, you get an error explaining how to use it.
94 proc = subprocess.Popen(
96 stdout=subprocess.PIPE,
97 stderr=subprocess.PIPE,
99 stdout, stderr = proc.communicate()
101 assert proc.returncode == 1
103 assert stderr.startswith(b"Usage:")
106def test_prints_the_version(bin_path: Path) -> None:
108 If you run it with the --version flag, it prints the version number.
110 proc = subprocess.Popen(
111 [bin_path, "--version"],
112 stdout=subprocess.PIPE,
113 stderr=subprocess.PIPE,
115 stdout, stderr = proc.communicate()
117 assert proc.returncode == 0
118 assert re.match(r"get_live_text [0-9]+\.[0-9]+\.[0-9]+\n$", stdout.decode("utf8"))