generated from ivoa-std/doc-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_examples.py
71 lines (56 loc) · 1.73 KB
/
check_examples.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
"""
Run all examples given in RegTAP.html and shout if any
of them raises an error or returns no records.
This assumes that the examples to run are in lstlisting environments
that are immediately preceded by a CHECK_HERE comment. Everything
is
This requires the pyvo.
Set the TAP_ACCESS_URL environment variable to a TAP server implementing
the relational registry.
"""
import os
import re
import sys
import warnings
import pyvo
TAP_ACCESS_URL = os.environ.get("TAP_ACCESS_URL", "https://dc.g-vo.org/tap")
def iter_examples(f):
accumulator, state = [], "scanning"
cur_subsection = None
for ct, ln in enumerate(f.readlines()):
if state=="scanning":
if ln.startswith("%CHECK_HERE"):
state = "skipping"
elif ln.startswith("\\subsection"):
cur_subsection = re.search(r"\{([^}]*)\}", ln).group(1)
elif state=="skipping":
if ln.startswith("\\begin{lstlisting}"):
state = "accumulating"
else:
raise Exception("Line %d: Spurious CHECK_HERE"%ct)
elif state=="accumulating":
if ln.startswith("\end{lstlisting}"):
state = "scanning"
yield cur_subsection, "".join(accumulator)
accumulator = []
else:
accumulator.append(ln)
def main():
svc = pyvo.dal.TAPService(TAP_ACCESS_URL)
with open("RegTAP.tex") as f:
for title, sample_query in iter_examples(f):
try:
result = svc.run_sync(sample_query).to_table()
if not len(result):
print(f"WARNING: Example returned no records in sect. '{title}'")
except Exception as ex:
print(f"ERROR: Example went bad in sect. {title}")
print(ex)
sys.exit(1)
if __name__=="__main__":
try:
warnings.filterwarnings("ignore", category=pyvo.dal.DALOverflowWarning)
except AttributeError:
# not warning against overflows yet
pass
main()