From 279a524eb67cdfd305e8f93373652f7f5ddded3a Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Tue, 28 Jan 2020 20:05:01 +0100 Subject: [PATCH] Unittest adaptions to improve project structure --- run.py | 12 ++++++++---- scripts/unittest.py | 20 +++++++++++++++++++ scripts/unittest.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++ unittest_flow.sh | 39 ------------------------------------- 4 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 scripts/unittest.py create mode 100755 scripts/unittest.sh delete mode 100755 unittest_flow.sh diff --git a/run.py b/run.py index 0761351..a7ddc18 100644 --- a/run.py +++ b/run.py @@ -273,7 +273,7 @@ def unittest_run(unittest_folder, options): execution_level = report.TCEL_REVERSE_NAMED.get(options.execution_level, report.TCEL_FULL) # if sys.version_info.major in config.lib.__INTERPRETER__: - print_header("Running Unittest with %s" % interpreter_version) + print_header("Running \"%s\" Unittest with %s" % (options.execution_level, interpreter_version)) print_action('Loading Testrun data from %s' % unittest_filename(unittest_folder, FILES['data-collection'])) with open(unittest_filename(unittest_folder, FILES['data-collection']), 'r') as fh: data_collection = json.loads(fh.read()) @@ -456,11 +456,15 @@ def unittest_copy(unittest_folder): def unittest_release(unittest_folder): - with open(os.path.join(unittest_folder, 'src', 'config.py'), 'r') as fh: + unittest_uid = module_uid(os.path.join(unittest_folder, 'src', 'tests')) + config_file = os.path.join(unittest_folder, 'src', 'config.py') + print_header('Releasing unittest') + with open(config_file, 'r') as fh: conf_file = fh.read() - with open(os.path.join(unittest_folder, 'src', 'config.py'), 'w') as fh: + print_action('Setting release_unittest_version = %s in %s' % (unittest_uid, config_file)) + with open(config_file, 'w') as fh: for line in conf_file.splitlines(): if line.startswith('release_unittest_version'): - fh.write("release_unittest_version = '%s'\n" % module_uid(os.path.join(unittest_folder, 'src', 'tests'))) + fh.write("release_unittest_version = '%s'\n" % unittest_uid) else: fh.write(line + '\n') diff --git a/scripts/unittest.py b/scripts/unittest.py new file mode 100644 index 0000000..66d2e82 --- /dev/null +++ b/scripts/unittest.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +import sys +sys.path.insert(0, 'src') + +import optparse +import os +import report +import tests +import unittest + +parser = optparse.OptionParser("usage: %prog [clean|run|coverage|pdf|copy|release]") +parser.add_option("-e", "--execution-level", dest="execution_level", default="full", help="sets the execution level [full | short | smoke | single]") +(options, args) = parser.parse_args() + +if report.TCEL_REVERSE_NAMED.get(tests.execution_level, report.TCEL_FULL) < report.TCEL_REVERSE_NAMED.get(options.execution_level, report.TCEL_FULL): + options.execution_level = tests.execution_level + +unittest.run.unittest(options, args, os.path.abspath(os.path.join(os.path.dirname(__file__)))) diff --git a/scripts/unittest.sh b/scripts/unittest.sh new file mode 100755 index 0000000..7ced627 --- /dev/null +++ b/scripts/unittest.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# +# Set commands depending on distribution +# +. /etc/os-release +# python2 +if [[ "$ID" == "arch" || "$ID" == "manjaro" || "$ID_LIKE" == *"opensuse"* || "$ID" == "solus" ]]; then + COV2_CMD="coverage2" + PYT2_CMD="python2" +else + COV2_CMD="python2-coverage" + PYT2_CMD="python2" +fi +# python3 +if [[ "$ID" == "arch" || "$ID" == "manjaro" || "$ID_LIKE" == *"opensuse"* || "$ID" == "solus" ]]; then + COV3_CMD="coverage3" + PYT3_CMD="python3" +else + COV3_CMD="python3-coverage" + PYT3_CMD="python3" +fi +# pdf viewer +PDF_CMD="xdg-open" + +if [[ $# -eq 0 || ($# -eq 2 && $1 == '-e') ]]; then + # + # Unittest Flow + # + $PYT3_CMD unittest.py clean + echo -e "\e[1m * Erasing collected coverage information\e[0m" + $COV2_CMD erase + $COV2_CMD run -a --branch --source=$($PYT3_CMD src/config.py -p) unittest.py run $* + $COV3_CMD run -a --branch --source=$($PYT3_CMD src/config.py -p) unittest.py run $* + echo -e "\e[1m\e[93mCreating Coverage-XML-File: $(pwd)/testresults/coverage.xml\e[0m" + $COV3_CMD xml -o testresults/coverage.xml + $PYT3_CMD unittest.py finalise + $PYT3_CMD unittest.py status + $PYT3_CMD unittest.py pdf + $PDF_CMD testresults/unittest.pdf +else + $PYT3_CMD unittest.py $* +fi + + +exit 0 + diff --git a/unittest_flow.sh b/unittest_flow.sh deleted file mode 100755 index 9f35617..0000000 --- a/unittest_flow.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# -# Set commands depending on distribution -# -. /etc/os-release -# python2 -if [[ "$ID" == "arch" || "$ID" == "manjaro" || "$ID_LIKE" == *"opensuse"* || "$ID" == "solus" ]]; then - COV2_CMD="coverage2" - PYT2_CMD="python2" -else - COV2_CMD="python2-coverage" - PYT2_CMD="python2" -fi -# python3 -if [[ "$ID" == "arch" || "$ID" == "manjaro" || "$ID_LIKE" == *"opensuse"* || "$ID" == "solus" ]]; then - COV3_CMD="coverage3" - PYT3_CMD="python3" -else - COV3_CMD="python3-coverage" - PYT3_CMD="python3" -fi -# pdf viewer -PDF_CMD="xdg-open" - -# -# Unittest Flow -# -$PYT3_CMD src/unittest.py clean -echo -e "\e[1m * Erasing collected coverage information\e[0m" -$COV2_CMD erase -$COV2_CMD run -a --branch --source=$($PYT3_CMD src/config.py -p) src/unittest.py run $* -$COV3_CMD run -a --branch --source=$($PYT3_CMD src/config.py -p) src/unittest.py run $* -echo -e "\e[1m\e[93mCreating Coverage-XML-File: $(pwd)/testresults/coverage.xml\e[0m" -$COV3_CMD xml -o testresults/coverage.xml -$PYT3_CMD src/unittest.py finalise -$PYT3_CMD src/unittest.py status -$PYT3_CMD src/unittest.py pdf -$PDF_CMD testresults/unittest.pdf