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