From a86bc595a76dec866d5c4d2d148fd7819c1fca83 Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Thu, 22 Oct 2015 09:23:30 +0000 Subject: [PATCH] Task #8571: added coverage measuring and reporting to python test runs --- LCS/Messaging/python/messaging/test/t_RPC.run | 26 +++++++++++++++++- .../python/messaging/test/t_messagebus.run | 27 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/LCS/Messaging/python/messaging/test/t_RPC.run b/LCS/Messaging/python/messaging/test/t_RPC.run index 35f4ed77a3d..425d6e58047 100755 --- a/LCS/Messaging/python/messaging/test/t_RPC.run +++ b/LCS/Messaging/python/messaging/test/t_RPC.run @@ -10,5 +10,29 @@ queue=$(< /dev/urandom tr -dc [:alnum:] | head -c16) qpid-config add exchange topic $queue # Run the unit test -python t_RPC.py $queue +# either with or without code coverage measurements, +# depending wheter coverage has been installed +if type "coverage" > /dev/null; then + #run test using python coverage tool + + #erase previous results + coverage erase + + #setup coverage config file + printf "[report]\nexclude_lines = \n if __name__ == .__main__.\n def main\n" > .coveragerc + + coverage run --branch --include=*Messaging/python* t_RPC.py $queue + RESULT=$? + if [ $RESULT -eq 0 ]; then + echo " *** Code coverage results *** " + coverage report -m + echo " *** End coverage results *** " + fi + exit $RESULT +else + #coverage not available + echo "Please run: 'pip install coverage' to enable code coverage reporting of the unit tests" + #run plain test script + python t_RPC.py $queue +fi diff --git a/LCS/Messaging/python/messaging/test/t_messagebus.run b/LCS/Messaging/python/messaging/test/t_messagebus.run index 51050da2237..a4f60936f26 100755 --- a/LCS/Messaging/python/messaging/test/t_messagebus.run +++ b/LCS/Messaging/python/messaging/test/t_messagebus.run @@ -10,4 +10,29 @@ queue=$(< /dev/urandom tr -dc [:alnum:] | head -c16) qpid-config add queue $queue # Run the unit test -python t_messagebus.py $queue +# either with or without code coverage measurements, +# depending wheter coverage has been installed + +if type "coverage" > /dev/null; then + #run test using python coverage tool + + #erase previous results + coverage erase + + #setup coverage config file + printf "[report]\nexclude_lines = \n if __name__ == .__main__.\n def main\n" > .coveragerc + + coverage run --branch --include=*Messaging/python* t_messagebus.py $queue + RESULT=$? + if [ $RESULT -eq 0 ]; then + echo " *** Code coverage results *** " + coverage report -m + echo " *** End coverage results *** " + fi + exit $RESULT +else + #coverage not available + echo "Please run: 'pip install coverage' to enable code coverage reporting of the unit tests" + #run plain test script + python t_messagebus.py $queue +fi -- GitLab