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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2777 by volute@g-vo.org, Tue Feb 25 12:27:22 2014 UTC revision 2778 by volute@g-vo.org, Wed Dec 3 17:26:16 2014 UTC
# Line 2  Line 2 
2  Run all examples given in RegTAP.html and shout if any  Run all examples given in RegTAP.html and shout if any
3  of them raises an error or returns no records.  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).  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  Set the TAP_ACCESS_URL environment variable to a TAP server implementing
# Line 9  Line 13 
13  """  """
14    
15  import os  import os
16    import re
17    
 from gavo.utils import StartEndHandler  
18  from gavo import votable  from gavo import votable
19  from gavo.votable import tapquery  from gavo.votable import tapquery
20    
# Line 18  Line 22 
22  TAP_ACCESS_URL = os.environ.get("TAP_ACCESS_URL", "http://dc.g-vo.org/tap")  TAP_ACCESS_URL = os.environ.get("TAP_ACCESS_URL", "http://dc.g-vo.org/tap")
23    
24    
25  class ExampleChecker(StartEndHandler):  def iter_examples(f):
26            accumulator, state = [], "scanning"
27          lastDT = None          cur_subsection = None
28    
29          def _end_pre(self, name, attrs, content):          for ct, ln in enumerate(f.readlines()):
30                  if attrs.get("class")!="samplequery":                  if state=="scanning":
31                          return                          if ln.startswith("%CHECK_HERE"):
32                  try:                                  state = "skipping"
33                          job = votable.ADQLSyncJob(TAP_ACCESS_URL, content)                          elif ln.startswith("\\subsection"):
34                          data, metadata = votable.load(job.run().openResult())                                  cur_subsection = re.search(r"\{([^}]*)\}", ln).group(1)
35                          if not data:  
36                                  print "(Example returned no records: '%s')"%self.lastDT                  elif state=="skipping":
37                  except tapquery.WrongStatus:                          if ln.startswith("\\begin{lstlisting}"):
38                          print "************ Example went bad"                                  state = "accumulating"
39                          print "Last title:", self.lastDT                          else:
40                          print "Error message:", job.getErrorFromServer()[:1000]                                  raise Exception("Line %d: Spurious CHECK_HERE"%ct)
41            
42          def _start_div(self, name, attrs):                  elif state=="accumulating":
43                  if attrs.get("class")=="query-example":                          if ln.startswith("\end{lstlisting}"):
44                          self.lastDT = attrs["id"]                                  state = "scanning"
45                                    yield cur_subsection, "".join(accumulator)
46                                    accumulator = []
47                            else:
48                                    accumulator.append(ln)
49    
50    
51  def main():  def main():
52          with open("RegTAP.html") as f:          with open("RegTAP.tex") as f:
53                  ExampleChecker().parse(f)                  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__":  if __name__=="__main__":
66          main()          main()

Legend:
Removed from v.2777  
changed lines
  Added in v.2778

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