1 | |
---|
2 | try: |
---|
3 | import pkgutil |
---|
4 | l = pkgutil.iter_modules() |
---|
5 | ll = map( lambda x: x[1], l ) |
---|
6 | pkgutilFailed=False |
---|
7 | except: |
---|
8 | pkgutilFailed=True |
---|
9 | print 'Failed to load pkgutil .. more limited tests on available modules will be done' |
---|
10 | ll = [] |
---|
11 | |
---|
12 | |
---|
13 | requiredModules = ['xml','string','collections','os'] |
---|
14 | confirmed = [] |
---|
15 | installFailed = [] |
---|
16 | missingLib = [] |
---|
17 | for 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 | |
---|
29 | if 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) |
---|
37 | else: |
---|
38 | print 'Required libraries present' |
---|
39 | all = True |
---|
40 | |
---|
41 | |
---|
42 | import inspect |
---|
43 | class 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 | |
---|
62 | class 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='../docs/dreqSample.xml',configdoc='../docs/dreqDefn.xml' ) |
---|
71 | print 'Dreq sample load checked' |
---|
72 | self.ok = True |
---|
73 | |
---|
74 | class 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 | schema = '../docs/dreqSchema.xsd' |
---|
98 | xml = '../docs/dreqSample.xml' |
---|
99 | |
---|
100 | cmd = 'xmllint --noout --schema %s %s 2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' % (schema,xml) |
---|
101 | os.popen( cmd ).readlines() |
---|
102 | ii = open( '.simpleCheck_check2_err.txt' ).readlines() |
---|
103 | if len(ii) == 0: |
---|
104 | print 'WARNING[003]: Failed to capture xmllint response' |
---|
105 | print cmd |
---|
106 | self.ok = False |
---|
107 | self._clear_ch03() |
---|
108 | return |
---|
109 | if string.find(ii[0],'validates') != -1: |
---|
110 | print 'Sample XML validated' |
---|
111 | self.ok = True |
---|
112 | else: |
---|
113 | print 'Sample XML failed to validate' |
---|
114 | self.ok = False |
---|
115 | self._clear_ch03() |
---|
116 | return |
---|
117 | |
---|
118 | all &= check1('Suite 1 (dreq module)').ok |
---|
119 | all &= check2('Suite 2 (xmllint)').ok |
---|
120 | |
---|
121 | if all: |
---|
122 | print 'ALL CHECK PASSED' |
---|