Skip to content

Commit

Permalink
restore input file encoding argument tests (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
JKatzwinkel committed Feb 12, 2025
1 parent b74fcb3 commit 56f352b
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
import tempfile
from typing import List
from typing import Iterable, List

import pytest

Expand All @@ -18,6 +18,37 @@ def argv(args: str) -> List[str]:
return ["alto-tools"] + args.split()


@pytest.fixture
def latin1_input_file_path() -> Iterable[str]:
with open("tests/data/PPN720183197-PHYS_0004.xml") as f:
xml = f.read()
with tempfile.TemporaryDirectory() as tmpdir:
fn = os.path.join(tmpdir, "iso8859.xml")
with open(fn, "w+", encoding="iso-8859-1", errors="replace") as f:
f.write(xml)
yield fn


def test_single_file_xml_encoding(
latin1_input_file_path: str,
capsys: pytest.CaptureFixture[str],
) -> None:
fn = latin1_input_file_path
sys.argv = argv(f"-t -x iso8859-1 {fn}")
alto_tools.main()
assert "Stille Gedanken" in capsys.readouterr().out


def test_single_file_file_encoding(
latin1_input_file_path: str,
capsys: pytest.CaptureFixture[str],
) -> None:
fn = latin1_input_file_path
sys.argv = argv(f"-t -e iso8859-1 {fn}")
alto_tools.main()
assert "Stille Gedanken" in capsys.readouterr().out


def test_nonexistant_file_input(capsys: pytest.CaptureFixture[str]) -> None:
sys.argv = argv("i/dont/exist.xml -t")
alto_tools.main()
Expand Down Expand Up @@ -78,4 +109,4 @@ def test_pipe_input_xml(capsys: pytest.CaptureFixture[str]) -> None:
sys.argv = ["alto-tools", "-t", "-"]
alto_tools.main()
captured = capsys.readouterr()
assert "Stille Gedanken" in captured.out
assert "Stille Gedanken" in captured.out

0 comments on commit 56f352b

Please sign in to comment.