File: test_e2e.py

package info (click to toggle)
python-kajiki 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 692 kB
  • sloc: python: 4,145; makefile: 115
file content (63 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""End-to-end tests of Kajiki."""

import pathlib

import pytest

from kajiki.__main__ import main

DATA = pathlib.Path(__file__).parent / "data"
GOLDEN = DATA / "golden"


@pytest.mark.parametrize(
    ["args", "golden_file"],
    [
        (["-p", "kajiki_test_data.kitchensink"], "kitchensink1.html"),
        ([str(DATA / "kitchensink.html")], "kitchensink1.html"),
    ],
)
def test_golden_file(args, golden_file, capsys):
    with open(str(GOLDEN / golden_file)) as f:
        golden_data = f.read()

    main(args)

    captured = capsys.readouterr()
    assert captured.out == golden_data
    assert captured.err == ""


def test_file_not_found():
    with pytest.raises(IOError):
        main(["/does/not/exist.txt"])


# We should be able to force a non-txt file into text mode.
def test_force_text_mode(tmpdir, capsys):
    tmpfile = str(tmpdir / "myfile.png")
    with open(tmpfile, "w") as f:
        f.write("<!DOCTYPE html>\n")
        f.write("%for i in range(10)\n")
        f.write("${i}\n")
        f.write("%end")

    main(["-m", "text", tmpfile])

    captured = capsys.readouterr()
    assert (
        captured.out
        == """<!DOCTYPE html>
0
1
2
3
4
5
6
7
8
9
"""
    )
    assert captured.err == ""