File: test_integration.py

package info (click to toggle)
daps 3.3.2%2Bcleaned1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,540 kB
  • sloc: xml: 9,773; sh: 3,059; python: 1,322; lisp: 380; makefile: 239
file content (64 lines) | stat: -rw-r--r-- 1,443 bytes parent folder | download | duplicates (3)
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
64
from pathlib import Path
import logging

import pytest

# "dxwf" is the abbreviated name for daps-xmlwellformed
# We can't import a name with a "-" so we use a link here:
import dxwf

THISDIR = Path(__file__).parent
DATADIR = THISDIR / "data"
BADDIR = DATADIR / "bad"
GOODDIR = DATADIR / "good"


def test_main_single_unknown():
    # Given
    xmlfile = "unknown"
    file = str(BADDIR / xmlfile)

    # When
    result = dxwf.main(["--xinclude", file])

    # Then
    assert result == dxwf.ExitCode.file_not_found


def test_main_two():
    # Given
    xmlfiles = ["test-syntax-comments.xml",
                "test-syntax-err-undeclared-entity.xml"]
    files = [str(BADDIR / f) for f in xmlfiles]

    # When
    result = dxwf.main(["--xinclude", *files])

    # Then
    assert result != 0


def test_main_one_good_one_bad(caplog):
    # Given
    xmlfiles = [
        # the good
        "test-external-entity.xml",
        # the bad
        "test-syntax-comments.xml",
    ]
    messages = (
        "Comment not terminated",
        "Start tag expected, '<' not found",
    )
    dirs = [GOODDIR, BADDIR]
    files = [str(d / f) for d, f in zip(dirs, xmlfiles)]

    # When
    with caplog.at_level(logging.ERROR):
        result = dxwf.main(["--xinclude", *files])

    # Then
    assert result != 0
    assert len(caplog.records) == len(messages)
    for record, msg in zip(caplog.records, messages):
        assert record.msg == msg