/[volute]/trunk/projects/registry/regtap/check_examples.py
ViewVC logotype

Contents of /trunk/projects/registry/regtap/check_examples.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2778 - (show annotations)
Wed Dec 3 17:26:16 2014 UTC (6 years, 8 months ago) by volute@g-vo.org
File MIME type: text/x-python
File size: 1713 byte(s)
RegTAP: fixed one SQL typo, ported check_examples to the ivoatex version.

1 """
2 Run all examples given in RegTAP.html and shout if any
3 of them raises an error or returns no records.
4
5 This assumes that the examples to run are in lstlisting environments
6 that are immediately preceded by a CHECK_HERE comment. Everything
7 is
8
9 This requires the GAVO VOTable package (http://soft.g-vo.org).
10
11 Set the TAP_ACCESS_URL environment variable to a TAP server implementing
12 the relational registry.
13 """
14
15 import os
16 import re
17
18 from gavo import votable
19 from gavo.votable import tapquery
20
21
22 TAP_ACCESS_URL = os.environ.get("TAP_ACCESS_URL", "http://dc.g-vo.org/tap")
23
24
25 def iter_examples(f):
26 accumulator, state = [], "scanning"
27 cur_subsection = None
28
29 for ct, ln in enumerate(f.readlines()):
30 if state=="scanning":
31 if ln.startswith("%CHECK_HERE"):
32 state = "skipping"
33 elif ln.startswith("\\subsection"):
34 cur_subsection = re.search(r"\{([^}]*)\}", ln).group(1)
35
36 elif state=="skipping":
37 if ln.startswith("\\begin{lstlisting}"):
38 state = "accumulating"
39 else:
40 raise Exception("Line %d: Spurious CHECK_HERE"%ct)
41
42 elif state=="accumulating":
43 if ln.startswith("\end{lstlisting}"):
44 state = "scanning"
45 yield cur_subsection, "".join(accumulator)
46 accumulator = []
47 else:
48 accumulator.append(ln)
49
50
51 def main():
52 with open("RegTAP.tex") as f:
53 for title, ex in iter_examples(f):
54 try:
55 job = votable.ADQLSyncJob(TAP_ACCESS_URL, ex)
56 data, metadata = votable.load(job.run().openResult())
57 if not data:
58 print "(Example returned no records: '%s')"%title
59 except tapquery.WrongStatus:
60 print "************ Example went bad"
61 print "Last title:", title
62 print "Error message:", job.getErrorFromServer()[:1000]
63
64
65 if __name__=="__main__":
66 main()

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26