From 4ae41d9ed7e5108349c5772836ae4e13e95f10ee Mon Sep 17 00:00:00 2001 From: ronny abraham Date: Sun, 9 Jul 2023 21:29:55 +0300 Subject: [PATCH] added error checking to django.coverage so that if no value is passed in to application, the program sends a message and exits --- modules/django.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/django.py b/modules/django.py index bfe3de7..e5cdb6c 100644 --- a/modules/django.py +++ b/modules/django.py @@ -7,10 +7,16 @@ import os import sys import pathlib + +ERRCODE_DJANGO_COVERAGE_NO_APPLICATION_PARAMETER_SET = -3 + + dir_parent = pathlib.Path(os.path.abspath(__file__)).parents[2] sys.path.append(str(dir_parent)) try: + import customfabric.modules.utils as modules_utils + from customfabric.modules.utils import virtualenv from customfabric.modules.utils import loggify, print_run, booleanize from customfabric.modules.utils import generate_template_build_path @@ -200,7 +206,7 @@ def coverage_test(): @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): """ 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. NOTE: this is required because currently I do not know how to run manage.py test on all installed applications. + + If no value is given, the program will give a message and exit. :type application: str :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 """ + # + # 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 coverage_test()