-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck-queries.py
69 lines (53 loc) · 1.57 KB
/
check-queries.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
#!/usr/bin/python3
"""
This script extracts the example queries from LineTAP.tex and runs them
against the dc.g-vo.org server using pyVO.
This works by looking for comments including
please-run-a[-lenient]-test and fetching the next lstlisting environment.
A lenient test here is one that may return empty.
"""
import sys
import pyvo
class ExampleCollector:
def __init__(self):
self.state, self.cur_query = "sleeping", []
def feed(self, line):
return getattr(self, "_exec_"+self.state)(line)
def _exec_sleeping(self, line):
if "please-run-a-test" in line:
self.opener = line
self.state = "hunting"
def _exec_hunting(self, line):
if "\\begin{lstlisting}" in line:
self.state = "collecting"
def _exec_collecting(self, line):
if "\\end{lstlisting}" in line:
query = "".join(self.cur_query)
self.state, self.cur_query = "sleeping", []
if "-lenient" in self.opener:
return "lenient", query
else:
return "strict", query
else:
self.cur_query.append(line)
def iter_examples(src_name):
coll = ExampleCollector()
with open(src_name, encoding="utf-8") as f:
for ln in f:
val = coll.feed(ln)
if val:
yield val
def main():
failures = 0
svc = pyvo.dal.TAPService("http://dc.g-vo.org/tap")
for mode, query in iter_examples("LineTAP.tex"):
try:
res = svc.run_sync(query)
if mode=="strict":
assert len(res)>0, "No rows returned"
# else we're happy that the thing didn't crash
except (pyvo.DALQueryError, AssertionError) as ex:
print(f"FAILURE ({ex}):\n{query}")
failures += 1
if __name__=="__main__":
sys.exit(main())