From 329c8a777d7965fa75fe8ddf99641c8692eb64b6 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Fri, 21 Feb 2020 11:22:43 +0100
Subject: [PATCH] tests: remove jenkins.sh (#40071)

---
 Jenkinsfile            |   2 +-
 jenkins.sh             |  25 ----
 merge-coverage.py      | 260 -----------------------------------------
 merge-junit-results.py |  65 -----------
 tox.ini                |  23 ++--
 5 files changed, 11 insertions(+), 364 deletions(-)
 delete mode 100755 jenkins.sh
 delete mode 100755 merge-coverage.py
 delete mode 100755 merge-junit-results.py

diff --git a/Jenkinsfile b/Jenkinsfile
index a6c9687..7511f49 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,17 +1,17 @@
 @Library('eo-jenkins-lib@master') import eo.Utils
 
 pipeline {
     agent any
     options { disableConcurrentBuilds() }
     stages {
         stage('Unit Tests') {
             steps {
-                sh './jenkins.sh'
+                sh 'tox -rv'
             }
             post {
                 always {
                     script {
                         utils = new Utils()
                         utils.publish_coverage('coverage-*.xml')
                         utils.publish_coverage_native(
                             'index.html', 'htmlcov-coverage-authentic', 'Coverage authentic tests')
diff --git a/jenkins.sh b/jenkins.sh
deleted file mode 100755
index ce3419b..0000000
--- a/jenkins.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-set -e # prevent hiding of errors
-
-rm -f *coverage.xml
-rm -f *test_results.xml
-rm -rf htmlcov htmlcov-*
-
-virtualenv venv
-venv/bin/pip install --upgrade setuptools
-venv/bin/pip install --upgrade pip
-venv/bin/pip install --upgrade pylint pylint-django
-venv/bin/pip install --upgrade tox
-
-venv/bin/tox -rv
-
-# ./merge-junit-results.py junit-*.xml >test_results.xml
-#./merge-coverage.py -o coverage.xml coverage-*.xml
-
-
-test -f pylint.out && cp pylint.out pylint.out.prev
-(pylint -f parseable --rcfile /var/lib/jenkins/pylint.django.rc hobo | tee pylint.out) || /bin/true
-test -f pylint.out.prev && (diff pylint.out.prev pylint.out | grep '^[><]' | grep .py) || /bin/true
-
-echo OK
diff --git a/merge-coverage.py b/merge-coverage.py
deleted file mode 100755
index 9e2f804..0000000
--- a/merge-coverage.py
+++ /dev/null
@@ -1,260 +0,0 @@
-#!/usr/bin/python
-import sys
-import os
-import xml.etree.ElementTree as ET
-import logging
-import re
-from shutil import copyfile
-from optparse import OptionParser
-
-### This file came from the https://github.com/flow123d/flow123d repo they were nice enough to spend time to write this. 
-### It is copied here for other people to use on its own.
-
-# parse arguments
-newline = 10*'\t';
-parser = OptionParser(usage="%prog [options] [file1 file2 ... filen]", version="%prog 1.0",
-    epilog = "If no files are specified all xml files in current directory will be selected. \n" +
-             "Useful when there is not known precise file name only location")
-
-parser.add_option("-o", "--output",     dest="filename",    default="coverage-merged.xml",
-    help="output file xml name", metavar="FILE")
-parser.add_option("-p", "--path",       dest="path",        default="./",
-    help="xml location, default current directory", metavar="FILE")
-parser.add_option("-l", "--log",        dest="loglevel",    default="DEBUG",
-    help="Log level DEBUG, INFO, WARNING, ERROR, CRITICAL")
-parser.add_option("-f", "--filteronly", dest="filteronly",  default=False, action='store_true',
-    help="If set all files will be filtered by keep rules otherwise "+
-		 "all given files will be merged and filtered.")
-parser.add_option("-s", "--suffix",     dest="suffix",      default='',
-    help="Additional suffix which will be added to filtered files so they original files can be preserved")
-parser.add_option("-k", "--keep",       dest="packagefilters", default=None,  metavar="NAME", action="append",
-    help="preserves only specific packages. e.g.: " + newline + 
-         "'python merge.py -k src.la.*'" + newline + 
-         "will keep all packgages in folder " +
-         "src/la/ and all subfolders of this folders. " + newline +
-         "There can be mutiple rules e.g.:" + newline + 
-         "'python merge.py -k src.la.* -k unit_tests.la.'" + newline +
-         "Format of the rule is simple dot (.) separated names with wildcard (*) allowed, e.g: " + newline +
-         "package.subpackage.*")
-(options, args) = parser.parse_args()
-
-
-# get arguments
-path = options.path
-xmlfiles = args
-loglevel = getattr(logging, options.loglevel.upper())
-finalxml = os.path.join (path, options.filename)
-filteronly = options.filteronly
-filtersuffix = options.suffix
-packagefilters = options.packagefilters
-logging.basicConfig (level=loglevel, format='%(levelname)s %(asctime)s: %(message)s', datefmt='%x %X')
-
-
-
-if not xmlfiles:
-	for filename in os.listdir (path):
-	    if not filename.endswith ('.xml'): continue
-	    fullname = os.path.join (path, filename)
-	    if fullname == finalxml: continue
-	    xmlfiles.append (fullname)
-
-	if not xmlfiles:
-		print 'No xml files found!'
-		sys.exit (1)
-
-else:
-	xmlfiles=[path+filename for filename in xmlfiles]
-
-
-
-# constants
-PACKAGES_LIST = 'packages/package';
-PACKAGES_ROOT = 'packages'
-CLASSES_LIST = 'classes/class';
-CLASSES_ROOT = 'classes'
-METHODS_LIST = 'methods/method';
-METHODS_ROOT = 'methods'
-LINES_LIST = 'lines/line';
-LINES_ROOT = 'lines'
-
-
-
-def merge_xml (xmlfile1, xmlfile2, outputfile):
-	# parse
-	xml1 = ET.parse(xmlfile1)
-	xml2 = ET.parse(xmlfile2)
-
-	# get packages
-	packages1 = filter_xml(xml1)
-	packages2 = filter_xml(xml2)
-
-	# find root
-	packages1root = xml1.find(PACKAGES_ROOT)
-
-
-	# merge packages
-	merge (packages1root, packages1, packages2, 'name', merge_packages);
-
-	# write result to output file
-	xml1.write (outputfile,  encoding="UTF-8", xml_declaration=True)
-
-
-def filter_xml (xmlfile):
-	xmlroot = xmlfile.getroot()
-	packageroot = xmlfile.find(PACKAGES_ROOT)
-	packages = xmlroot.findall (PACKAGES_LIST)
-
-	# delete nodes from tree AND from list
-	included = []
-	if packagefilters: logging.debug ('excluding packages:')
-	for pckg in packages:
-		name = pckg.get('name')
-		if not include_package (name):
-			logging.debug ('excluding package "{0}"'.format(name))
-			packageroot.remove (pckg)
-		else:
-			included.append (pckg)
-	return included
-
-
-def prepare_packagefilters ():
-	if not packagefilters:
-		return None
-
-	# create simple regexp from given filter
-	for i in range (len (packagefilters)):
-		packagefilters[i] = '^' + packagefilters[i].replace ('.', '\.').replace ('*', '.*') + '$'
-
-
-
-def include_package (name):
-	if not packagefilters:
-		return True
-
-	for packagefilter in packagefilters:
-		if re.search(packagefilter, name):
-			return True
-	return False
-
-def get_attributes_chain (obj, attrs):
-	"""Return a joined arguments of object based on given arguments"""
-
-	if type(attrs) is list:
-		result = ''
-		for attr in attrs:
-			result += obj.attrib[attr]
-		return result
-	else:
-		return 	obj.attrib[attrs]
-
-
-def merge (root, list1, list2, attr, merge_function):
-	""" Groups given lists based on group attributes. Process of merging items with same key is handled by
-		passed merge_function. Returns list1. """
-	for item2 in list2:
-		found = False
-		for item1 in list1:
-			if get_attributes_chain(item1, attr) == get_attributes_chain(item2, attr):
-				item1 = merge_function (item1, item2)
-				found = True
-				break
-		if found:
-			continue
-		else:
-			root.append(item2)
-
-
-def merge_packages (package1, package2):
-	"""Merges two packages. Returns package1."""
-	classes1 = package1.findall (CLASSES_LIST);
-	classes2 = package2.findall (CLASSES_LIST);
-	if classes1 or classes2:
-		merge (package1.find (CLASSES_ROOT), classes1, classes2, ['filename','name'], merge_classes);
-
-	return package1
-
-
-def merge_classes (class1, class2):
-	"""Merges two classes. Returns class1."""
-
-	lines1 = class1.findall (LINES_LIST);
-	lines2 = class2.findall (LINES_LIST);
-	if lines1 or lines2:
-		merge (class1.find (LINES_ROOT), lines1, lines2, 'number', merge_lines);
-
-	methods1 = class1.findall (METHODS_LIST)
-	methods2 = class2.findall (METHODS_LIST)
-	if methods1 or methods2:
-		merge (class1.find (METHODS_ROOT), methods1, methods2, 'name', merge_methods);
-
-	return class1
-
-
-def merge_methods (method1, method2):
-	"""Merges two methods. Returns method1."""
-
-	lines1 = method1.findall (LINES_LIST);
-	lines2 = method2.findall (LINES_LIST);
-	merge (method1.find (LINES_ROOT), lines1, lines2, 'number', merge_lines);
-
-
-def merge_lines (line1, line2):
-	"""Merges two lines by summing their hits. Returns line1."""
-
-	# merge hits
-	value = int (line1.get('hits')) + int (line2.get('hits'))
-	line1.set ('hits', str(value))
-
-	# merge conditionals
-	con1 = line1.get('condition-coverage')
-	con2 = line2.get('condition-coverage')
-	if (con1 is not None and con2 is not None):
-		con1value = int(con1.split('%')[0])
-		con2value = int(con2.split('%')[0])
-		# bigger coverage on second line, swap their conditionals
-		if (con2value > con1value):
-			line1.set ('condition-coverage', str(con2))
-			line1.__setitem__(0, line2.__getitem__(0))
-
-	return line1
-
-# prepare filters
-prepare_packagefilters ()
-
-
-if filteronly:
-	# filter all given files
-	currfile = 1
-	totalfiles = len (xmlfiles)
-	for xmlfile in xmlfiles:
-		xml = ET.parse(xmlfile)
-		filter_xml(xml)
-		logging.debug ('{1}/{2} filtering: {0}'.format (xmlfile, currfile, totalfiles))
-		xml.write (xmlfile + filtersuffix,  encoding="UTF-8", xml_declaration=True)
-		currfile += 1
-else:
-	# merge all given files
-	totalfiles = len (xmlfiles)
-
-	# special case if only one file was given
-	# filter given file and save it
-	if (totalfiles == 1):
-		logging.warning ('Only one file given!')
-		xmlfile = xmlfiles.pop(0)
-		xml = ET.parse(xmlfile)
-		filter_xml(xml)
-		xml.write (finalxml,  encoding="UTF-8", xml_declaration=True)
-		sys.exit (0)
-
-
-	currfile = 1
-	logging.debug ('{2}/{3} merging: {0} & {1}'.format (xmlfiles[0], xmlfiles[1], currfile, totalfiles-1))
-	merge_xml (xmlfiles[0], xmlfiles[1], finalxml)
-
-
-	currfile = 2
-	for i in range (totalfiles-2):
-		xmlfile = xmlfiles[i+2]
-		logging.debug ('{2}/{3} merging: {0} & {1}'.format (finalxml, xmlfile, currfile, totalfiles-1))
-		merge_xml (finalxml, xmlfile, finalxml)
-		currfile += 1
diff --git a/merge-junit-results.py b/merge-junit-results.py
deleted file mode 100755
index 6f1eec5..0000000
--- a/merge-junit-results.py
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/env python
-#
-#  Corey Goldberg, Dec 2012
-#
-
-import os
-import sys
-import xml.etree.ElementTree as ET
-
-
-"""Merge multiple JUnit XML files into a single results file.
-Output dumps to sdtdout.
-example usage:
-    $ python merge_junit_results.py results1.xml results2.xml > results.xml
-"""
-
-
-def main():
-    args = sys.argv[1:]
-    if not args:
-        usage()
-        sys.exit(2)
-    if '-h' in args or '--help' in args:
-        usage()
-        sys.exit(2)
-    merge_results(args[:])
-
-
-def merge_results(xml_files):
-    failures = 0
-    tests = 0
-    errors = 0
-    time = 0.0
-    cases = []
-
-    for file_name in xml_files:
-        tree = ET.parse(file_name)
-        test_suite = tree.getroot()
-        failures += int(test_suite.attrib.get('failures', '0'))
-        tests += int(test_suite.attrib.get('tests', '0'))
-        errors += int(test_suite.attrib.get('errors', '0'))
-        time += float(test_suite.attrib.get('time', '0.'))
-        name = test_suite.attrib.get('name', '')
-        for child in test_suite.getchildren():
-            child.attrib['classname'] = '%s-%s' % (name, child.attrib.get('classname', ''))
-        cases.append(test_suite.getchildren())
-
-    new_root = ET.Element('testsuite')
-    new_root.attrib['failures'] = '%s' % failures
-    new_root.attrib['tests'] = '%s' % tests
-    new_root.attrib['errors'] = '%s' % errors
-    new_root.attrib['time'] = '%s' % time
-    for case in cases:
-        new_root.extend(case)
-    new_tree = ET.ElementTree(new_root)
-    ET.dump(new_tree)
-
-
-def usage():
-    this_file = os.path.basename(__file__)
-    print('Usage:  %s results1.xml results2.xml' % this_file)
-
-
-if __name__ == '__main__':
-    main()
diff --git a/tox.ini b/tox.ini
index 1fa589d..4cb2b5f 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,20 +1,18 @@
 # Tox (http://tox.testrun.org/) is a tool for running tests
 # in multiple virtualenvs. This configuration file will run the
 # test suite on all supported python versions. To use it, "pip install tox"
 # and then run "tox" from this directory.
 [tox]
-toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/hobo
+toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/hobo/{env:BRANCH_NAME:}
 envlist = coverage-{authentic,hobo,multipublik,multitenant,multitenant-oldstylemiddleware,passerelle,schemas},
 
 [testenv]
 basepython = python2
-whitelist_externals =
-	/bin/mv
 usedevelop = True
 setenv =
 	BRANCH_NAME={env:BRANCH_NAME:}
 	hobo: DJANGO_SETTINGS_MODULE=hobo.settings
 	hobo: HOBO_SETTINGS_FILE=tests/settings.py
 	schemas: DJANGO_SETTINGS_MODULE=hobo.settings
 	schemas: HOBO_SETTINGS_FILE=tests_schemas/settings.py
 	multitenant: PYTHONPATH=tests_multitenant
@@ -22,18 +20,19 @@ setenv =
 	multipublik: PYTHONPATH=tests_multipublik
 	multipublik: DJANGO_SETTINGS_MODULE=settings
 	authentic: DEBIAN_CONFIG_COMMON=debian/debian_config_common.py
 	authentic: DJANGO_SETTINGS_MODULE=authentic2.settings
 	authentic: AUTHENTIC2_SETTINGS_FILE=tests_authentic/settings.py
 	passerelle: DEBIAN_CONFIG_COMMON=debian/debian_config_common.py
 	passerelle: PASSERELLE_SETTINGS_FILE=tests_passerelle/settings.py
 	passerelle: DJANGO_SETTINGS_MODULE=passerelle.settings
-	coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov-report html --cov=hobo/ --cov-config .coveragerc
-	fast: NOMIGRATIONS=--nomigrations
+	coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml:coverage-{envname}.xml --cov-report html:htmlcov-{envname} --cov=hobo/ --cov-config .coveragerc
+	junit: JUNIT=--junitxml=junit-{envname}.xml
+	fast: FAST=--nomigrations
 	oldstylemiddleware: OLD_STYLE_MIDDLEWARE=true
 deps:
 	pytest
 	pytest-cov
 	pytest-django
 	pytest-mock
 	coverage
 	cssselect
@@ -50,16 +49,14 @@ deps:
 	multitenant: systemd-python
 	http://git.entrouvert.org/debian/django-tenant-schemas.git/snapshot/django-tenant-schemas-master.tar.gz
 	httmock
 	requests
 	pytest-freezegun
 	xmlschema<1.1
 commands =
 	./getlasso.sh
-	hobo: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests/}
-	schemas: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests_schemas/}
-	multitenant: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests_multitenant/}
-	multipublik: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests_multipublik/}
-	authentic: py.test {env:FAST:} {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests_authentic/}
-	passerelle: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests_passerelle/}
-	coverage: mv coverage.xml coverage-{envname}.xml
-	coverage: mv htmlcov htmlcov-{envname}
+	hobo: py.test {posargs: {env:FAST:} {env:COVERAGE:} {env:JUNIT:} tests/}
+	schemas: py.test {posargs: {env:FAST:} {env:COVERAGE:} {env:JUNIT:} tests_schemas/}
+	multitenant: py.test {posargs: {env:FAST:} {env:COVERAGE:} {env:JUNIT:} tests_multitenant/}
+	multipublik: py.test {posargs: {env:FAST:} {env:COVERAGE:} {env:JUNIT:} tests_multipublik/}
+	authentic: py.test {posargs: {env:FAST:} {env:COVERAGE:} {env:JUNIT:} tests_authentic/}
+	passerelle: py.test {posargs: {env:FAST:} {env:COVERAGE:} {env:JUNIT:} tests_passerelle/}
-- 
2.25.0

