1 | from __init__ import DOC_DIR |
---|
2 | import string, os, sys, collections |
---|
3 | |
---|
4 | try: |
---|
5 | import pkgutil |
---|
6 | l = pkgutil.iter_modules() |
---|
7 | ll = map( lambda x: x[1], l ) |
---|
8 | pkgutilFailed=False |
---|
9 | except: |
---|
10 | pkgutilFailed=True |
---|
11 | print ( 'Failed to load pkgutil .. more limited tests on available modules will be done' ) |
---|
12 | ll = [] |
---|
13 | |
---|
14 | requiredModules = ['xml'] |
---|
15 | confirmed = [] |
---|
16 | installFailed = [] |
---|
17 | missingLib = [] |
---|
18 | for x in requiredModules: |
---|
19 | if x in ll or pkgutilFailed: |
---|
20 | try: |
---|
21 | __import__(x) |
---|
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: %s' % str(missingLib) ) |
---|
33 | if len(installFailed) > 0: |
---|
34 | print ( 'LIBRARIES PRESENT BUT FAILED TO INSTALL:%s' % str(missingLib) ) |
---|
35 | all = False |
---|
36 | exit(0) |
---|
37 | else: |
---|
38 | print ( 'Required libraries present' ) |
---|
39 | all = True |
---|
40 | |
---|
41 | import inspect |
---|
42 | class checkbase(object): |
---|
43 | def __init__(self,lab): |
---|
44 | self.lab = lab |
---|
45 | self.ok = True |
---|
46 | self.entryPoint = sys.argv[0].split( '/' )[-1] |
---|
47 | ##if os.path.isdir( 'out' ): |
---|
48 | ##self.docdir = 'out' |
---|
49 | ##elif os.path.isdir( 'docs' ): |
---|
50 | ##self.docdir = 'docs' |
---|
51 | ##else: |
---|
52 | ##assert False, 'Document directory not found' |
---|
53 | |
---|
54 | #document directory |
---|
55 | self.docdir = DOC_DIR |
---|
56 | #schema location |
---|
57 | self.schema = '%s/dreq2Schema.xsd' % self.docdir |
---|
58 | #sample xml location |
---|
59 | self.sampleXml = '%s/dreq2Sample.xml' % self.docdir |
---|
60 | #definition document xml location |
---|
61 | self.defnXml = '%s/dreq2Defn.xml' % self.docdir |
---|
62 | |
---|
63 | ml = inspect.getmembers( self, predicate=inspect.ismethod ) |
---|
64 | ok = True |
---|
65 | for tag,m in ml: |
---|
66 | if tag[:3] == '_ch': |
---|
67 | try: |
---|
68 | self.ok = False |
---|
69 | m() |
---|
70 | ok &= self.ok |
---|
71 | except: |
---|
72 | print ( 'Failed to complete check %s' % tag ) |
---|
73 | raise |
---|
74 | if ok: |
---|
75 | print ( '%s: All checks passed' % lab ) |
---|
76 | else: |
---|
77 | print ( '%s: Errors detected' % lab ) |
---|
78 | |
---|
79 | class check1(checkbase): |
---|
80 | def _ch01_importDreq(self): |
---|
81 | import dreq |
---|
82 | print ( 'Dreq software import checked' ) |
---|
83 | self.ok = True |
---|
84 | |
---|
85 | def _ch02_importSample(self): |
---|
86 | import dreq |
---|
87 | self.dq = dreq.loadDreq( manifest='%s/dreqManifest.txt' % self.docdir ) |
---|
88 | print ( 'Dreq sample load checked' ) |
---|
89 | self.ok = True |
---|
90 | |
---|
91 | def _ch03_linkCheck(self): |
---|
92 | nn = 0 |
---|
93 | import dreq |
---|
94 | self.dq = dreq.loadDreq( manifest='%s/dreqManifest.txt' % self.docdir ) |
---|
95 | for section in self.dq.coll : |
---|
96 | ks=[k for k in self.dq.coll[section].attDefn.keys() if self.dq.coll[section].attDefn[k].useClass == 'internalLink'] |
---|
97 | nerr = 0 |
---|
98 | cc = collections.defaultdict( int ) |
---|
99 | for i in self.dq.coll[section].items: |
---|
100 | for k in ks : |
---|
101 | if k in i.__dict__: |
---|
102 | if i.__dict__[k] not in self.dq.inx.uid: |
---|
103 | nerr += 1 |
---|
104 | cc[k] += 1 |
---|
105 | print ('Bad link found: section: %s: %s %s' % (section, k, i.__dict__[k]) ) |
---|
106 | if nerr > 0: |
---|
107 | msg = '' |
---|
108 | for k in cc: |
---|
109 | msg += '%s: %s; ' % (k,cc[k]) |
---|
110 | print ( 'Section %s: bad links: %s %s' % (section,nerr,msg) ) |
---|
111 | nn += nerr |
---|
112 | ##print section, ks, nerr |
---|
113 | if nn == 0: |
---|
114 | print ( 'Dreq links checked' ) |
---|
115 | self.ok = nn == 0 |
---|
116 | |
---|
117 | class check2(checkbase): |
---|
118 | |
---|
119 | def _clear_ch03(self): |
---|
120 | os.unlink( '.simpleCheck_check2_err.txt' ) |
---|
121 | os.unlink( '.simpleCheck_check2.txt' ) |
---|
122 | |
---|
123 | def _clear_ch04(self): |
---|
124 | os.unlink( '.simpleCheck_check2_err.txt' ) |
---|
125 | os.unlink( '.simpleCheck_check2.txt' ) |
---|
126 | |
---|
127 | def _ch04_checkCmd(self): |
---|
128 | import os |
---|
129 | if self.entryPoint == 'drq': |
---|
130 | cmd = 'drq' |
---|
131 | else: |
---|
132 | cmd = 'python dreqCmdl.py' |
---|
133 | |
---|
134 | os.popen( '%s -v 2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' % cmd ).readlines() |
---|
135 | |
---|
136 | ii = open( '.simpleCheck_check2_err.txt' ).readlines() |
---|
137 | if len(ii) > 0: |
---|
138 | print ( 'WARNING[003]: failed to get version with command line call' ) |
---|
139 | self.ok = False |
---|
140 | self._clear_ch04() |
---|
141 | return |
---|
142 | |
---|
143 | ii = open( '.simpleCheck_check2.txt' ).readlines() |
---|
144 | if len(ii) < 1: |
---|
145 | print ( 'WARNING[004]: failed to get version with command line call' ) |
---|
146 | self.ok = False |
---|
147 | self._clear_ch04() |
---|
148 | return |
---|
149 | |
---|
150 | self.ok = True |
---|
151 | return |
---|
152 | |
---|
153 | def _ch03_checkXML(self): |
---|
154 | import os |
---|
155 | os.popen( 'which xmllint 2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' ).readlines() |
---|
156 | ii = open( '.simpleCheck_check2_err.txt' ).readlines() |
---|
157 | if len(ii) > 0: |
---|
158 | print ( 'WARNING[001]: failed to detect xmllint command line program' ) |
---|
159 | print ( 'optional checks omitted' ) |
---|
160 | self.ok = False |
---|
161 | self._clear_ch03() |
---|
162 | return |
---|
163 | ii = open( '.simpleCheck_check2.txt' ).readlines() |
---|
164 | if len(ii) < 1: |
---|
165 | print ( 'WARNING[002]: failed to detect xmllint command line program' ) |
---|
166 | print ( 'Optional checks omitted' ) |
---|
167 | self.ok = False |
---|
168 | self._clear_ch03() |
---|
169 | return |
---|
170 | |
---|
171 | cmd = 'xmllint --noout --schema %s %s 2> .simpleCheck_check2_err.txt 1>.simpleCheck_check2.txt' % (self.schema,self.sampleXml) |
---|
172 | os.popen( cmd ).readlines() |
---|
173 | ii = open( '.simpleCheck_check2_err.txt' ).readlines() |
---|
174 | if len(ii) == 0: |
---|
175 | print ( 'WARNING[003]: Failed to capture xmllint response' ) |
---|
176 | print ( cmd ) |
---|
177 | self.ok = False |
---|
178 | self._clear_ch03() |
---|
179 | return |
---|
180 | if ii[0].find('validates') != -1: |
---|
181 | print ( 'Sample XML validated' ) |
---|
182 | self.ok = True |
---|
183 | self._clear_ch03() |
---|
184 | else: |
---|
185 | print ( 'Sample XML failed to validate' ) |
---|
186 | print ( cmd ) |
---|
187 | self.ok = False |
---|
188 | return |
---|
189 | |
---|
190 | all &= check1('Suite 1 (dreq module)').ok |
---|
191 | all &= check2('Suite 2 (xmllint & command line)').ok |
---|
192 | |
---|
193 | if all: |
---|
194 | print ( 'ALL CHECK PASSED' ) |
---|