-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.py
169 lines (127 loc) · 3.76 KB
/
tests.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
r"""*Master script for* ``pent`` *test suite*.
``pent`` Extracts Numerical Text.
**Author**
Brian Skinn ([email protected])
**File Created**
3 Sep 2018
**Copyright**
\(c) Brian Skinn 2018
**Source Repository**
http://www.github.com/bskinn/pent
**Documentation**
http://pent.readthedocs.io
**License**
The MIT License; see |license_txt|_ for full license terms
**Members**
*(none documented)*
"""
class AP(object):
""" Container for arguments for selecting test suites.
Also includes PFX, a helper string for substitution/formatting.
"""
ALL = "all"
FAST = "fast"
README = "readme"
LIVE = "live"
ORCA = "orca"
MWFN = "mwfn"
GAMESS = "gamess"
PFX = "--{0}"
def get_parser():
import argparse
# Create the parser
prs = argparse.ArgumentParser(description="Run tests for pent")
# Verbosity argument
prs.add_argument("-v", action="store_true", help="Show verbose output")
# Test subgroups
grp_livedata = prs.add_argument_group(title="Run live-data tests")
# Options without subgroups
prs.add_argument(
AP.PFX.format(AP.ALL),
"-a",
action="store_true",
help="Run all tests (overrides any other selections)",
)
prs.add_argument(
AP.PFX.format(AP.FAST),
"-f",
action="store_true",
help="Run only 'fast' tests",
)
prs.add_argument(
AP.PFX.format(AP.README),
action="store_true",
help="Run only the tests on README.rst",
)
# Subgroup for live data
grp_livedata.add_argument(
AP.PFX.format(AP.LIVE),
"-l",
action="store_true",
help="Run all 'live data' tests",
)
grp_livedata.add_argument(
AP.PFX.format(AP.ORCA),
action="store_true",
help="Run all ORCA 'live data' tests",
)
grp_livedata.add_argument(
AP.PFX.format(AP.MWFN),
action="store_true",
help="Run all Multiwfn 'live data' tests",
)
grp_livedata.add_argument(
AP.PFX.format(AP.GAMESS),
action="store_true",
help="Run all GAMESS 'live data' tests",
)
# Return the parser
return prs
def main():
import sys
import unittest as ut
import pent.test
# Retrieve the parser
prs = get_parser()
# Pull the dict of stored flags, saving the un-consumed args, and
# update sys.argv
ns, args_left = prs.parse_known_args()
params = vars(ns)
sys.argv = sys.argv[:1] + args_left
# Create the empty test suite
ts = ut.TestSuite()
# Helper function for adding test suites. Just uses ts and params from
# the main() function scope
def addsuiteif(suite, flags):
if any(params[k] for k in flags):
ts.addTest(suite)
# Add commandline-indicated tests per-group
# Fast tests
addsuiteif(pent.test.pent_base.suite_base(), [AP.ALL, AP.FAST])
# Slow tests
addsuiteif(pent.test.pent_slow.suite_base_slow(), [AP.ALL])
# README tests
addsuiteif(
pent.test.pent_readme.suite_doctest_readme(),
[AP.ALL, AP.FAST, AP.README],
)
# Live data tests
addsuiteif(
pent.test.pent_livedata.suite_live_orca(),
[AP.ALL, AP.FAST, AP.LIVE, AP.ORCA],
)
addsuiteif(
pent.test.pent_livedata.suite_live_mwfn(),
[AP.ALL, AP.FAST, AP.LIVE, AP.MWFN],
)
addsuiteif(
pent.test.pent_livedata.suite_live_gamess(),
[AP.ALL, AP.FAST, AP.LIVE, AP.GAMESS],
)
# Create the test runner and execute
ttr = ut.TextTestRunner(buffer=True, verbosity=(2 if params["v"] else 1))
success = ttr.run(ts).wasSuccessful()
# Return based on success result (lets tox report success/fail)
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()