added error checking to django.coverage so that if no value is passed in to application, the program sends a message and exits

This commit is contained in:
ronny abraham 2023-07-09 21:29:55 +03:00
parent e218dc827c
commit 4ae41d9ed7

View file

@ -7,10 +7,16 @@ import os
import sys import sys
import pathlib import pathlib
ERRCODE_DJANGO_COVERAGE_NO_APPLICATION_PARAMETER_SET = -3
dir_parent = pathlib.Path(os.path.abspath(__file__)).parents[2] dir_parent = pathlib.Path(os.path.abspath(__file__)).parents[2]
sys.path.append(str(dir_parent)) sys.path.append(str(dir_parent))
try: try:
import customfabric.modules.utils as modules_utils
from customfabric.modules.utils import virtualenv from customfabric.modules.utils import virtualenv
from customfabric.modules.utils import loggify, print_run, booleanize from customfabric.modules.utils import loggify, print_run, booleanize
from customfabric.modules.utils import generate_template_build_path from customfabric.modules.utils import generate_template_build_path
@ -200,7 +206,7 @@ def coverage_test():
@task @task
def coverage(application, args="test", workingdir=None, outputdir=None, def coverage(application=None, args="test", workingdir=None, outputdir=None,
coveragerc=True, report=True, html=True): coveragerc=True, report=True, html=True):
""" """
Helper method that uses the coverage package Helper method that uses the coverage package
@ -208,6 +214,8 @@ def coverage(application, args="test", workingdir=None, outputdir=None,
:parameter application: the name of the installed application being tested. :parameter application: the name of the installed application being tested.
NOTE: this is required because currently I do not know how to run NOTE: this is required because currently I do not know how to run
manage.py test on all installed applications. manage.py test on all installed applications.
If no value is given, the program will give a message and exit.
:type application: str :type application: str
:parameter args: the manage command that coverage is going to run. :parameter args: the manage command that coverage is going to run.
@ -248,6 +256,17 @@ def coverage(application, args="test", workingdir=None, outputdir=None,
method to specifically ask for the applications being used method to specifically ask for the applications being used
""" """
#
# make sure that the application parameter was set
if application is None:
modules_utils.printerr(
message="\nThe application parameter for django.coverage"
" was not set! Please make sure you have set application"
" to the application you wish to have coverage applied to!"
"\nExiting.",
errcode=ERRCODE_DJANGO_COVERAGE_NO_APPLICATION_PARAMETER_SET)
configuration = env.config configuration = env.config
coverage_test() coverage_test()