当前位置: 首页>>代码示例>>Python>>正文


Python testing.suppress_warnings方法代码示例

本文整理汇总了Python中numpy.testing.suppress_warnings方法的典型用法代码示例。如果您正苦于以下问题:Python testing.suppress_warnings方法的具体用法?Python testing.suppress_warnings怎么用?Python testing.suppress_warnings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.testing的用法示例。


在下文中一共展示了testing.suppress_warnings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fcompiler_flags_append_warning

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import suppress_warnings [as 别名]
def test_fcompiler_flags_append_warning(monkeypatch):
    # Test to check that the warning for append behavior changing in future
    # is triggered.  Need to use a real compiler instance so that we have
    # non-empty flags to start with (otherwise the "if var and append" check
    # will always be false).
    try:
        with suppress_warnings() as sup:
            sup.record()
            fc = numpy.distutils.fcompiler.new_fcompiler(compiler='gnu95')
            fc.customize()
    except numpy.distutils.fcompiler.CompilerNotFound:
        pytest.skip("gfortran not found, so can't execute this test")

    # Ensure NPY_DISTUTILS_APPEND_FLAGS not defined
    monkeypatch.delenv('NPY_DISTUTILS_APPEND_FLAGS', raising=False)

    for opt, envvar in customizable_flags:
        new_flag = '-dummy-{}-flag'.format(opt)
        with suppress_warnings() as sup:
            sup.record()
            prev_flags = getattr(fc.flag_vars, opt)

        monkeypatch.setenv(envvar, new_flag)
        with suppress_warnings() as sup:
            sup.record()
            new_flags = getattr(fc.flag_vars, opt)
            if prev_flags:
                # Check that warning was issued
                assert len(sup.log) == 1

        monkeypatch.delenv(envvar)
        assert_(new_flags == [new_flag]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:34,代码来源:test_fcompiler.py

示例2: __enter__

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import suppress_warnings [as 别名]
def __enter__(self):
            if self._entered:
                raise RuntimeError("cannot enter suppress_warnings twice.")

            self._orig_show = warnings.showwarning
            self._filters = warnings.filters
            warnings.filters = self._filters[:]

            self._entered = True
            self._tmp_suppressions = []
            self._tmp_modules = set()
            self._forwarded = set()

            self.log = []  # reset global log (no need to keep same list)

            for cat, mess, _, mod, log in self._suppressions:
                if log is not None:
                    del log[:]  # clear the log
                if mod is None:
                    warnings.filterwarnings(
                        "always", category=cat, message=mess)
                else:
                    module_regex = mod.__name__.replace('.', r'\.') + '$'
                    warnings.filterwarnings(
                        "always", category=cat, message=mess,
                        module=module_regex)
                    self._tmp_modules.add(mod)
            warnings.showwarning = self._showwarning
            self._clear_registries()

            return self 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:33,代码来源:_numpy_compat.py

示例3: test_py2_float_print

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import suppress_warnings [as 别名]
def test_py2_float_print(self):
        # gh-10753
        # In python2, the python float type implements an obsolte method
        # tp_print, which overrides tp_repr and tp_str when using "print" to
        # output to a "real file" (ie, not a StringIO). Make sure we don't
        # inherit it.
        x = np.double(0.1999999999999)
        with TemporaryFile('r+t') as f:
            print(x, file=f)
            f.seek(0)
            output = f.read()
        assert_equal(output, str(x) + '\n')
        # In python2 the value float('0.1999999999999') prints with reduced
        # precision as '0.2', but we want numpy's np.double('0.1999999999999')
        # to print the unique value, '0.1999999999999'.

        # gh-11031
        # Only in the python2 interactive shell and when stdout is a "real"
        # file, the output of the last command is printed to stdout without
        # Py_PRINT_RAW (unlike the print statement) so `>>> x` and `>>> print
        # x` are potentially different. Make sure they are the same. The only
        # way I found to get prompt-like output is using an actual prompt from
        # the 'code' module. Again, must use tempfile to get a "real" file.

        # dummy user-input which enters one line and then ctrl-Ds.
        def userinput():
            yield 'np.sqrt(2)'
            raise EOFError
        gen = userinput()
        input_func = lambda prompt="": next(gen)

        with TemporaryFile('r+t') as fo, TemporaryFile('r+t') as fe:
            orig_stdout, orig_stderr = sys.stdout, sys.stderr
            sys.stdout, sys.stderr = fo, fe

            # py2 code.interact sends irrelevant internal DeprecationWarnings
            with suppress_warnings() as sup:
                sup.filter(DeprecationWarning)
                code.interact(local={'np': np}, readfunc=input_func, banner='')

            sys.stdout, sys.stderr = orig_stdout, orig_stderr

            fo.seek(0)
            capture = fo.read().strip()

        assert_equal(capture, repr(np.sqrt(2))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:48,代码来源:test_scalarprint.py


注:本文中的numpy.testing.suppress_warnings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。