| 1 |
from pathlib import Path |
| 2 |
import logging |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
# "dxwf" is the abbreviated name for daps-xmlwellformed |
| 7 |
# We can't import a name with a "-" so we use a link here: |
| 8 |
import dxwf |
| 9 |
|
| 10 |
THISDIR = Path(__file__).parent |
| 11 |
DATADIR = THISDIR / "data" |
| 12 |
BADDIR = DATADIR / "bad" |
| 13 |
GOODDIR = DATADIR / "good" |
| 14 |
|
| 15 |
|
| 16 |
def test_main_single_unknown(): |
| 17 |
# Given |
| 18 |
xmlfile = "unknown" |
| 19 |
file = str(BADDIR / xmlfile) |
| 20 |
|
| 21 |
# When |
| 22 |
result = dxwf.main(["--xinclude", file]) |
| 23 |
|
| 24 |
# Then |
| 25 |
assert result == dxwf.ExitCode.file_not_found |
| 26 |
|
| 27 |
|
| 28 |
def test_main_two(): |
| 29 |
# Given |
| 30 |
xmlfiles = ["test-syntax-comments.xml", |
| 31 |
"test-syntax-err-undeclared-entity.xml"] |
| 32 |
files = [str(BADDIR / f) for f in xmlfiles] |
| 33 |
|
| 34 |
# When |
| 35 |
result = dxwf.main(["--xinclude", *files]) |
| 36 |
|
| 37 |
# Then |
| 38 |
assert result != 0 |
| 39 |
|
| 40 |
|
| 41 |
def test_main_one_good_one_bad(caplog): |
| 42 |
# Given |
| 43 |
xmlfiles = [ |
| 44 |
# the good |
| 45 |
"test-external-entity.xml", |
| 46 |
# the bad |
| 47 |
"test-syntax-comments.xml", |
| 48 |
] |
| 49 |
messages = ( |
| 50 |
"Comment not terminated", |
| 51 |
"Start tag expected, '<' not found", |
| 52 |
) |
| 53 |
dirs = [GOODDIR, BADDIR] |
| 54 |
files = [str(d / f) for d, f in zip(dirs, xmlfiles)] |
| 55 |
|
| 56 |
# When |
| 57 |
with caplog.at_level(logging.ERROR): |
| 58 |
result = dxwf.main(["--xinclude", *files]) |
| 59 |
|
| 60 |
# Then |
| 61 |
assert result != 0 |
| 62 |
assert len(caplog.records) == len(messages) |
| 63 |
for record, msg in zip(caplog.records, messages): |
| 64 |
assert record.msg == msg |