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


Python test_support.check_warnings方法代码示例

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


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

示例1: test_main

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_main():
    # Check the doctest cases in doctest itself:
    test_support.run_doctest(doctest, verbosity=True)

    from test import test_doctest

    # Ignore all warnings about the use of class Tester in this module.
    deprecations = []
    if __debug__:
        deprecations.append(("class Tester is deprecated", DeprecationWarning))
    if sys.py3kwarning:
        deprecations += [("backquote not supported", SyntaxWarning),
                         ("execfile.. not supported", DeprecationWarning)]
    with test_support.check_warnings(*deprecations):
        # Check the doctest cases defined here:
        test_support.run_doctest(test_doctest, verbosity=True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_doctest.py

示例2: test_format

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_format(self):
        buf = create_string_buffer(' ' * 100)

        tests = [
            ('%f', 100.0),
            ('%g', 100.0),
            ('%#g', 100.0),
            ('%#.2g', 100.0),
            ('%#.2g', 123.4567),
            ('%#.2g', 1.234567e200),
            ('%e', 1.234567e200),
            ('%e', 1.234),
            ('%+e', 1.234),
            ('%-e', 1.234),
            ]

        with check_warnings(('PyOS_ascii_formatd is deprecated',
                             DeprecationWarning)):
            for format, val in tests:
                PyOS_ascii_formatd(byref(buf), sizeof(buf), format,
                                   c_double(val))
                self.assertEqual(buf.value, format % val) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_ascii_formatd.py

示例3: test_basic_auth_with_unquoted_realm

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_basic_auth_with_unquoted_realm(self):
        opener = OpenerDirector()
        password_manager = MockPasswordManager()
        auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
        realm = "ACME Widget Store"
        http_handler = MockHTTPHandler(
            401, 'WWW-Authenticate: Basic realm=%s\r\n\r\n' % realm)
        opener.add_handler(auth_handler)
        opener.add_handler(http_handler)
        msg = "Basic Auth Realm was unquoted"
        with test_support.check_warnings((msg, UserWarning)):
            self._test_basic_auth(opener, auth_handler, "Authorization",
                                  realm, http_handler, password_manager,
                                  "http://acme.example.com/protected",
                                  "http://acme.example.com/protected"
                                 ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_urllib2.py

示例4: check_all

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def check_all(self, modname):
        names = {}
        with support.check_warnings((".* (module|package)",
                                     DeprecationWarning), quiet=True):
            try:
                exec "import %s" % modname in names
            except:
                # Silent fail here seems the best route since some modules
                # may not be available or not initialize properly in all
                # environments.
                raise FailedImport(modname)
        if not hasattr(sys.modules[modname], "__all__"):
            raise NoAll(modname)
        names = {}
        try:
            exec "from %s import *" % modname in names
        except Exception as e:
            # Include the module name in the exception string
            self.fail("__all__ failure in {}: {}: {}".format(
                      modname, e.__class__.__name__, e))
        if "__builtins__" in names:
            del names["__builtins__"]
        keys = set(names)
        all = set(sys.modules[modname].__all__)
        self.assertEqual(keys, all) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test___all__.py

示例5: test_exclude

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_exclude(self):
        tempdir = os.path.join(TEMPDIR, "exclude")
        os.mkdir(tempdir)
        try:
            for name in ("foo", "bar", "baz"):
                name = os.path.join(tempdir, name)
                open(name, "wb").close()

            exclude = os.path.isfile

            tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
            with test_support.check_warnings(("use the filter argument",
                                              DeprecationWarning)):
                tar.add(tempdir, arcname="empty_dir", exclude=exclude)
            tar.close()

            tar = tarfile.open(tmpname, "r")
            self.assertEqual(len(tar.getmembers()), 1)
            self.assertEqual(tar.getnames()[0], "empty_dir")
        finally:
            shutil.rmtree(tempdir) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:test_tarfile.py

示例6: __init__

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def __init__(self, quiet=False):
        if sys.flags.optimize >= 2:
            # under -OO, doctests cannot be run and therefore not all warnings
            # will be emitted
            quiet = True
        deprecations = (
            # Search behaviour is broken if search path starts with "/".
            ("This search is broken in 1.3 and earlier, and will be fixed "
             "in a future version.  If you rely on the current behaviour, "
             "change it to '.+'", FutureWarning),
            # Element.getchildren() and Element.getiterator() are deprecated.
            ("This method will be removed in future versions.  "
             "Use .+ instead.", DeprecationWarning),
            ("This method will be removed in future versions.  "
             "Use .+ instead.", PendingDeprecationWarning),
            # XMLParser.doctype() is deprecated.
            ("This method of XMLParser is deprecated.  Define doctype.. "
             "method on the TreeBuilder target.", DeprecationWarning))
        self.checkwarnings = test_support.check_warnings(*deprecations,
                                                         quiet=quiet) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:22,代码来源:test_xml_etree.py

示例7: testAssertDictContainsSubset

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def testAssertDictContainsSubset(self):
        self.assertDictContainsSubset({}, {})
        self.assertDictContainsSubset({}, {'a': 1})
        self.assertDictContainsSubset({'a': 1}, {'a': 1})
        self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2})
        self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2})

        with self.assertRaises(self.failureException):
            self.assertDictContainsSubset({1: "one"}, {})

        with self.assertRaises(self.failureException):
            self.assertDictContainsSubset({'a': 2}, {'a': 1})

        with self.assertRaises(self.failureException):
            self.assertDictContainsSubset({'c': 1}, {'a': 1})

        with self.assertRaises(self.failureException):
            self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})

        with self.assertRaises(self.failureException):
            self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})

        with test_support.check_warnings(("", UnicodeWarning)):
            one = ''.join(chr(i) for i in range(255))
            # this used to cause a UnicodeDecodeError constructing the failure msg
            with self.assertRaises(self.failureException):
                self.assertDictContainsSubset({'foo': one}, {'foo': u'\uFFFD'}) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_case.py

