File: test_openclose.py

package info (click to toggle)
archmage 1%3A0.4.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 460 kB
  • sloc: python: 732; sh: 13; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 940 bytes parent folder | download | duplicates (5)
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
import sys, archmage.cli, pathlib, tempfile, errno, shutil, contextlib


@contextlib.contextmanager
def TempDir():
    tmpdir = tempfile.mkdtemp()
    try:
        yield pathlib.Path(tmpdir)
    finally:
        try:
            shutil.rmtree(tmpdir)
        except OSError as exc:
            if exc.errno != errno.ENOENT:
                raise


def test_extract():
    with TempDir() as tmpdir:
        t = tmpdir / "example_html"

        sys.argv = ["extract", "tests/example.chm", t]
        archmage.cli.main()

        for f in ["index.html", "page 1.html", "page 2.html"]:
            assert (t / f).exists()

        assert "Page 1" in (t / "page 1.html").read_text()


def test_render_extracted():
    with TempDir() as tmpdir:
        t = tmpdir / "example_html"

        sys.argv = ["extract", "tests/example", t]
        archmage.cli.main()

        for f in ["index.html", "page 1.html"]:
            assert (t / f).exists()