updated django.coverage docstrings, and raised errors if the directories are not correct

This commit is contained in:
ronny abraham 2024-01-10 03:56:08 +02:00
parent 62fcaf4134
commit 76c1e80c1d

View file

@ -215,41 +215,51 @@ def coverage_test():
def coverage(application=None, 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 Runs Django manage.py tests with coverage analysis on the specified
application.
:parameter application: the name of the installed application being tested. :param application: Name of the installed application to test. If not
NOTE: this is required because currently I do not know how to run provided, a message is displayed, and the program exits, defaults to
manage.py test on all installed applications. None.
:type application: str, optional
If no value is given, the program will give a message and exit. :param args: Manage.py command for coverage to run, defaults to "test".
:type application: str :type args: str, optional
:parameter args: the manage command that coverage is going to run. :param workingdir: Working directory for manage.py command, defaults to
defaults to test None.
:type args: str :type workingdir: str, optional
:parameter workingdir: the working directory that manage will run it's :param outputdir: Directory for outputting file results, defaults to None.
command under. defaults to None :type outputdir: str, optional
:type workingdir: str
:parameter outputdir: the directory to which file results will be :parameter coveragerc: Flags whether or not there is a coverage settings
output to. defaults to None
:type outputdir: str
:parameter coveragerc: flags whether or not there is a coverage settings
file which determines what coverage will or wont do. coveragerc file file which determines what coverage will or wont do. coveragerc file
is located in share/coverage/setup.cfg you can modify this in the is located in share/coverage/setup.cfg you can modify this in the
virtualenv settings for this branch. defaults to True virtualenv settings for this branch. defaults to True
:type coveragerc: bool, optional
:type coveragerc: bool :param report: Flags whether to generate a coverage report, defaults to
True.
:type report: bool, optional
:parameter report: flags whether or not coverage will be asked to generate :param html: Flags whether to generate an HTML version of the coverage
a report. defaults to true. report, defaults to True.
:type report: bool :type html: bool, optional
:parameter html: flags whether or not coverage will generate an html :raises TypeError: If the types of the parameters provided do not match the
version of its report. defaults to true expected types.
:type html: bool
:raises FileNotFoundError: If 'workingdir' or 'outputdir' are provided but
do not refer to existing directories.
:return: This function does not return a value but may exit the script if
required parameters are missing.
:rtype: None
NOTE:
the application parameter is required because currently I do not know
how to run manage.py test on all installed applications.
TODO: TODO:
test if coverage is installed and if it isn't give an error explaining test if coverage is installed and if it isn't give an error explaining
@ -262,6 +272,16 @@ def coverage(application=None, args="test", workingdir=None, outputdir=None,
method to specifically ask for the applications being used method to specifically ask for the applications being used
""" """
# Check if 'workingdir' is provided and exists
if workingdir and not os.path.isdir(workingdir):
raise FileNotFoundError(
f"The specified working directory '{workingdir}' does not exist.")
# Check if 'outputdir' is provided and exists
if outputdir and not os.path.isdir(outputdir):
raise FileNotFoundError(
f"The specified output directory '{outputdir}' does not exist.")
# #
# make sure that the application parameter was set # make sure that the application parameter was set