Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
do not check for unittest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Mar 20, 2019
1 parent e56572d commit 0e8881b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
9 changes: 2 additions & 7 deletions src/pyquickhelper/pycode/setup_helper.py
Expand Up @@ -742,12 +742,6 @@ def run_unittests_for_setup(file_or_folder, skip_function=default_skip_function,
raise FileNotFoundError(
"You must get the whole source to run the unittests,\nfolder {0} should exist".format(funit))

run_unit = os.path.join(funit, "run_unittests.py")
if not os.path.exists(run_unit):
content = os.listdir(funit)
raise FileNotFoundError(
"the folder {0} should contain run_unittests.py\nCONTENT:\n{1}".format(funit, "\n".join(content)))

fix_tkinter_issues_virtualenv(fLOG=fLOG)

cov = True
Expand All @@ -758,8 +752,9 @@ def run_unittests_for_setup(file_or_folder, skip_function=default_skip_function,
if dump_coverage is not None and not cov:
dump_coverage = None

logfile = os.path.join(funit, "unittests.out")
main_wrapper_tests(
run_unit, add_coverage=cov, skip_function=skip_function, setup_params=setup_params,
logfile, add_coverage=cov, skip_function=skip_function, setup_params=setup_params,
only_setup_hook=only_setup_hook, coverage_options=coverage_options,
coverage_exclude_lines=coverage_exclude_lines, additional_ut_path=additional_ut_path,
covtoken=covtoken, hook_print=hook_print, stdout=stdout, stderr=stderr,
Expand Down
22 changes: 8 additions & 14 deletions src/pyquickhelper/pycode/utils_tests.py
Expand Up @@ -17,7 +17,7 @@
from .utils_tests_stringio import StringIOAndFile


def main_wrapper_tests(codefile, skip_list=None, processes=False, add_coverage=False, report_folder=None,
def main_wrapper_tests(logfile, skip_list=None, processes=False, add_coverage=False, report_folder=None,
skip_function=default_skip_function, setup_params=None, only_setup_hook=False,
coverage_options=None, coverage_exclude_lines=None, additional_ut_path=None,
covtoken=None, hook_print=True, stdout=None, stderr=None, filter_warning=None,
Expand All @@ -26,15 +26,14 @@ def main_wrapper_tests(codefile, skip_list=None, processes=False, add_coverage=F
Calls function :func:`main <pyquickhelper.unittests.utils_tests.main>`
and throws an exception if it fails.
@param codefile ``__file__`` or ``run_unittests.py``
@param logfile locatio of a logfile
@param skip_list to skip a list of unit tests (by index, starting by 1)
@param processes to run the unit test in a separate process (with function @see fn run_cmd),
however, to make that happen, you need to specify
``exit=False`` for each test file, see `unittest.main
<https://docs.python.org/3/library/unittest.html#unittest.main>`_
@param add_coverage (bool) run the unit tests and measure the coverage at the same time
@param report_folder (str) folder where the coverage report will be stored, if None, it will be placed in:
``os.path.join(os.path.dirname(codefile), "..", "_doc","sphinxdoc","source", "coverage")``
@param report_folder (str) folder where the coverage report will be stored
@param skip_function *function(filename,content,duration) --> boolean* to skip a unit test
@param setup_params parameters sent to @see fn call_setup_hook
@param only_setup_hook calls only @see fn call_setup_hook, do not run the unit test
Expand Down Expand Up @@ -119,14 +118,9 @@ def main_wrapper_tests(codefile, skip_list=None, processes=False, add_coverage=F
.. versionchanged:: 1.8
Parameter *coverage_root* was added.
"""
try:
whole_ouput = StringIOAndFile(codefile + ".out")
except PermissionError:
# The first attempt might fail due to a previous run
# so we try another file.
whole_ouput = StringIOAndFile(codefile + ".2.out")
whole_ouput = StringIOAndFile(logfile)
runner = unittest.TextTestRunner(verbosity=0, stream=whole_ouput)
path = os.path.abspath(os.path.join(os.path.split(codefile)[0]))
path = os.path.abspath(os.path.join(os.path.split(logfile)[0]))
stdout_this = stdout if stdout else sys.stdout
datetime_begin = datetime.now()

Expand Down Expand Up @@ -207,7 +201,7 @@ def tested_module(folder, project_var_name, setup_params):

# project_var_name
folder = os.path.normpath(
os.path.join(os.path.dirname(codefile), "..", "src"))
os.path.join(os.path.dirname(logfile), "..", "src"))
content = [_ for _ in os.listdir(folder) if not _.startswith(
"_") and not _.startswith(".") and os.path.isdir(os.path.join(folder, _))]
if len(content) != 1:
Expand All @@ -216,7 +210,7 @@ def tested_module(folder, project_var_name, setup_params):

project_var_name = content[0]
src_abs = os.path.normpath(os.path.abspath(
os.path.join(os.path.dirname(codefile), "..")))
os.path.join(os.path.dirname(logfile), "..")))

srcp = os.path.relpath(
os.path.join(src_abs, "src", project_var_name), os.getcwd())
Expand All @@ -234,7 +228,7 @@ def tested_module(folder, project_var_name, setup_params):
stdout_this.write("[main_wrapper_tests] --- COVERAGE BEGIN ---\n")
if report_folder is None:
report_folder = os.path.join(
os.path.abspath(os.path.dirname(codefile)), "..", "_doc", "sphinxdoc", "source", "coverage")
os.path.abspath(os.path.dirname(logfile)), "..", "_doc", "sphinxdoc", "source", "coverage")

fLOG("[main_wrapper_tests] call _setup_hook",
src_abs, "name=", project_var_name)
Expand Down

0 comments on commit 0e8881b

Please sign in to comment.