source: CMIP6dreq/trunk/dreqPy/simpleCheck.py @ 425

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreq/trunk/dreqPy/simpleCheck.py@425
Revision 425, 3.5 KB checked in by mjuckes, 4 years ago (diff)

spurious files removed

Line 
1
2try:
3  import pkgutil
4  l = pkgutil.iter_modules()
5  ll = map( lambda x: x[1], l )
6  pkgutilFailed=False
7except:
8  pkgutilFailed=True
9  print 'Failed to load pkgutil .. more limited tests on available modules will be done'
10  ll = []
11
12
13requiredModules = ['xml','string','collections','os']
14confirmed = []
15installFailed = []
16missingLib = []
17for x in requiredModules:
18  if x in ll or pkgutilFailed:
19      try:
20        cmd = 'import %s' % x
21        exec cmd
22        confirmed.append( x )
23      except:
24        installFailed.append( x )
25        print 'Failed to install %s' % x
26  else:
27      missingLib.append( x )
28
29if len( missingLib ) > 0 or len(installFailed) > 0:
30  print 'Could not load all required python libraries'
31  if len(missingLib) > 0:
32    print 'MISSING LIBRARIES:',str(missingLib)
33  if len(installFailed) > 0:
34    print 'LIBRARIES PRESENT BUT FAILED TO INSTALL:',str(missingLib)
35  all = False
36  exit(0)
37else:
38  print 'Required libraries present'
39  all = True
40
41
42import inspect
43class checkbase(object):
44  def __init__(self,lab):
45    self.lab = lab
46    self.ok = True
47
48#document directory
49    self.docdir = '../docs'
50#schema location
51    self.schema = '%s/dreq2Schema.xsd' % self.docdir
52#sample xml location
53    self.sampleXml = '%s/dreq2Sample.xml' % self.docdir
54#definition document xml location
55    self.defnXml = '%s/dreq2Defn.xml' % self.docdir
56
57    ml = inspect.getmembers( self, predicate=inspect.ismethod ) 
58    ok = True
59    for tag,m in ml:
60      if tag[:3] == '_ch':
61        try:
62          self.ok = False
63          m()
64          ok &= self.ok
65        except:
66          print 'Failed to complete check %s' % tag
67    if ok:
68      print '%s: All checks passed' % lab
69    else: 
70      print '%s: Errors detected' % lab
71       
72class check1(checkbase):
73  def _ch01_importDreq(self):
74    import dreq
75    print 'Dreq software import checked'
76    self.ok = True
77
78  def _ch02_importSample(self):
79    import dreq
80    rq = dreq.loadDreq( dreqXML=self.sampleXml,configdoc=self.defnXml )
81    print 'Dreq sample load checked'
82    self.ok = True
83
84class check2(checkbase):
85
86  def _clear_ch03(self):
87    os.unlink( '.simpleCheck_check2_err.txt' )
88    os.unlink( '.simpleCheck_check2.txt' )
89
90  def _ch03_checkXML(self):
91    import os
92    os.popen( 'which xmllint 2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' ).readlines()
93    ii = open( '.simpleCheck_check2_err.txt' ).readlines()
94    if len(ii) > 0:
95      print 'WARNING[001]: failed to detect xmllint command line program'
96      print 'optional checks omitted'
97      self.ok = False
98      self._clear_ch03()
99      return
100    ii = open( '.simpleCheck_check2.txt' ).readlines()
101    if len(ii) < 1:
102      print 'WARNING[002]: failed to detect xmllint command line program'
103      print 'optional checks omitted'
104      self.ok = False
105      self._clear_ch03()
106      return
107
108    cmd = 'xmllint --noout --schema %s %s  2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' % (self.schema,self.sampleXml) 
109    os.popen( cmd ).readlines()
110    ii = open( '.simpleCheck_check2_err.txt' ).readlines()
111    if len(ii) == 0:
112      print 'WARNING[003]: Failed to capture xmllint response'
113      print cmd
114      self.ok = False
115      self._clear_ch03()
116      return
117    if string.find(ii[0],'validates') != -1:
118      print 'Sample XML validated'
119      self.ok = True
120      self._clear_ch03()
121    else:
122      print 'Sample XML failed to validate'
123      print cmd
124      self.ok = False
125    return
126   
127all &= check1('Suite 1 (dreq module)').ok
128all &= check2('Suite 2 (xmllint)').ok
129
130if all:
131  print 'ALL CHECK PASSED'
Note: See TracBrowser for help on using the repository browser.