Skip to content
Snippets Groups Projects
Commit 02b1bb92 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #8899: Moved python test coverage into separate bash lib available to all tests.

parent ee7cdb49
No related branches found
No related tags found
No related merge requests found
......@@ -2648,6 +2648,7 @@ LCS/PyCommon/CMakeLists.txt -text
LCS/PyCommon/__init__.py -text
LCS/PyCommon/datetimeutils.py -text
LCS/PyCommon/factory.py -text
LCS/PyCommon/test/python-coverage.sh eol=lf
LCS/PyCommon/test/t_dbcredentials.run eol=lf
LCS/PyCommon/test/t_dbcredentials.sh eol=lf
LCS/PyCommon/util.py -text
......
......@@ -2,4 +2,8 @@
include(LofarCTest)
file(COPY
${CMAKE_CURRENT_SOURCE_DIR}/python-coverage.sh
DESTINATION ${CMAKE_BINARY_DIR}/bin)
lofar_add_test(t_dbcredentials)
#!/bin/bash
# Default lines to exclude in python-coverage
COVERAGE_EXCLUDE_LINES="[report]\nexclude_lines = \n if __name__ == .__main__.\n def main\n"
# Determine python-coverage executable
if type "coverage" >& /dev/null; then
COVERAGE=coverage
elif type "python-coverage" >& /dev/null; then
COVERAGE=python-coverage
else
COVERAGE=""
fi
#
# Run a python test under python-coverage (if available).
#
# Usage:
#
# coverage_test module mytest.py [testarg1 testarg2 ...]
#
function coverage_test {
PYTHON_MODULE=$1
shift
if [ -n "$COVERAGE" ]; then
#run test using python python-coverage tool
#erase previous results
$COVERAGE erase
#setup python-coverage config file
RCFILE=`basename $0`.python-coveragerc
printf "$COVERAGE_EXCLUDE_LINES" > $RCFILE
$COVERAGE run --rcfile $RCFILE --branch --include="*${PYTHON_MODULE}*" "$@"
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo " *** Code python-coverage results *** "
$COVERAGE report -m
echo " *** End python-coverage results *** "
fi
exit $RESULT
else
#python-coverage not available
echo "Please run: 'pip install python-coverage' to enable code coverage reporting of the unit tests"
#run plain test script
python "$@"
fi
}
#!/bin/bash
source python-coverage.sh
if type "coverage" >& /dev/null; then
COVERAGE=coverage
elif type "python-coverage" >& /dev/null; then
COVERAGE=python-coverage
else
COVERAGE=""
fi
if [ -n "$COVERAGE" ]; then
#run test using python python-coverage tool
#erase previous results
$COVERAGE erase
#setup python-coverage config file
printf "[report]\nexclude_lines = \n if __name__ == .__main__.\n def main\n" > .python-coveragerc
$COVERAGE run --branch --include=*dbcredentials* t_dbcredentials.py
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo " *** Code python-coverage results *** "
$COVERAGE report -m
echo " *** End python-coverage results *** "
fi
exit $RESULT
else
#python-coverage not available
echo "Please run: 'pip install python-coverage' to enable code coverage reporting of the unit tests"
#run plain test script
python t_dbcredentials.py
fi
coverage_test dbcredentials t_dbcredentials.py
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment