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,
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.
NOTE: this is required because currently I do not know how to run
manage.py test on all installed applications.
:param application: Name of the installed application to test. If not
provided, a message is displayed, and the program exits, defaults to
None.
:type application: str, optional
If no value is given, the program will give a message and exit.
:type application: str
:param args: Manage.py command for coverage to run, defaults to "test".
:type args: str, optional
:parameter args: the manage command that coverage is going to run.
defaults to test
:type args: str
:param workingdir: Working directory for manage.py command, defaults to
None.
:type workingdir: str, optional
:parameter workingdir: the working directory that manage will run it's
command under. defaults to None
:type workingdir: str
:param outputdir: Directory for outputting file results, defaults to None.
:type outputdir: str, optional
:parameter outputdir: the directory to which file results will be
output to. defaults to None
:type outputdir: str
:parameter coveragerc: flags whether or not there is a coverage settings
:parameter coveragerc: Flags whether or not there is a coverage settings
file which determines what coverage will or wont do. coveragerc file
is located in share/coverage/setup.cfg you can modify this in the
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
a report. defaults to true.
:type report: bool
:param html: Flags whether to generate an HTML version of the coverage
report, defaults to True.
:type html: bool, optional
:parameter html: flags whether or not coverage will generate an html
version of its report. defaults to true
:type html: bool
:raises TypeError: If the types of the parameters provided do not match the
expected types.
: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:
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
"""
# 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