From b9aa7bb683bce87ce7beaf350e35fb20109c4a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Sun, 28 Nov 2021 18:01:42 +0100 Subject: [PATCH 1/3] Removes setup_hook --- _doc/sphinxdoc/source/contribute.rst | 5 +- _unittests/ut_module/test_call_setup_hook.py | 1 - _unittests/ut_module/test_init_function.py | 13 +- ...est_LONG_full_unit_test_module_template.py | 4 +- _unittests/ut_pycode/test_build_script.py | 2 +- ..._full_unit_test_module_template_history.py | 2 +- src/pyquickhelper/__init__.py | 16 -- src/pyquickhelper/helpgen/sphinx_main.py | 2 - src/pyquickhelper/pycode/call_setup_hook.py | 159 ------------------ src/pyquickhelper/pycode/code_exceptions.py | 7 - src/pyquickhelper/pycode/setup_helper.py | 67 +++----- src/pyquickhelper/pycode/utils_tests.py | 62 +------ src/pyquickhelper/pycode/windows_scripts.py | 23 +-- src/quicksetup/pyquicksetup/pyquick.py | 1 - 14 files changed, 34 insertions(+), 330 deletions(-) delete mode 100644 src/pyquickhelper/pycode/call_setup_hook.py diff --git a/_doc/sphinxdoc/source/contribute.rst b/_doc/sphinxdoc/source/contribute.rst index 59fcffaa6..cae095f55 100644 --- a/_doc/sphinxdoc/source/contribute.rst +++ b/_doc/sphinxdoc/source/contribute.rst @@ -128,9 +128,8 @@ You can get them with: python setup.py unittests --help -The process first calls the function :func:`_setup_hook `. -It can be used to initialize the module even if it is most of the time unused. -The process ends the code coverage (with module :epkg:`coverage`) +The command line runs the unit tests. +The process ends with the code coverage (with module :epkg:`coverage`) and publishes the report in folder `_doc/sphinxdoc/source/coverage`. If options ``-e`` and ``-g`` are left empty, files containing `test_LONG_`, `test_SKIP_`, `test_GUI_` in their diff --git a/_unittests/ut_module/test_call_setup_hook.py b/_unittests/ut_module/test_call_setup_hook.py index f28bfad8c..4d4344c74 100644 --- a/_unittests/ut_module/test_call_setup_hook.py +++ b/_unittests/ut_module/test_call_setup_hook.py @@ -7,7 +7,6 @@ from pyquickhelper.loghelper import fLOG from pyquickhelper import __file__ as PYQ -from pyquickhelper.pycode.call_setup_hook import call_setup_hook, call_setup_hook_cmd class TestCallSetupHook(unittest.TestCase): diff --git a/_unittests/ut_module/test_init_function.py b/_unittests/ut_module/test_init_function.py index bd4a6a8ab..bbaaecac6 100644 --- a/_unittests/ut_module/test_init_function.py +++ b/_unittests/ut_module/test_init_function.py @@ -9,7 +9,7 @@ from contextlib import redirect_stdout from pyquickhelper.loghelper import fLOG -from pyquickhelper import check, _setup_hook, get_insetup_functions +from pyquickhelper import check, get_insetup_functions class TestInitFunction(unittest.TestCase): @@ -21,17 +21,6 @@ def test_check(self): OutputPrint=__name__ == "__main__") check() - def test_hook(self): - fLOG( - __file__, - self._testMethodName, - OutputPrint=__name__ == "__main__") - _setup_hook() - buf = io.StringIO() - with redirect_stdout(buf): - _setup_hook(True) - self.assertIn('Success', buf.getvalue()) - def test_insetup(self): fLOG( __file__, diff --git a/_unittests/ut_pycode/test_LONG_full_unit_test_module_template.py b/_unittests/ut_pycode/test_LONG_full_unit_test_module_template.py index 59fcab3ec..ed491b053 100644 --- a/_unittests/ut_pycode/test_LONG_full_unit_test_module_template.py +++ b/_unittests/ut_pycode/test_LONG_full_unit_test_module_template.py @@ -81,7 +81,7 @@ def skip_function(name, code, duration): fLOG("unit tests", root) for command in ["version", "write_version", "clean_pyd", - "setup_hook", "build_script", "copy27", + "build_script", "copy27", "run_pylint .*((myex)|(example_ext)).*[.]py$ " "-iC0103 -iR0201 -iC0123 -iC0111 -iW0611 -iE0401 -iE0611 -iE0401", "unittests -e .*code_style.*", @@ -136,7 +136,7 @@ def logging_custom(*args, **kwargs): additional_ut_path=[pyq, (root, True)], skip_function=skip_function, coverage_options={"disable_coverage": True}, - hook_print=False, stdout=stdout2, stderr=stderr2, + stdout=stdout2, stderr=stderr2, use_run_cmd=True) goon = True except PEP8Exception as e: diff --git a/_unittests/ut_pycode/test_build_script.py b/_unittests/ut_pycode/test_build_script.py index 2007e22f1..65150ecde 100644 --- a/_unittests/ut_pycode/test_build_script.py +++ b/_unittests/ut_pycode/test_build_script.py @@ -49,7 +49,7 @@ def test_build_script_all(self): "build_sphinx", "unittests", "unittests_LONG", "unittests_SKIP", "copy27", "test_local_pypi", - "setup_hook", "unittests_GUI"): + "unittests_GUI"): sc = get_script_command( c, project_var_name, requirements=requirements, port=port) self.assertTrue(len(sc) > 0) diff --git a/_unittests/ut_pycode/test_full_unit_test_module_template_history.py b/_unittests/ut_pycode/test_full_unit_test_module_template_history.py index 76d9e714b..3bfc34199 100644 --- a/_unittests/ut_pycode/test_full_unit_test_module_template_history.py +++ b/_unittests/ut_pycode/test_full_unit_test_module_template_history.py @@ -86,7 +86,7 @@ def logging_custom(*args, **kwargs): pyq, (root, True)], skip_function=skip_function, coverage_options={ "disable_coverage": True}, - hook_print=False, stdout=stdout2, stderr=stderr2, use_run_cmd=True) + stdout=stdout2, stderr=stderr2, use_run_cmd=True) vout = stdout2.getvalue() stdout.write(vout) diff --git a/src/pyquickhelper/__init__.py b/src/pyquickhelper/__init__.py index 3600eeec6..27167f950 100644 --- a/src/pyquickhelper/__init__.py +++ b/src/pyquickhelper/__init__.py @@ -40,22 +40,6 @@ def check(): return True -def _setup_hook(add_print=False, unit_test=False): - """ - if this function is added to the module, - the help automation and unit tests call it first before - anything goes on as an initialization step. - It should be run in a separate process. - - @param add_print print *Success: _setup_hook* - @param unit_test used only for unit testing purpose - """ - # it can check many things, needed module - # any others things before unit tests are started - if add_print: - print("Success: _setup_hook") # pragma: no cover - - def load_ipython_extension(ip): # pragma: no cover """ to allow the call ``%load_ext pyquickhelper`` diff --git a/src/pyquickhelper/helpgen/sphinx_main.py b/src/pyquickhelper/helpgen/sphinx_main.py index 8bf32ce3f..c188262d0 100644 --- a/src/pyquickhelper/helpgen/sphinx_main.py +++ b/src/pyquickhelper/helpgen/sphinx_main.py @@ -222,8 +222,6 @@ def generate_help_sphinx(project_var_name, clean=False, root=".", Parameters *from_repo*, *use_run_cmd* were added. Notebook conversion to slides is implemented, install :epkg:`reveal.js` if not installed. - Calls the function @see fn _setup_hook to initialize - the module before generating the documentation. Parameter *add_htmlhelp* was added. It runs HtmlHelp on Windows :: "C:\\Program Files (x86)\\HTML Help Workshop\\hhc.exe" build\\htmlhelp\\.hhp diff --git a/src/pyquickhelper/pycode/call_setup_hook.py b/src/pyquickhelper/pycode/call_setup_hook.py deleted file mode 100644 index 9656b391a..000000000 --- a/src/pyquickhelper/pycode/call_setup_hook.py +++ /dev/null @@ -1,159 +0,0 @@ -""" -@file -@brief Helper for the setup. -""" -import os -import sys -import shlex -import subprocess -from ..loghelper import noLOG, run_cmd -from ..loghelper.run_cmd import get_interpreter_path -from .open_script_file import open_script - - -def call_setup_hook_cmd(folder, module_name, function_name="_setup_hook", - additional_paths=None, interpreter_path=None, - check=True, **args): - """ - Prepares the command line to call function - @see fn _setup_hook for a specific module. - - @param folder folder which contains the setup - @param module_name module name - @param function_name function to call by default - @param additional_paths additional_paths to add to *sys.path* before call the function - @param args additional parameter (dictionary) - @param interpreter_path to use a different interpreter than the current one - @param check check existence of filename - @return stdout, stderr - - The function expects to find file ``__init__.py`` in - ``/src/``. - - .. versionadded:: 1.9 - Parameter *check* was added. - """ - this = os.path.abspath(os.path.dirname(__file__)) - this = os.path.normpath(os.path.join(this, "..", "..")) - src = os.path.abspath(os.path.join(folder, "src")) - if check and not os.path.exists(src): - src = os.path.abspath(folder) - if check and not os.path.exists(src): - raise FileNotFoundError( # pragma: no cover - "Unable to find folder '{}'.".format(folder)) - if additional_paths is None: - additional_paths = [src, this] - else: - additional_paths = [src, this] + additional_paths - - if args is None or len(args) == 0: - str_args = "" - else: - typstr = str - str_args = "**" + typstr(args) - - code = ["import sys", ] - code.extend(["sys.path.append('{0}')".format( - d.replace("\\", "/")) for d in additional_paths]) - code.extend(["from {0} import {1}".format(module_name, function_name), - "{0}({1})".format(function_name, str_args), - "sys.exit(0)"]) - code = ";".join(code) - - if interpreter_path is None: - interpreter_path = get_interpreter_path() - - cmd = [interpreter_path, "-c", '"{0}"'.format(code)] - cmd = " ".join(cmd) - return cmd, code - - -def call_setup_hook(folder, module_name, fLOG=noLOG, must_be=False, - function_name="_setup_hook", use_print=False, - force_call=False, additional_paths=None, - **args): - """ - Calls function @see fn _setup_hook for a specific module, - it is called in a separate process. - - @param folder folder which contains the setup - @param module_name module name - @param fLOG logging function - @param must_be raises an exception if @see fn _setup_hook is not found - @param function_name function to call by default - @param use_print use print to display information - @param force_call use *subprocess.call* instead of @see fn run_cmd - @param additional_paths additional_paths to add to *sys.path* before call the function - @param args additional parameter (dictionary) - @return stdout, stderr - - The function expects to find file ``__init__.py`` in - ``/src/``. - """ - cmd, code = call_setup_hook_cmd(folder=folder, module_name=module_name, - function_name=function_name, - additional_paths=additional_paths, **args) - if use_print: # pragma: no cover - print("CODE:\n", code) - print("CMD:\n", cmd) - - fLOG("[call_setup_hook] calls _setup_hook from", module_name) - if not force_call and sys.platform.startswith("win"): - out, err = run_cmd( # pragma: no cover - cmd, wait=True, fLOG=fLOG, log_error=False) - exit = 0 # pragma: no cover - else: - if use_print: # pragma: no cover - print("subprocess.call", cmd) - if not sys.platform.startswith("win"): - args = shlex.split(cmd) - else: - args = cmd # pragma: no cover - exit = subprocess.call(args) - out = "linux" - err = "" - - if exit != 0: - src = os.path.abspath(os.path.join(folder, "src")) - if not os.path.exists(src): # pragma: no cover - src = os.path.abspath(folder) - if not os.path.exists(src): - raise FileNotFoundError( # pragma: no cover - "Unable to find folder '{}'.".format(folder)) - init = os.path.join(src, module_name, "__init__.py") - with open_script(init, "r") as f: - content = f.read() - sdef = 'def {0}'.format(function_name) - if sdef not in content: - exit = 0 - err = "ImportError: cannot import name '{0}'".format( - function_name) - fLOG("[call_setup_hook] end of call _setup_hook") - - if use_print: # pragma: no cover - print("OUT:\n", out) - if err: - if "cannot import name '_setup_hook'" in err: - fLOG("[call_setup_hook] _setup_hook was not found.") - else: - print("[pyqerror]\n", err) - - def error(): - mes = ("**CMD:\n{3}\n**CODE:\n{0}\n**OUT:\n{1}\n**[pyqerror]" - "\n{2}\nexit={4}").format( # pragma: no cover - code.replace(";", "\n"), out, err, cmd, exit) - return mes # pragma: no cover - - if not must_be and ( - "ImportError: cannot import name '{0}'".format(function_name) in err or - "ImportError: cannot import name {0}".format(function_name) in err): - # no _setup_hook - return out, "no {0}".format(function_name) - if "Error while finding spec " in err: - raise Exception(error()) # pragma: no cover - if "ImportError: No module named" in err: - raise Exception(error()) # pragma: no cover - if exit != 0: - raise Exception(error()) # pragma: no cover - out = "CMD: {0}\n---\n{1}".format(cmd, out) - return out, err diff --git a/src/pyquickhelper/pycode/code_exceptions.py b/src/pyquickhelper/pycode/code_exceptions.py index 71188256a..9b36c0da3 100644 --- a/src/pyquickhelper/pycode/code_exceptions.py +++ b/src/pyquickhelper/pycode/code_exceptions.py @@ -9,10 +9,3 @@ class CoverageException(Exception): raised when an issue happens with the coverage """ pass - - -class SetupHookException(Exception): - """ - raised when something happen while running setup_hook - """ - pass diff --git a/src/pyquickhelper/pycode/setup_helper.py b/src/pyquickhelper/pycode/setup_helper.py index e9b060279..882d625f4 100644 --- a/src/pyquickhelper/pycode/setup_helper.py +++ b/src/pyquickhelper/pycode/setup_helper.py @@ -20,7 +20,7 @@ def get_available_setup_commands(): 'build_ext', 'build_script', 'build_sphinx', 'clean_pyd', 'clean_space', 'copy27', 'copy_dist', 'copy_sphinx', 'history', 'lab', 'local_pypi', 'notebook', 'publish', 'publish_doc', 'register', 'run27', 'run_pylint', - 'sdist', 'setup_hook', 'setupdep', 'test_local_pypi', + 'sdist', 'setupdep', 'test_local_pypi', 'unittests', 'unittests_GUI', 'unittests_LONG', 'unittests_SKIP', 'upload_docs', 'write_version', 'local_jenkins'] return commands @@ -131,14 +131,14 @@ def process_standard_options_for_setup( argv, file_or_folder, project_var_name, module_name=None, unittest_modules=None, pattern_copy=None, requirements=None, port=8067, blog_list=None, default_engine_paths=None, - extra_ext=None, add_htmlhelp=False, setup_params=None, coverage_options=None, + extra_ext=None, add_htmlhelp=False, coverage_options=None, coverage_exclude_lines=None, func_sphinx_begin=None, func_sphinx_end=None, additional_notebook_path=None, additional_local_path=None, copy_add_ext=None, nbformats=("ipynb", "html", "python", "rst", "slides", "pdf", "github"), layout=None, direct_call=False, additional_ut_path=None, - skip_function=None, covtoken=None, hook_print=True, + skip_function=None, covtoken=None, stdout=None, stderr=None, use_run_cmd=False, filter_warning=None, file_filter_pep8=None, github_owner=None, existing_history=None, coverage_root='src', @@ -172,7 +172,6 @@ def process_standard_options_for_setup( @param extra_ext extra file extension to process (add a page for each of them, ex ``["doc"]``) @param add_htmlhelp run HTML Help too (only on Windows) - @param setup_params parameters send to @see fn call_setup_hook @param coverage_options see @see fn main_wrapper_tests @param coverage_exclude_lines see @see fn main_wrapper_tests @param func_sphinx_begin function called before the documentation generation, @@ -194,7 +193,6 @@ def process_standard_options_for_setup( `codecov `_, more in @see fn main_wrapper_tests @param fLOG logging function - @param hook_print enable, disable print when calling *_setup_hook* @param stdout redirect stdout for unit test if not None @param stderr redirect stderr for unit test if not None @param use_run_cmd to run the sphinx documentation with @see fn run_cmd and @@ -365,7 +363,6 @@ def dump_coverage_fct(full=True): elif "build_sphinx" in argv: # delayed import - from .call_setup_hook import call_setup_hook try: from nbconvert.nbconvertapp import main as nbconvert_main if nbconvert_main is None: # pragma: no cover @@ -373,15 +370,6 @@ def dump_coverage_fct(full=True): except AttributeError as e: # pragma: no cover raise ImportError( "Unable to import nbconvert, cannot generate the documentation") from e - if setup_params is None: - setup_params = {} - out, err = call_setup_hook( - folder, project_var_name if module_name is None else module_name, - fLOG=fLOG, **setup_params) - if len(err) > 0 and err != "no _setup_hook": - raise Exception( # pragma: no cover - "Unable to run _setup_hook\nOUT:\n{0}\n[setuperror]\n" - "{1}".format(out, err)) if func_sphinx_begin is not None: func_sphinx_begin( @@ -392,7 +380,7 @@ def dump_coverage_fct(full=True): requirements=requirements, port=port, blog_list=blog_list, default_engine_paths=default_engine_paths, extra_ext=extra_ext, add_htmlhelp=add_htmlhelp, - setup_params=setup_params, coverage_options=coverage_options, + coverage_options=coverage_options, coverage_exclude_lines=coverage_exclude_lines, func_sphinx_begin=func_sphinx_begin, func_sphinx_end=func_sphinx_end, @@ -417,7 +405,7 @@ def dump_coverage_fct(full=True): requirements=requirements, port=port, blog_list=blog_list, default_engine_paths=default_engine_paths, extra_ext=extra_ext, add_htmlhelp=add_htmlhelp, - setup_params=setup_params, coverage_options=coverage_options, + coverage_options=coverage_options, coverage_exclude_lines=coverage_exclude_lines, func_sphinx_begin=func_sphinx_begin, func_sphinx_end=func_sphinx_end, @@ -431,35 +419,24 @@ def dump_coverage_fct(full=True): elif "unittests" in argv: skip_f = process_argv_for_unittest(argv, skip_function) run_unittests_for_setup( - file_or_folder, setup_params=setup_params, + file_or_folder, coverage_options=coverage_options, coverage_exclude_lines=coverage_exclude_lines, additional_ut_path=additional_ut_path, skip_function=skip_f, covtoken=covtoken, - hook_print=hook_print, stdout=stdout, stderr=stderr, + stdout=stdout, stderr=stderr, filter_warning=filter_warning, dump_coverage=dump_coverage_fct(), add_coverage_folder=dump_coverage_fct(False), coverage_root=coverage_root, fLOG=fLOG) return True - elif "setup_hook" in argv: # pragma: no cover - fLOG("---- JENKINS BEGIN SETUPHOOK ----") - run_unittests_for_setup( - file_or_folder, setup_params=setup_params, only_setup_hook=True, - coverage_options=coverage_options, coverage_exclude_lines=coverage_exclude_lines, - additional_ut_path=additional_ut_path, skip_function=skip_function, - hook_print=hook_print, stdout=stdout, stderr=stderr, dump_coverage=dump_coverage_fct(), - fLOG=fLOG) - fLOG("---- JENKINS END SETUPHOOK ----") - return True - elif "unittests_LONG" in argv: def skip_long(name, code, duration): return "test_LONG_" not in name run_unittests_for_setup( - file_or_folder, skip_function=skip_long, setup_params=setup_params, + file_or_folder, skip_function=skip_long, coverage_options=coverage_options, coverage_exclude_lines=coverage_exclude_lines, - additional_ut_path=additional_ut_path, hook_print=hook_print, + additional_ut_path=additional_ut_path, stdout=stdout, stderr=stderr, dump_coverage=dump_coverage_fct(), fLOG=fLOG) return True @@ -468,9 +445,9 @@ def skip_long(name, code, duration): def skip_skip(name, code, duration): return "test_SKIP_" not in name run_unittests_for_setup( - file_or_folder, skip_function=skip_skip, setup_params=setup_params, + file_or_folder, skip_function=skip_skip, coverage_options=coverage_options, coverage_exclude_lines=coverage_exclude_lines, - additional_ut_path=additional_ut_path, hook_print=hook_print, + additional_ut_path=additional_ut_path, stdout=stdout, stderr=stderr, dump_coverage=dump_coverage_fct(), fLOG=fLOG) return True @@ -479,9 +456,9 @@ def skip_skip(name, code, duration): def skip_skip(name, code, duration): return "test_GUI_" not in name run_unittests_for_setup( - file_or_folder, skip_function=skip_skip, setup_params=setup_params, + file_or_folder, skip_function=skip_skip, coverage_options=coverage_options, coverage_exclude_lines=coverage_exclude_lines, - additional_ut_path=additional_ut_path, hook_print=hook_print, + additional_ut_path=additional_ut_path, stdout=stdout, stderr=stderr, dump_coverage=dump_coverage_fct(), fLOG=fLOG) return True @@ -504,7 +481,7 @@ def skip_skip(name, code, duration): "write_version", "clean_pyd", "build_sphinx", "unittests", "unittests_LONG", "unittests_SKIP", "unittests_GUI", - "unittests -d 5", "setup_hook", "copy27", + "unittests -d 5", "copy27", "local_pypi", 'run_pylint'): sc = get_script_command( c, project_var_name, requirements=requirements, port=port, platform=sys.platform, @@ -775,9 +752,9 @@ def standard_help_for_setup(argv, file_or_folder, project_var_name, module_name= direct_call=direct_call, fexclude=fexclude) -def run_unittests_for_setup(file_or_folder, skip_function=None, 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, +def run_unittests_for_setup(file_or_folder, skip_function=None, + coverage_options=None, coverage_exclude_lines=None, + additional_ut_path=None, covtoken=None, stdout=None, stderr=None, filter_warning=None, dump_coverage=None, add_coverage_folder=None, coverage_root='src', fLOG=None): """ @@ -787,13 +764,10 @@ def run_unittests_for_setup(file_or_folder, skip_function=None, setup_params=Non @param file_or_folder file ``setup.py`` or folder which contains it @param skip_function see @see fn main_wrapper_tests - @param setup_params see @see fn main_wrapper_tests - @param only_setup_hook see @see fn main_wrapper_tests @param coverage_options see @see fn main_wrapper_tests @param coverage_exclude_lines see @see fn main_wrapper_tests @param additional_ut_path see @see fn main_wrapper_tests @param covtoken see @see fn main_wrapper_tests - @param hook_print see @see fn main_wrapper_tests @param stdout see @see fn main_wrapper_tests @param stderr see @see fn main_wrapper_tests @param filter_warning see @see fn main_wrapper_tests @@ -839,10 +813,10 @@ def run_unittests_for_setup(file_or_folder, skip_function=None, setup_params=Non logfile = os.path.join(funit, "unittests.out") main_wrapper_tests( - logfile, add_coverage=cov, skip_function=skip_function, setup_params=setup_params, - only_setup_hook=only_setup_hook, coverage_options=coverage_options, + logfile, add_coverage=cov, skip_function=skip_function, + 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, + covtoken=covtoken, stdout=stdout, stderr=stderr, filter_warning=filter_warning, dump_coverage=dump_coverage, add_coverage_folder=add_coverage_folder, coverage_root=coverage_root, fLOG=fLOG) @@ -928,7 +902,6 @@ def process_standard_options_for_setup_help(argv): "local_jenkins": "sets up jobs on a local jenkins server", "run27": "run the unit tests for the Python 2.7", "run_pylint": "run pylint on the sources, allowed parameters ", - "setup_hook": "call function setup_hook which initializes the module before running unit tests", "unittests": "run the unit tests which do not contain test_LONG, test_SKIP or test_GUI in their file name", "unittests_LONG": "run the unit tests which contain test_LONG their file name", "unittests_SKIP": "run the unit tests which contain test_SKIP their file name", diff --git a/src/pyquickhelper/pycode/utils_tests.py b/src/pyquickhelper/pycode/utils_tests.py index ddd46d93d..ab1d86bd4 100644 --- a/src/pyquickhelper/pycode/utils_tests.py +++ b/src/pyquickhelper/pycode/utils_tests.py @@ -40,10 +40,10 @@ def _modifies_coverage_report(name, bsrcp, bproj): def main_wrapper_tests(logfile, skip_list=None, processes=False, add_coverage=False, - report_folder=None, skip_function=None, setup_params=None, - only_setup_hook=False, coverage_options=None, + report_folder=None, skip_function=None, + coverage_options=None, coverage_exclude_lines=None, additional_ut_path=None, - covtoken=None, hook_print=True, stdout=None, stderr=None, + covtoken=None, stdout=None, stderr=None, filter_warning=None, dump_coverage=None, add_coverage_folder=None, coverage_root="src", fLOG=None): """ @@ -59,14 +59,11 @@ def main_wrapper_tests(logfile, skip_list=None, processes=False, add_coverage=Fa @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 @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 @param coverage_options (dict) options for module coverage as a dictionary, see below, default is None @param coverage_exclude_lines (list) options for module coverage, lines to exclude from the coverage report, defaul is None @param additional_ut_path (list) additional paths to add when running the unit tests @param covtoken (str|tuple(str, str)) token used when publishing coverage report to `codecov `_ or None to not publish - @param hook_print enable print display when calling *_setup_hook* @param stdout if not None, write output on this stream instead of *sys.stdout* @param stderr if not None, write errors on this stream instead of *sys.stderr* @param filter_warning function which removes some warnings in the final output, @@ -119,18 +116,6 @@ def main_wrapper_tests(logfile, skip_list=None, processes=False, add_coverage=Fa generating-matplotlib-graphs-without-a-running-x-server>`_. If the skip function is None, it will replace it by the function @see fn default_skip_function. - Calls function @see fn _setup_hook if it is available - in the unit tested module. Parameter *tested_module* was added, - the function then checks the presence of - function @see fn _setup_hook, it is the case, it runs it. - - Parameter *setup_params*: a mechanism was put in place - to let the module to test a possibility to run some preprocessing steps - in a separate process. They are described in @see fn _setup_hook - which must be found in the main file ``__init__.py``. - Parameter *only_setup_hook*: - saves the report in XML format, binary format, - replace full paths by relative path. Parameters *coverage_options*, *coverage_exclude_lines*, *additional_ut_path*: see class `Coverage `_ @@ -217,36 +202,6 @@ def run_main(): "matplotlib" in sys.modules, "first execution", _first_execution) fLOG("[main_wrapper_tests] fix_tkinter_issues_virtualenv", r) - def tested_module(folder, project_var_name, setup_params): - # module mod - # delayed import - from .call_setup_hook import call_setup_hook - if setup_params is None: - setup_params = {} - out, err = call_setup_hook( - folder, project_var_name, fLOG=fLOG, use_print=hook_print, **setup_params) - if len(err) > 0 and err != "no _setup_hook": # pragma: no cover - # fix introduced because pip 8.0 displays annoying warnings - # RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect - # RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python - # ABI tag may be incorrect - lines = err.split("\n") - keep = [] - for line in lines: - line = line.rstrip("\r\t ") - if (line and not line.startswith(" ") and - "RuntimeWarning: Config variable" not in line): - keep.append(line) - if len(keep) > 0: - raise SetupHookException( - "Unable to run _setup_hook\n**OUT:\n{0}\n**[pyqerror]" - "\n{1}\n**FOLDER:\n{2}\n**NAME:\n{3}\n**KEEP:\n{4}\n**" - "".format(out, err, folder, project_var_name, - "\n".join(keep))) - out += "\nWARNINGS:\n" + err - err = None - return out, err - # project_var_name folder = os.path.normpath( os.path.join(os.path.dirname(logfile), "..", "src")) @@ -295,10 +250,7 @@ def selec_name(folder, name): "The location of the source should not contain " "'{0}': {1}".format(get_user(), srcp)) - if only_setup_hook: - tested_module(src_abs, project_var_name, setup_params) - - else: + if True: # coverage if add_coverage: # pragma: no cover stdout_this.write("[main_wrapper_tests] --- COVERAGE BEGIN ---\n") @@ -307,11 +259,6 @@ def selec_name(folder, name): os.path.abspath(os.path.dirname(logfile)), "..", "_doc", "sphinxdoc", "source", "coverage") - fLOG("[main_wrapper_tests] call _setup_hook", - src_abs, "name=", project_var_name) - tested_module(src_abs, project_var_name, setup_params) - fLOG("[main_wrapper_tests] end _setup_hook") - fLOG("[main_wrapper_tests] current folder", os.getcwd()) fLOG("[main_wrapper_tests] enabling coverage", srcp) dfile = os.path.join(report_folder, ".coverage") @@ -509,7 +456,6 @@ def write_covlog(covs): if covtoken and (not isinstance(covtoken, tuple) or eval(covtoken[1])): raise CoverageException( # pragma: no cover "covtoken is not null but add_coverage is not True, coverage cannot be published") - tested_module(src_abs, project_var_name, setup_params) res = run_main() stdout_this.write("[main_wrapper_tests] --- NO COVERAGE END ---\n") diff --git a/src/pyquickhelper/pycode/windows_scripts.py b/src/pyquickhelper/pycode/windows_scripts.py index 86ec4c743..4e1612718 100644 --- a/src/pyquickhelper/pycode/windows_scripts.py +++ b/src/pyquickhelper/pycode/windows_scripts.py @@ -257,24 +257,11 @@ def _sversion(): """.replace("PY??", _sversion()) -################# -#: setup_hook for Windows -################# - -windows_setup_hook = """ -@echo SCRIPT: windows_setup_hook -@echo #######################################################_setup_hook -@echo ~CALL %pythonexe% %current%setup.py setup_hook -%pythonexe% %current%setup.py setup_hook -if %errorlevel% neq 0 exit /b %errorlevel% -@echo #######################################################_END_BASE -""" - ################# #: build script for Windows ################# -windows_any_setup_command = windows_any_setup_command_base + windows_setup_hook + """ +windows_any_setup_command = windows_any_setup_command_base + """ @echo ~CALL %pythonexe% -u %current%setup.py %3 %4 %5 %6 %7 %8 %9 rem set PYTHONPATH=additional_path %pythonexe% -u %current%setup.py %3 %4 %5 %6 %7 %8 %9 @@ -292,7 +279,7 @@ def _sversion(): #: build setup script for Windows ################# -windows_build_setup = windows_any_setup_command_base + windows_setup_hook + """ +windows_build_setup = windows_any_setup_command_base + """ @echo ~CALL %pythonexe% %current%setup.py sdist %2 --formats=gztar,zip --verbose %pythonexe% %current%setup.py sdist %2 --formats=gztar,zip --verbose if %errorlevel% neq 0 exit /b %errorlevel% @@ -306,7 +293,7 @@ def _sversion(): ################# #: build script MAIN SCRIPT ################# -windows_build = windows_any_setup_command_base + windows_setup_hook + """ +windows_build = windows_any_setup_command_base + """ @echo #######################################################_unit @echo ~CALL %pythonexe% -u %current%setup.py unittests rem set PYTHONPATH=additional_path --> we use a virtual environment here @@ -569,8 +556,6 @@ def _sversion(): + "\n__PACTHPQb__\n" + jenkins_windows_setup + " build_script\n" + windows_error - + "\n@echo ~CALL %jenkinspythonexe% %current%setup.py setup_hook\n%jenkinspythonexe% %current%setup.py setup_hook\n" - + windows_error + "\nauto_setup_co + y27.bat %jenkinspythonexe%\n" + windows_error, # next script # "\n__PACTHPQe__\n" + @@ -593,8 +578,6 @@ def _sversion(): "\n__PACTHPQb__\n" + jenkins_windows_setup + " build_script\n" + windows_error + - "\n@echo ~CALL %jenkinspythonexe% %current%setup.py setup_hook\n%jenkinspythonexe% %current%setup.py setup_hook\n" + - windows_error + "\nauto_setup_copy27.bat %jenkinspythonexe%\n" + windows_error, # next script # diff --git a/src/quicksetup/pyquicksetup/pyquick.py b/src/quicksetup/pyquicksetup/pyquick.py index 599a76601..e1bf1766a 100644 --- a/src/quicksetup/pyquicksetup/pyquick.py +++ b/src/quicksetup/pyquicksetup/pyquick.py @@ -11,7 +11,6 @@ * unittests_LONG * * unittests_SKIP * * unittests_GUI * -* setup_hook * write_version """ import os From 329acb1095a313e8862eada9f985b0f7e86f2751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Sun, 28 Nov 2021 18:05:45 +0100 Subject: [PATCH 2/3] Update utils_tests.py --- src/pyquickhelper/pycode/utils_tests.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pyquickhelper/pycode/utils_tests.py b/src/pyquickhelper/pycode/utils_tests.py index ab1d86bd4..fca8f10e1 100644 --- a/src/pyquickhelper/pycode/utils_tests.py +++ b/src/pyquickhelper/pycode/utils_tests.py @@ -8,8 +8,7 @@ from datetime import datetime import warnings import sqlite3 -from .code_exceptions import ( - CoverageException, SetupHookException) +from .code_exceptions import CoverageException from .coverage_helper import ( publish_coverage_on_codecov, find_coverage_report, coverage_combine) From d0b5730e5f4acf68aafbd34ed57f9d1e16a6e492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Sun, 28 Nov 2021 22:07:24 +0100 Subject: [PATCH 3/3] Delete test_call_setup_hook.py --- _unittests/ut_module/test_call_setup_hook.py | 94 -------------------- 1 file changed, 94 deletions(-) delete mode 100644 _unittests/ut_module/test_call_setup_hook.py diff --git a/_unittests/ut_module/test_call_setup_hook.py b/_unittests/ut_module/test_call_setup_hook.py deleted file mode 100644 index 4d4344c74..000000000 --- a/_unittests/ut_module/test_call_setup_hook.py +++ /dev/null @@ -1,94 +0,0 @@ -""" -@brief test log(time=10s) -""" -import sys -import os -import unittest - -from pyquickhelper.loghelper import fLOG -from pyquickhelper import __file__ as PYQ - - -class TestCallSetupHook(unittest.TestCase): - - @unittest.skipIf(sys.platform == "darwin", reason="skipping on Mac OS") - def test_call_setup_hook_cmd(self): - fLOG( - __file__, - self._testMethodName, - OutputPrint=__name__ == "__main__") - cmd, code = call_setup_hook_cmd("c:/__MOCK__", "pyquickhelper", check=False, - interpreter_path="__PYTHON__") - pyq = os.path.normpath(os.path.join(os.path.abspath(PYQ), "..", "..")) - exp = '''__PYTHON__ -c "import sys;sys.path.append('c:/__MOCK__/src');sys.path.append('__PYQ__');''' + \ - '''from pyquickhelper import _setup_hook;_setup_hook();sys.exit(0)"''' - exp = exp.replace("__PYQ__", pyq.replace("\\", "/")) - cmd = cmd.replace("/home/travis/build/sdpython/pyquickhelper/", "") - exp = exp.replace("/home/travis/build/sdpython/pyquickhelper/", "") - cmd = cmd.replace("/home/circleci/repo/src/", "") - exp = exp.replace("/home/circleci/repo/src/", "") - cmd = cmd.replace("/home/circleci/repo/", "") - exp = exp.replace("/home/circleci/repo/", "") - cmd = cmd.replace("/root/github/pyquickhelper/", "") - exp = exp.replace("/root/github/pyquickhelper/", "") - cmd = cmd.replace("/home/vsts/work/1/s/", "") - exp = exp.replace("/home/vsts/work/1/s/", "") - for sub in ["/Users/vsts/agent/2.144.0/work/1/s/", - "/Users/vsts/agent/2.144.2/work/1/s/"]: - cmd = cmd.replace(sub, "") - exp = exp.replace(sub, "") - rem = "/var/lib/jenkins/workspace/pyquickhelper/pyquickhelper_UT_%d%d_std/" % sys.version_info[:2] - cmd = cmd.replace(rem, "") - exp = exp.replace(rem, "") - if exp != cmd and "UT_SPHINX" not in cmd: - raise Exception("\nCMD: {0}\nEXP: {1}".format(cmd, exp)) - - def test_call_setup_hook(self): - fLOG( - __file__, - self._testMethodName, - OutputPrint=__name__ == "__main__") - init = os.path.join( - os.path.split(__file__)[0], - "..", - "..") - out, err = call_setup_hook( - init, "pyquickhelper", fLOG=fLOG, function_name="______") - fLOG(err) - fLOG(out) - if not(err == "no ______" or "linux" in out): - raise Exception("OUT:\n{0}\nERR:\n{1}".format(out, err)) - - out, err = call_setup_hook( - init, "pyquickhelper", fLOG=fLOG, use_print=False) - fLOG(err) - fLOG(out) - self.assertEqual(err, "") - - def test_call_setup_hook_call(self): - fLOG( - __file__, - self._testMethodName, - OutputPrint=__name__ == "__main__") - init = os.path.join( - os.path.split(__file__)[0], - "..", - "..") - out, err = call_setup_hook( - init, "pyquickhelper", fLOG=fLOG, function_name="______", force_call=True) - fLOG(err) - fLOG(out) - if not(err == "no ______" or "linux" in out): - raise Exception("OUT:\n{0}\nERR:\n{1}".format(out, err)) - - out, err = call_setup_hook( - init, "pyquickhelper", fLOG=fLOG, force_call=True, - additional_paths=["not a path"], - unit_test=True, use_print=False) - fLOG(err) - fLOG(out) - self.assertEqual(err, "") - - -if __name__ == "__main__": - unittest.main()