-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_alt_inputs.py
68 lines (55 loc) · 2.04 KB
/
test_alt_inputs.py
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
65
66
67
68
#!/usr/bin/env python
"""
test_alt_inputs.py: Test whether phylo2owl supports multiple input types,
including NEXUS and NexML. All of these file types should return exactly the
same RDF/XML output.
"""
import os
import pytest
import libphylo2owl
def test_newick_convert_to_OWL(path_tre):
"""
Test all .tre files by comparing them to the corresponding .owl file.
"""
# This might seem redundant, but it tests that '--format newick' works.
path_owl = path_tre[:-4] + '.owl'
if os.path.isfile(path_tre):
compare_example_file(path_tre, 'Newick', path_owl)
else:
pytest.skip("Newick file '{0}' does not have a comparable OWL file at {1}.".format(
path_tre,
path_owl
))
def test_nexus_convert_to_OWL(path_nex):
""" Test all .nex files by comparing them to the corresponding .owl file. """
path_owl = path_nex[:-4] + '.owl'
if os.path.isfile(path_owl):
compare_example_file(path_nex, 'NEXUS', path_owl)
else:
pytest.skip("Nexus file '{0}' does not have a comparable OWL file at {1}.".format(
path_nex,
path_owl
))
def test_nexml_convert_to_OWL(path_nexml):
""" Test all .nexml files by comparing them to the corresponding .owl file. """
path_owl = path_nexml[:-6] + '.owl'
if os.path.isfile(path_owl):
compare_example_file(path_nexml, 'NeXML', path_owl)
else:
pytest.skip("NeXML file '{0}' does not have a comparable OWL file at {1}.".format(
path_nexml,
path_owl
))
def compare_example_file(input_file, input_format, expected_output_file):
"""
For a given input file and format, generate OWL output, and then compare
it with the expected output file to make sure it's identical.
"""
(return_code, stdout, stderr) = libphylo2owl.exec_phylo2owl(
[
input_file, "--format", input_format
])
assert return_code == 0
with open(expected_output_file) as fil:
expected_output = fil.read()
assert expected_output == stdout