|
@@ -35,7 +35,7 @@ UNDERLINE = '\033[4m'
|
35
|
35
|
ARG_CLEAN = 'clean'
|
36
|
36
|
ARG_RUN = 'run'
|
37
|
37
|
ARG_FINALISE = 'finalise'
|
38
|
|
-ARG_PDF = 'pdf'
|
|
38
|
+ARG_TEX = 'tex'
|
39
|
39
|
ARG_STATUS = 'status'
|
40
|
40
|
ARG_COPY = 'copy'
|
41
|
41
|
ARG_RELEASE = 'release'
|
|
@@ -92,7 +92,7 @@ class coverage_info(list):
|
92
|
92
|
f[self.KEY_LINE_COVERAGE] = float(c.attributes['line-rate'].value) * 100.
|
93
|
93
|
try:
|
94
|
94
|
f[self.KEY_BRANCH_COVERAGE] = float(p.attributes['branch-rate'].value) * 100.
|
95
|
|
- except:
|
|
95
|
+ except Exception:
|
96
|
96
|
f[self.KEY_BRANCH_COVERAGE] = None
|
97
|
97
|
f[self.KEY_FRAGMENTS] = []
|
98
|
98
|
last_hit = None
|
|
@@ -193,23 +193,46 @@ def module_uid(path):
|
193
|
193
|
|
194
|
194
|
|
195
|
195
|
def unittest(options, args, unittest_folder):
|
196
|
|
- if ARG_CLEAN in args:
|
197
|
|
- unittest_init(unittest_folder)
|
198
|
|
- elif ARG_RUN in args:
|
199
|
|
- unittest_run(unittest_folder, options)
|
200
|
|
- elif ARG_FINALISE in args:
|
|
196
|
+ if 'release_testcases' in args:
|
|
197
|
+ unittest_release_testcases(unittest_folder)
|
|
198
|
+ elif 'clean' in args:
|
|
199
|
+ unittest_clean(unittest_folder)
|
|
200
|
+ elif 'prepare' in args:
|
|
201
|
+ unittest_prepare(unittest_folder)
|
|
202
|
+ elif 'testrun' in args:
|
|
203
|
+ unittest_testrun(unittest_folder, options)
|
|
204
|
+ elif 'finalise' in args:
|
201
|
205
|
unittest_finalise(unittest_folder)
|
202
|
|
- elif ARG_PDF in args:
|
203
|
|
- unittest_pdf(unittest_folder)
|
204
|
|
- elif ARG_STATUS in args:
|
|
206
|
+ elif 'status' in args:
|
205
|
207
|
unittest_status(unittest_folder)
|
206
|
|
- elif ARG_COPY in args:
|
207
|
|
- unittest_copy(unittest_folder)
|
208
|
|
- elif ARG_RELEASE in args:
|
209
|
|
- unittest_release(unittest_folder)
|
|
208
|
+ elif 'publish' in args:
|
|
209
|
+ unittest_publish(unittest_folder)
|
210
|
210
|
|
211
|
211
|
|
212
|
|
-def unittest_init(unittest_folder):
|
|
212
|
+def unittest_release_testcases(unittest_folder):
|
|
213
|
+ unittest_uid = module_uid(os.path.join(unittest_folder, 'src', 'tests'))
|
|
214
|
+ config_file = os.path.join(unittest_folder, 'src', 'config.py')
|
|
215
|
+ print_header('Releasing unittest')
|
|
216
|
+ with open(config_file, 'r') as fh:
|
|
217
|
+ conf_file = fh.read()
|
|
218
|
+ print_action('Setting release_unittest_version = %s in %s' % (unittest_uid, config_file))
|
|
219
|
+ with open(config_file, 'w') as fh:
|
|
220
|
+ for line in conf_file.splitlines():
|
|
221
|
+ if line.startswith('release_unittest_version'):
|
|
222
|
+ fh.write("release_unittest_version = '%s'\n" % unittest_uid)
|
|
223
|
+ else:
|
|
224
|
+ fh.write(line + '\n')
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+def unittest_clean(unittest_folder):
|
|
228
|
+ print_header('Cleaning up...')
|
|
229
|
+ print_action('Testresults from last testrun')
|
|
230
|
+ for fn in os.listdir(unittest_filename(unittest_folder, '')):
|
|
231
|
+ remove_file(unittest_filename(unittest_folder, fn))
|
|
232
|
+ remove_file(unittest_filename(unittest_folder, FILES['coverage-xml']))
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+def unittest_prepare(unittest_folder):
|
213
|
236
|
config = imp.load_source('', os.path.join(unittest_folder, 'src', 'config.py'))
|
214
|
237
|
#
|
215
|
238
|
print_header("Initiating unittest for first testrun...")
|
|
@@ -217,11 +240,6 @@ def unittest_init(unittest_folder):
|
217
|
240
|
print_action('Creating outpout folder %s' % unittest_filename(unittest_folder, ''))
|
218
|
241
|
fstools.mkdir(unittest_filename(unittest_folder, ''))
|
219
|
242
|
#
|
220
|
|
- print_action('Cleaning up data from last testrun')
|
221
|
|
- for fn in os.listdir(unittest_filename(unittest_folder, '')):
|
222
|
|
- remove_file(unittest_filename(unittest_folder, fn))
|
223
|
|
- remove_file(unittest_filename(unittest_folder, FILES['coverage-xml']))
|
224
|
|
- #
|
225
|
243
|
print_action('Creating unittest data-collection: %s' % unittest_filename(unittest_folder, FILES['data-collection']))
|
226
|
244
|
#
|
227
|
245
|
system_info = {}
|
|
@@ -268,7 +286,7 @@ def unittest_init(unittest_folder):
|
268
|
286
|
fh.write(json.dumps(data_collection, indent=4, sort_keys=True))
|
269
|
287
|
|
270
|
288
|
|
271
|
|
-def unittest_run(unittest_folder, options):
|
|
289
|
+def unittest_testrun(unittest_folder, options):
|
272
|
290
|
tests = imp.load_source('', os.path.join(unittest_folder, 'src', 'tests', '__init__.py'))
|
273
|
291
|
config = imp.load_source('', os.path.join(unittest_folder, 'src', 'config.py'))
|
274
|
292
|
#
|
|
@@ -305,12 +323,12 @@ def unittest_run(unittest_folder, options):
|
305
|
323
|
def unittest_finalise(unittest_folder):
|
306
|
324
|
config = imp.load_source('', os.path.join(unittest_folder, 'src', 'config.py'))
|
307
|
325
|
#
|
308
|
|
- print_action('Adding Testrun data to %s' % unittest_filename(unittest_folder, FILES['data-collection']))
|
|
326
|
+ print_header("Adding Requirement information")
|
|
327
|
+ #
|
|
328
|
+ print_action('Loading Testrun data from %s' % unittest_filename(unittest_folder, FILES['data-collection']))
|
309
|
329
|
with open(unittest_filename(unittest_folder, FILES['data-collection']), 'r') as fh:
|
310
|
330
|
data_collection = json.loads(fh.read())
|
311
|
331
|
#
|
312
|
|
- print_header("Adding Requirement information")
|
313
|
|
- #
|
314
|
332
|
data_collection['lost_souls'] = {}
|
315
|
333
|
#
|
316
|
334
|
print_action("Adding Lost Requirement Soul")
|
|
@@ -340,16 +358,14 @@ def unittest_finalise(unittest_folder):
|
340
|
358
|
data_collection[UNITTEST_KEY_COVERAGE_INFO] = coverage_info(unittest_filename(unittest_folder, 'coverage.xml'), os.path.dirname(config.lib_path))
|
341
|
359
|
with open(unittest_filename(unittest_folder, FILES['data-collection']), 'w') as fh:
|
342
|
360
|
fh.write(json.dumps(data_collection, indent=4, sort_keys=True))
|
343
|
|
-
|
344
|
|
-
|
345
|
|
-def unittest_pdf(unittest_folder):
|
346
|
|
- print_header("Creating PDF-Report of Unittest")
|
|
361
|
+ #
|
|
362
|
+ print_header("Creating LaTeX-Report of Unittest")
|
347
|
363
|
print_action('Loading Testrun data from %s' % unittest_filename(unittest_folder, FILES['data-collection']))
|
348
|
364
|
with open(unittest_filename(unittest_folder, FILES['data-collection']), 'r') as fh:
|
349
|
365
|
data_collection = json.loads(fh.read())
|
350
|
366
|
|
351
|
367
|
if jinja2 is None:
|
352
|
|
- print_action('You need to install jinja2 to create a PDF-Report!', FAIL)
|
|
368
|
+ print_action('You need to install jinja2 to create a LaTeX-Report!', FAIL)
|
353
|
369
|
else:
|
354
|
370
|
fn = unittest_filename(unittest_folder, FILES['tex-report'])
|
355
|
371
|
print_action('Creating LaTeX-File %s' % fn)
|
|
@@ -360,16 +376,25 @@ def unittest_pdf(unittest_folder):
|
360
|
376
|
jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path))
|
361
|
377
|
template = jenv.get_template(template_filename)
|
362
|
378
|
fh.write(template.render(data=data_collection))
|
363
|
|
- print_action('Creating PDF %s' % unittest_filename(unittest_folder, 'unittest.pdf'))
|
364
|
|
- for i in range(3):
|
365
|
|
- sys.stdout.write(' Starting run %d/3 of pdflatex... ' % (i + 1))
|
366
|
|
- sys.stdout.flush()
|
367
|
|
- exit_value = os.system("pdflatex -interaction nonstopmode --output-directory %(path)s %(path)s/unittest.tex 1> /dev/null" % {'path': unittest_filename(unittest_folder, '')})
|
368
|
|
- if exit_value != 0:
|
369
|
|
- print(FAIL + 'FAILED' + ENDC)
|
370
|
|
- break
|
371
|
|
- else:
|
372
|
|
- print(OKGREEN + 'SUCCESS' + ENDC)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+def unittest_publish(unittest_folder):
|
|
382
|
+ config = imp.load_source('', os.path.join(unittest_folder, 'src', 'config.py'))
|
|
383
|
+ #
|
|
384
|
+ print_header('Copy unittest files to library')
|
|
385
|
+ target_folder = os.path.join(config.lib_path, '_testresults_')
|
|
386
|
+ print_action('Copying Unittest Files to %s' % target_folder)
|
|
387
|
+ if not os.path.exists(target_folder):
|
|
388
|
+ print_info('Creating folder %s' % target_folder)
|
|
389
|
+ fstools.mkdir(target_folder)
|
|
390
|
+ else:
|
|
391
|
+ for fn in os.listdir(target_folder):
|
|
392
|
+ remove_file(os.path.join(target_folder, fn))
|
|
393
|
+ for fn in REPORT_FILES:
|
|
394
|
+ src = unittest_filename(unittest_folder, fn)
|
|
395
|
+ dst = os.path.join(target_folder, fn)
|
|
396
|
+ print_info('copying %s -> %s' % (src, dst))
|
|
397
|
+ shutil.copyfile(src, dst)
|
373
|
398
|
|
374
|
399
|
|
375
|
400
|
def unittest_status(unittest_folder):
|
|
@@ -438,37 +463,3 @@ def unittest_status(unittest_folder):
|
438
|
463
|
print_info("FAILED", FAIL)
|
439
|
464
|
else:
|
440
|
465
|
print_info("SUCCESS", OKGREEN)
|
441
|
|
-
|
442
|
|
-
|
443
|
|
-def unittest_copy(unittest_folder):
|
444
|
|
- config = imp.load_source('', os.path.join(unittest_folder, 'src', 'config.py'))
|
445
|
|
- #
|
446
|
|
- print_header('Copy unittest files to library')
|
447
|
|
- target_folder = os.path.join(config.lib_path, '_testresults_')
|
448
|
|
- print_action('Copying Unittest Files to %s' % target_folder)
|
449
|
|
- if not os.path.exists(target_folder):
|
450
|
|
- print_info('Creating folder %s' % target_folder)
|
451
|
|
- fstools.mkdir(target_folder)
|
452
|
|
- else:
|
453
|
|
- for fn in os.listdir(target_folder):
|
454
|
|
- remove_file(os.path.join(target_folder, fn))
|
455
|
|
- for fn in REPORT_FILES:
|
456
|
|
- src = unittest_filename(unittest_folder, fn)
|
457
|
|
- dst = os.path.join(target_folder, fn)
|
458
|
|
- print_info('copying %s -> %s' % (src, dst))
|
459
|
|
- shutil.copyfile(src, dst)
|
460
|
|
-
|
461
|
|
-
|
462
|
|
-def unittest_release(unittest_folder):
|
463
|
|
- unittest_uid = module_uid(os.path.join(unittest_folder, 'src', 'tests'))
|
464
|
|
- config_file = os.path.join(unittest_folder, 'src', 'config.py')
|
465
|
|
- print_header('Releasing unittest')
|
466
|
|
- with open(config_file, 'r') as fh:
|
467
|
|
- conf_file = fh.read()
|
468
|
|
- print_action('Setting release_unittest_version = %s in %s' % (unittest_uid, config_file))
|
469
|
|
- with open(config_file, 'w') as fh:
|
470
|
|
- for line in conf_file.splitlines():
|
471
|
|
- if line.startswith('release_unittest_version'):
|
472
|
|
- fh.write("release_unittest_version = '%s'\n" % unittest_uid)
|
473
|
|
- else:
|
474
|
|
- fh.write(line + '\n')
|