-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_sbml.py
executable file
·110 lines (83 loc) · 2.93 KB
/
test_sbml.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
from pyneuroml import sbml
import os
import stat
def test_sbml_validate_a_valid_file():
"ensure it validates a single valid file by returning True"
fname = "tests/sbml/test_data/valid_doc.sbml"
result = sbml.validate_sbml_files([fname])
assert result
def test_sbml_validate_missing_inputfile():
try:
result = sbml.validate_sbml_files(["tests/sbml/test_data/nonexistent_file"])
except FileNotFoundError:
return
except Exception:
pass
raise Exception("failed to properly flag file not found error")
def test_sbml_validate_no_read_access():
fname = "tests/sbml/test_data/no_read_access.sbml"
# Remove read permission
os.chmod(fname, 0)
try:
result = sbml.validate_sbml_files([fname])
except IOError:
os.chmod(fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
return
except Exception:
pass
os.chmod(
fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
) # Restore permission for git
raise Exception("failed to properly flag lack of read access")
def test_sbml_validate_valueerror_on_no_inputfiles():
"ensure it raises a ValueError exception for failing to provide any files"
try:
result = sbml.validate_sbml_files([])
except ValueError:
return
except Exception:
pass
raise Exception("failed to properly flag missing input files")
def test_sbml_validate_unit_consistency_check():
"""
ensure it fails a unit inconsistency in strict mode
ensure it only warns about a unit inconsistency when not in strict mode
"""
try:
result = sbml.validate_sbml_files(
["tests/sbml/test_data/inconsistent_units_doc.sbml"], strict_units=True
)
assert not result
except Exception:
raise Exception("failed to flag inconsistent units as an error")
try:
result = sbml.validate_sbml_files(
["tests/sbml/test_data/inconsistent_units_doc.sbml"], strict_units=False
)
assert result
except Exception:
raise Exception("failed to flag inconsistent units as an error")
def test_sbml_validate_flag_all_invalid_files():
"""
ensure it returns False for all invalid files
without raising any exceptions
"""
fail_count = 0
n_files = 3
for i in range(n_files):
fname = "tests/sbml/test_data/invalid_doc%02d.sbml" % i
try:
result = sbml.validate_sbml_files([fname])
if not result:
fail_count += 1
except Exception:
pass
assert fail_count == n_files
if __name__ == "__main__":
test_sbml_validate_validate_a_valid_file()
test_sbml_validate_valueerror_on_no_inputfiles()
test_sbml_validate_missing_inputfile()
test_sbml_validate_flag_all_invalid_files()
test_sbml_validate_unit_consistency_check()
test_sbml_validate_no_read_access()