Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/numpy/_pytesttester.py
7756 views
"""1Pytest test running.23This module implements the ``test()`` function for NumPy modules. The usual4boiler plate for doing that is to put the following in the module5``__init__.py`` file::67from numpy._pytesttester import PytestTester8test = PytestTester(__name__)9del PytestTester101112Warnings filtering and other runtime settings should be dealt with in the13``pytest.ini`` file in the numpy repo root. The behavior of the test depends on14whether or not that file is found as follows:1516* ``pytest.ini`` is present (develop mode)17All warnings except those explicitly filtered out are raised as error.18* ``pytest.ini`` is absent (release mode)19DeprecationWarnings and PendingDeprecationWarnings are ignored, other20warnings are passed through.2122In practice, tests run from the numpy repo are run in develop mode. That23includes the standard ``python runtests.py`` invocation.2425This module is imported by every numpy subpackage, so lies at the top level to26simplify circular import issues. For the same reason, it contains no numpy27imports at module scope, instead importing numpy within function calls.28"""29import sys30import os3132__all__ = ['PytestTester']33343536def _show_numpy_info():37import numpy as np3839print("NumPy version %s" % np.__version__)40relaxed_strides = np.ones((10, 1), order="C").flags.f_contiguous41print("NumPy relaxed strides checking option:", relaxed_strides)42info = np.lib.utils._opt_info()43print("NumPy CPU features: ", (info if info else 'nothing enabled'))44454647class PytestTester:48"""49Pytest test runner.5051A test function is typically added to a package's __init__.py like so::5253from numpy._pytesttester import PytestTester54test = PytestTester(__name__).test55del PytestTester5657Calling this test function finds and runs all tests associated with the58module and all its sub-modules.5960Attributes61----------62module_name : str63Full path to the package to test.6465Parameters66----------67module_name : module name68The name of the module to test.6970Notes71-----72Unlike the previous ``nose``-based implementation, this class is not73publicly exposed as it performs some ``numpy``-specific warning74suppression.7576"""77def __init__(self, module_name):78self.module_name = module_name7980def __call__(self, label='fast', verbose=1, extra_argv=None,81doctests=False, coverage=False, durations=-1, tests=None):82"""83Run tests for module using pytest.8485Parameters86----------87label : {'fast', 'full'}, optional88Identifies the tests to run. When set to 'fast', tests decorated89with `pytest.mark.slow` are skipped, when 'full', the slow marker90is ignored.91verbose : int, optional92Verbosity value for test outputs, in the range 1-3. Default is 1.93extra_argv : list, optional94List with any extra arguments to pass to pytests.95doctests : bool, optional96.. note:: Not supported97coverage : bool, optional98If True, report coverage of NumPy code. Default is False.99Requires installation of (pip) pytest-cov.100durations : int, optional101If < 0, do nothing, If 0, report time of all tests, if > 0,102report the time of the slowest `timer` tests. Default is -1.103tests : test or list of tests104Tests to be executed with pytest '--pyargs'105106Returns107-------108result : bool109Return True on success, false otherwise.110111Notes112-----113Each NumPy module exposes `test` in its namespace to run all tests for114it. For example, to run all tests for numpy.lib:115116>>> np.lib.test() #doctest: +SKIP117118Examples119--------120>>> result = np.lib.test() #doctest: +SKIP121...1221023 passed, 2 skipped, 6 deselected, 1 xfailed in 10.39 seconds123>>> result124True125126"""127import pytest128import warnings129130module = sys.modules[self.module_name]131module_path = os.path.abspath(module.__path__[0])132133# setup the pytest arguments134pytest_args = ["-l"]135136# offset verbosity. The "-q" cancels a "-v".137pytest_args += ["-q"]138139with warnings.catch_warnings():140warnings.simplefilter("always")141# Filter out distutils cpu warnings (could be localized to142# distutils tests). ASV has problems with top level import,143# so fetch module for suppression here.144from numpy.distutils import cpuinfo145146with warnings.catch_warnings(record=True):147# Ignore the warning from importing the array_api submodule. This148# warning is done on import, so it would break pytest collection,149# but importing it early here prevents the warning from being150# issued when it imported again.151import numpy.array_api152153# Filter out annoying import messages. Want these in both develop and154# release mode.155pytest_args += [156"-W ignore:Not importing directory",157"-W ignore:numpy.dtype size changed",158"-W ignore:numpy.ufunc size changed",159"-W ignore::UserWarning:cpuinfo",160]161162# When testing matrices, ignore their PendingDeprecationWarnings163pytest_args += [164"-W ignore:the matrix subclass is not",165"-W ignore:Importing from numpy.matlib is",166]167168if doctests:169raise ValueError("Doctests not supported")170171if extra_argv:172pytest_args += list(extra_argv)173174if verbose > 1:175pytest_args += ["-" + "v"*(verbose - 1)]176177if coverage:178pytest_args += ["--cov=" + module_path]179180if label == "fast":181# not importing at the top level to avoid circular import of module182from numpy.testing import IS_PYPY183if IS_PYPY:184pytest_args += ["-m", "not slow and not slow_pypy"]185else:186pytest_args += ["-m", "not slow"]187188elif label != "full":189pytest_args += ["-m", label]190191if durations >= 0:192pytest_args += ["--durations=%s" % durations]193194if tests is None:195tests = [self.module_name]196197pytest_args += ["--pyargs"] + list(tests)198199# run tests.200_show_numpy_info()201202try:203code = pytest.main(pytest_args)204except SystemExit as exc:205code = exc.code206207return code == 0208209210