source: CMIP6dreq/trunk/src/simpleCheck.py @ 394

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

miscellaneous cleaning for 01.beta

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    ml = inspect.getmembers( self, predicate=inspect.ismethod ) 
48    ok = True
49    for tag,m in ml:
50      if tag[:3] == '_ch':
51        try:
52          self.ok = False
53          m()
54          ok &= self.ok
55        except:
56          print 'Failed to complete check %s' % tag
57    if ok:
58      print '%s: All checks passed' % lab
59    else: 
60      print '%s: Errors detected' % lab
61       
62class check1(checkbase):
63  def _ch01_importDreq(self):
64    import dreq
65    print 'Dreq software import checked'
66    self.ok = True
67
68  def _ch02_importSample(self):
69    import dreq
70    rq = dreq.loadDreq( dreqXML='out/dreq2Sample.xml',configdoc='out/dreq2Defn.xml' )
71    print 'Dreq sample load checked'
72    self.ok = True
73
74class check2(checkbase):
75
76  def _clear_ch03(self):
77    os.unlink( '.simpleCheck_check2_err.txt' )
78    os.unlink( '.simpleCheck_check2.txt' )
79
80  def _ch03_checkXML(self):
81    import os
82    os.popen( 'which xmllint 2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' ).readlines()
83    ii = open( '.simpleCheck_check2_err.txt' ).readlines()
84    if len(ii) > 0:
85      print 'WARNING[001]: failed to detect xmllint command line program'
86      print 'optional checks omitted'
87      self.ok = False
88      self._clear_ch03()
89      return
90    ii = open( '.simpleCheck_check2.txt' ).readlines()
91    if len(ii) < 1:
92      print 'WARNING[002]: failed to detect xmllint command line program'
93      print 'optional checks omitted'
94      self.ok = False
95      self._clear_ch03()
96      return
97
98#schema location
99    schema = '../docs/dreq2Schema.xsd'
100#xml location
101    xml = '../docs/dreq2Sample.xml'
102
103    cmd = 'xmllint --noout --schema %s %s  2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' % (schema,xml) 
104    os.popen( cmd ).readlines()
105    ii = open( '.simpleCheck_check2_err.txt' ).readlines()
106    if len(ii) == 0:
107      print 'WARNING[003]: Failed to capture xmllint response'
108      print cmd
109      self.ok = False
110      self._clear_ch03()
111      return
112    if string.find(ii[0],'validates') != -1:
113      print 'Sample XML validated'
114      self.ok = True
115      self._clear_ch03()
116    else:
117      print 'Sample XML failed to validate'
118      print cmd
119      self.ok = False
120    return
121   
122all &= check1('Suite 1 (dreq module)').ok
123all &= check2('Suite 2 (xmllint)').ok
124
125if all:
126  print 'ALL CHECK PASSED'
Note: See TracBrowser for help on using the repository browser.