示例8: testPendingDeprecationMethodNames

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def testPendingDeprecationMethodNames(self):
        """Test fail* methods pending deprecation, they will warn in 3.2.

        Do not use these methods.  They will go away in 3.3.
        """
        with test_support.check_warnings():
            self.failIfEqual(3, 5)
            self.failUnlessEqual(3, 3)
            self.failUnlessAlmostEqual(2.0, 2.0)
            self.failIfAlmostEqual(3.0, 5.0)
            self.failUnless(True)
            self.failUnlessRaises(TypeError, lambda _: 3.14 + u'spam')
            self.failIf(False) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_case.py

示例9: assertOldResultWarning

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def assertOldResultWarning(self, test, failures):
        with test_support.check_warnings(("TestResult has no add.+ method,",
                                          RuntimeWarning)):
            result = OldResult()
            test.run(result)
            self.assertEqual(len(result.failures), failures) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_result.py

示例10: test_check_metadata_deprecated

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_check_metadata_deprecated(self):
        # makes sure make_metadata is deprecated
        dist, cmd = self.get_cmd()
        with check_warnings() as w:
            warnings.simplefilter("always")
            cmd.check_metadata()
            self.assertEqual(len(w.warnings), 1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_sdist.py

示例11: test_compress_deprecated

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_compress_deprecated(self):
        tmpdir, tmpdir2, base_name =  self._create_files()

        # using compress and testing the PendingDeprecationWarning
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            with check_warnings() as w:
                warnings.simplefilter("always")
                make_tarball(base_name, 'dist', compress='compress')
        finally:
            os.chdir(old_dir)
        tarball = base_name + '.tar.Z'
        self.assertTrue(os.path.exists(tarball))
        self.assertEqual(len(w.warnings), 1)

        # same test with dry_run
        os.remove(tarball)
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            with check_warnings() as w:
                warnings.simplefilter("always")
                make_tarball(base_name, 'dist', compress='compress',
                             dry_run=True)
        finally:
            os.chdir(old_dir)
        self.assertFalse(os.path.exists(tarball))
        self.assertEqual(len(w.warnings), 1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:31,代码来源:test_archive_util.py

示例12: test_mix_unicode_str

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_mix_unicode_str(self):
        check = self.check_match
        check('test', u'*')
        check(u'test', '*')
        check('test', u'*', fn=fnmatchcase)
        check(u'test', '*', fn=fnmatchcase)
        with test_support.check_warnings(("", UnicodeWarning), quiet=True):
            check('test\xff', u'*\xff')
            check(u'test\xff', '*\xff')
            check('test\xff', u'*\xff', fn=fnmatchcase)
            check(u'test\xff', '*\xff', fn=fnmatchcase) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_fnmatch.py

示例13: test_unicode

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_unicode(self):
        with test_support.check_warnings(("", UnicodeWarning), quiet=True):
            self.check_match(u'test', u'te*')
            self.check_match(u'test\xff', u'te*\xff')
            self.check_match(u'test'+unichr(0x20ac), u'te*'+unichr(0x20ac))
            self.check_match(u'foo\nbar', u'foo*') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_fnmatch.py

示例14: test_filter

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_filter(self):
        self.assertEqual(filter(['Python', 'Ruby', 'Perl', 'Tcl'], 'P*'),
                         ['Python', 'Perl'])
        self.assertEqual(filter([u'Python', u'Ruby', u'Perl', u'Tcl'], u'P*'),
                         [u'Python', u'Perl'])
        with test_support.check_warnings(("", UnicodeWarning), quiet=True):
            self.assertEqual(filter([u'test\xff'], u'*\xff'), [u'test\xff']) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_fnmatch.py

示例15: test_mix_bytes_str

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import check_warnings [as 别名]
def test_mix_bytes_str(self):
        with test_support.check_warnings(("", UnicodeWarning), quiet=True):
            self.assertEqual(filter(['test'], u'*'), ['test'])
            self.assertEqual(filter([u'test'], '*'), [u'test'])
            self.assertEqual(filter(['test\xff'], u'*'), ['test\xff'])
            self.assertEqual(filter([u'test\xff'], '*'), [u'test\xff'])
            self.assertEqual(filter(['test\xff'], u'*\xff'), ['test\xff'])
            self.assertEqual(filter([u'test\xff'], '*\xff'), [u'test\xff']) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_fnmatch.py


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