Quellcode durchsuchen

Changed unittest execution from script to Makefile

master
Dirk Alders vor 3 Jahren
Ursprung
Commit
a70a6c432b
4 geänderte Dateien mit 151 neuen und 124 gelöschten Zeilen
  1. 64
    73
      run.py
  2. 81
    0
      scripts/Makefile
  3. 6
    4
      scripts/unittest.py
  4. 0
    47
      scripts/unittest.sh

+ 64
- 73
run.py Datei anzeigen

@@ -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')

+ 81
- 0
scripts/Makefile Datei anzeigen

@@ -0,0 +1,81 @@
1
+COV2_CMD=python2-coverage
2
+COV3_CMD=python3-coverage
3
+PYT2_CMD=python2
4
+PYT3_CMD=python3
5
+PDF_CMD=xdg-open
6
+
7
+OUTDIR=testresults
8
+TEXFILE=$(OUTDIR)/unittest.tex
9
+PDFFILE=$(OUTDIR)/unittest.pdf
10
+
11
+.PHONY: all help release full short smoke single testrun_full testrun_short testrun_smoke testrun_single coverage_analysis finalise status compile release_testcases publish view clean
12
+
13
+all: full
14
+
15
+help:
16
+	@echo "make [target]"
17
+	@echo "  Here is a list of the most helpfull targets:"
18
+	@echo "    - release: Release the testcases, creates a pdf ducument including all testcases and copy testdata to the module"
19
+	@echo "    ----------------------------------------------------------------------------------------------------------------"
20
+	@echo "    - full: Create a pdf ducument including all testcases"
21
+	@echo "    - short: Create a pdf ducument including most testcases"
22
+	@echo "    - smoke: Create a pdf ducument including some testcases"
23
+	@echo "    - single: Create a pdf ducument including one testcases"
24
+	@echo "    ----------------------------------------------------------------------------------------------------------------"
25
+	@echo "    - testrun_full: Run all testcases"
26
+	@echo "    - testrun_short: Run most testcases"
27
+	@echo "    - testrun_smoke: Run some testcases"
28
+	@echo "    - testrun_single: Run one testcases"
29
+
30
+release: release_testcases full publish
31
+full: clean prepare testrun_full coverage_analysis finalise compile status
32
+short: clean prepare testrun_short coverage_analysis finalise compile status
33
+smoke: clean prepare testrun_smoke coverage_analysis finalise compile status
34
+single: clean prepare testrun_single coverage_analysis finalise compile status
35
+
36
+clean:
37
+	@$(PYT3_CMD) src/unittest/scripts/unittest.py clean
38
+	@echo "\e[1m  * Collected coverage information\e[0m"
39
+	@$(COV3_CMD) erase
40
+
41
+release_testcases:
42
+	@$(PYT3_CMD) src/unittest/scripts/unittest.py release_testcases
43
+
44
+prepare:
45
+	@$(PYT3_CMD) src/unittest/scripts/unittest.py prepare
46
+
47
+testrun_full:
48
+	@$(COV2_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e full
49
+	@$(COV3_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e full
50
+
51
+testrun_short:
52
+	@$(COV2_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e short
53
+	@$(COV3_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e short
54
+
55
+testrun_smoke:
56
+	@$(COV2_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e smoke
57
+	@$(COV3_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e smoke
58
+
59
+testrun_single:
60
+
61
+	@$(COV2_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e single
62
+	@$(COV3_CMD) run -a --branch --source=`$(PYT3_CMD) src/config.py -p` src/unittest/scripts/unittest.py testrun -e single
63
+
64
+coverage_analysis:
65
+	@echo "\e[1m\e[93mCreating Coverage-XML-File: $(pwd)/testresults/coverage.xml\e[0m"
66
+	@$(COV3_CMD) xml -o testresults/coverage.xml
67
+
68
+finalise:
69
+	@$(PYT3_CMD) src/unittest/scripts/unittest.py finalise
70
+
71
+compile:
72
+	@latexmk -pdf -quiet -pdflatex="pdflatex -interaction=nonstopmode" -output-directory=$(OUTDIR) -use-make $(TEXFILE) > /dev/null
73
+
74
+status:
75
+	@$(PYT3_CMD) src/unittest/scripts/unittest.py status
76
+
77
+publish:
78
+	@$(PYT3_CMD) src/unittest/scripts/unittest.py publish
79
+
80
+view:
81
+	@$(PDF_CMD) $(PDFFILE)

+ 6
- 4
scripts/unittest.py Datei anzeigen

@@ -1,11 +1,13 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: utf-8 -*-
3 3
 #
4
-import sys
5
-sys.path.insert(0, 'src')
6
-
7 4
 import optparse
8 5
 import os
6
+import sys
7
+
8
+BASEPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
9
+sys.path.insert(0, os.path.join(BASEPATH, 'src'))
10
+
9 11
 import report
10 12
 import tests
11 13
 import unittest
@@ -17,4 +19,4 @@ parser.add_option("-e", "--execution-level", dest="execution_level", default="fu
17 19
 if report.TCEL_REVERSE_NAMED.get(tests.execution_level, report.TCEL_FULL) < report.TCEL_REVERSE_NAMED.get(options.execution_level, report.TCEL_FULL):
18 20
     options.execution_level = tests.execution_level
19 21
 
20
-unittest.run.unittest(options, args, os.path.abspath(os.path.join(os.path.dirname(__file__))))
22
+unittest.run.unittest(options, args, BASEPATH)

+ 0
- 47
scripts/unittest.sh Datei anzeigen

@@ -1,47 +0,0 @@
1
-#!/bin/bash
2
-
3
-#
4
-# Set commands depending on distribution
5
-#
6
-. /etc/os-release
7
-# python2
8
-if [[ "$ID" == "arch" || "$ID" == "manjaro" || "$ID_LIKE" == *"opensuse"*  || "$ID" == "solus" ]]; then
9
-    COV2_CMD="coverage2"
10
-    PYT2_CMD="python2"
11
-else
12
-    COV2_CMD="python2-coverage"
13
-    PYT2_CMD="python2"
14
-fi
15
-# python3
16
-if [[ "$ID" == "arch" || "$ID" == "manjaro" || "$ID_LIKE" == *"opensuse"* || "$ID" == "solus" ]]; then
17
-    COV3_CMD="coverage3"
18
-    PYT3_CMD="python3"
19
-else
20
-    COV3_CMD="python3-coverage"
21
-    PYT3_CMD="python3"
22
-fi
23
-# pdf viewer
24
-PDF_CMD="xdg-open"
25
-
26
-if [[ $# -eq 0 || ($# -eq 2 && $1 == '-e') ]]; then
27
-	#
28
-	# Unittest Flow
29
-	#
30
-	$PYT3_CMD unittest.py clean
31
-	echo -e "\e[1m  * Erasing collected coverage information\e[0m"
32
-	$COV2_CMD erase
33
-	$COV2_CMD run -a --branch --source=$($PYT3_CMD src/config.py -p) unittest.py run $*
34
-	$COV3_CMD run -a --branch --source=$($PYT3_CMD src/config.py -p) unittest.py run $*
35
-	echo -e "\e[1m\e[93mCreating Coverage-XML-File: $(pwd)/testresults/coverage.xml\e[0m"
36
-	$COV3_CMD xml -o testresults/coverage.xml
37
-	$PYT3_CMD unittest.py finalise
38
-	$PYT3_CMD unittest.py status
39
-	$PYT3_CMD unittest.py pdf
40
-	$PDF_CMD testresults/unittest.pdf
41
-else
42
-	$PYT3_CMD unittest.py $*
43
-fi
44
-
45
-
46
-exit 0
47
-

Laden…
Abbrechen
Speichern