| 1 |
import pytest |
| 2 |
import py |
| 3 |
|
| 4 |
# "gen" is the abbreviated name for "getentityname.py" |
| 5 |
import gen |
| 6 |
|
| 7 |
DATADIR=py.path.local(__file__).dirpath().join("data") |
| 8 |
XMLFILES=DATADIR.listdir("*.xml", sort=True) |
| 9 |
OUTFILES=(f.new(ext=".out") for f in XMLFILES) |
| 10 |
# CATALOGFILES=DATADIR.listdir("*.", sort=True) |
| 11 |
|
| 12 |
|
| 13 |
@pytest.mark.parametrize("xmlfile, outfile", |
| 14 |
zip(XMLFILES, OUTFILES), |
| 15 |
ids=lambda path: path.basename, |
| 16 |
) |
| 17 |
def test_xml_and_output(xmlfile, outfile, capsys): |
| 18 |
DIRNAME = py.path.local(xmlfile.dirname) |
| 19 |
|
| 20 |
# First we check for consistency if the .out file is there |
| 21 |
assert outfile.exists() |
| 22 |
# We read our data and convert it into a set. |
| 23 |
# We are only interested in the content, not the order. |
| 24 |
# That way, the order doesn't matter. |
| 25 |
# Furthermore, any empty string ("") are skipped (see the if clause |
| 26 |
# inside the list comprehension) |
| 27 |
outdata = outfile.read().strip().split(" ") |
| 28 |
outdata = [DATADIR / f for f in outdata if f] |
| 29 |
|
| 30 |
result = gen.main([xmlfile.strpath]) |
| 31 |
assert result == 0 |
| 32 |
|
| 33 |
captured = capsys.readouterr().out.strip().split(" ") |
| 34 |
captured = [DATADIR / py.path.local(f).basename for f in captured if f] |
| 35 |
assert set(captured) == set(outdata) |