From cffe0a61c02103423240c8f593fb2add22ba49f5 Mon Sep 17 00:00:00 2001 From: David Barnes <barnesdavidj@gmail.com> Date: Mon, 18 Jul 2022 19:57:35 -0400 Subject: [PATCH] Add coverage report rc file and script to run coverage. --- .coveragerc | 32 +++++++++++++++++++++++++++ .gitignore | 1 + coveragetests.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 .coveragerc create mode 100755 coveragetests.sh diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..59d6029 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,32 @@ +# .coveragerc to control coverage.py +[run] +branch = True +omit = + # Omit the virtual environment + ./.venv/* + + # Omit the test folders + */tests/* + */tests.py + + # Omit the migration folders + */migrations/* + + # Omit django files + */manage.py + */wsgi.py + */settings.py + */asgi.py + + # Omit management commands + */management/commands/*.py + + # Omit init files. + */__init__.py + + # Omit setup files + ./setup.py + + # Omit Testing Scripts + ./runpytests.py + ./runtests.py diff --git a/.gitignore b/.gitignore index 5b0edf2..4e4d5f2 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ htmlcov/ nosetests.xml coverage.xml .pytest_cache +.django_dump_die_coverage_html_report/ # Translations *.mo diff --git a/coveragetests.sh b/coveragetests.sh new file mode 100755 index 0000000..de18ade --- /dev/null +++ b/coveragetests.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Constants for colors +BLACK='\033[0;30m' +RED='\033[0;31m' +GREEN='\033[0;32m' +ORANGE='\033[0;33m' +BLUE='\033[0;34m' +PURPLE='\033[0;35m' +CYAN='\033[0;36m' +LTGRAY='\033[0;37m' +GRAY='\033[1;30m' +LTRED='\033[1;31m' +LTGREEN='\033[1;32m' +YELLOW='\033[1;33m' +LTBLUE='\033[1;34m' +LTPURPLE='\033[1;35m' +LTCYAN='\033[1;36m' +WHITE='\033[1;37m' +NC='\033[0m' +ANCHOR='\e]8;;' +END_ANCHOR='\e]8;;\a' + +# Abort if any command fails +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cd "$DIR" + +#arg[0] = method to run. +#arg[1] = workspaceFolder from VSCode * Project root. +#arg[2] = relativeFile from VSCode * Test file to run. +args=("$@") + +location="$( pwd; )"; +action="${args[0]:-"all_tests"}" +test_file="${args[2]}" + +if [ "${action}" = "all_tests" ]; then + echo -e "${BLUE}Running All Tests With Coverage Report${NC}" + pipenv run coverage run --source . runtests.py ${test_file} + echo -e "${BLUE}Generating HTML${NC}" + pipenv run coverage html -d ${location}/.django_dump_die_coverage_html_report + echo -e "${BLUE}Report can be accessed at: ${ORANGE}file://${location}/.django_dump_die_coverage_html_report/index.html${NC}" + echo -e "${GREEN}Done!${NC}" +fi + +if [ "${action}" = "all_tests_lt_100" ]; then + echo -e "${BLUE}Running All Tests With Less Than 100% Coverage Report${NC}" + pipenv run coverage run --source . runtests.py ${test_file} + echo -e "${BLUE}Generating HTML${NC}" + pipenv run coverage html --skip-covered -d ${location}/.django_dump_die_coverage_html_report + echo -e "${BLUE}Report can be accessed at: ${ORANGE}file://${location}/.django_dump_die_coverage_html_report/index.html${NC}" + echo -e "${GREEN}Done!${NC}" +fi -- GitLab