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


Python support.requires方法代码示例

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


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

示例1: test_networked_good_cert

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_networked_good_cert(self):
        # We feed the server's cert as a validating cert
        import ssl
        support.requires('network')
        with support.transient_internet('self-signed.pythontest.net'):
            context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
            self.assertEqual(context.verify_mode, ssl.CERT_REQUIRED)
            self.assertEqual(context.check_hostname, True)
            context.load_verify_locations(CERT_selfsigned_pythontestdotnet)
            h = client.HTTPSConnection('self-signed.pythontest.net', 443, context=context)
            h.request('GET', '/')
            resp = h.getresponse()
            server_string = resp.getheader('server')
            resp.close()
            h.close()
            self.assertIn('nginx', server_string) 
开发者ID:bkerler,项目名称:android_universal,代码行数:18,代码来源:test_httplib.py

示例2: need_pcbuild

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def need_pcbuild(self):
        exe = os.path.normpath(os.path.abspath(sys.executable))
        parts = exe.split(os.path.sep)
        if len(parts) < 3:
            # it's not a python build, python is likely to be installed
            return

        build_dir = parts[-3]
        if build_dir.lower() != 'pcbuild':
            self.skipTest("Tools/buildbot/test.bat requires PCbuild build, "
                          "found %s" % build_dir) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_regrtest.py

示例3: test_resources

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_resources(self):
        # test -u command line option
        tests = {}
        for resource in ('audio', 'network'):
            code = textwrap.dedent("""
                        from test import support; support.requires(%r)
                        import unittest
                        class PassingTest(unittest.TestCase):
                            def test_pass(self):
                                pass

                        def test_main():
                            support.run_unittest(PassingTest)
                    """ % resource)

            tests[resource] = self.create_test(resource, code)
        test_names = sorted(tests.values())

        # -u all: 2 resources enabled
        output = self.run_tests('-u', 'all', *test_names)
        self.check_executed_tests(output, test_names)

        # -u audio: 1 resource enabled
        output = self.run_tests('-uaudio', *test_names)
        self.check_executed_tests(output, test_names,
                                  skipped=tests['network'])

        # no option: 0 resources enabled
        output = self.run_tests(*test_names)
        self.check_executed_tests(output, test_names,
                                  skipped=test_names) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_regrtest.py

示例4: setUpClass

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def setUpClass(cls):
        support.requires('network')
        with support.transient_internet(cls.base_url):
            cls.parser = robotparser.RobotFileParser(cls.robots_txt)
            cls.parser.read() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_robotparser.py

示例5: test_large_file_ops

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_large_file_ops(self):
        # On Windows and Mac OSX this test comsumes large resources; It takes
        # a long time to build the >2GB file and takes >2GB of disk space
        # therefore the resource must be enabled to run this test.
        if sys.platform[:3] == 'win' or sys.platform == 'darwin':
            support.requires(
                'largefile',
                'test requires %s bytes and a long time to run' % self.LARGE)
        with self.open(support.TESTFN, "w+b", 0) as f:
            self.large_file_ops(f)
        with self.open(support.TESTFN, "w+b") as f:
            self.large_file_ops(f) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_io.py

示例6: test_unbounded_file

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_unbounded_file(self):
        # Issue #1174606: reading from an unbounded stream such as /dev/zero.
        zero = "/dev/zero"
        if not os.path.exists(zero):
            self.skipTest("{0} does not exist".format(zero))
        if sys.maxsize > 0x7FFFFFFF:
            self.skipTest("test can only run in a 32-bit address space")
        if support.real_max_memuse < support._2G:
            self.skipTest("test requires at least 2GB of memory")
        with self.open(zero, "rb", buffering=0) as f:
            self.assertRaises(OverflowError, f.read)
        with self.open(zero, "rb") as f:
            self.assertRaises(OverflowError, f.read)
        with self.open(zero, "r") as f:
            self.assertRaises(OverflowError, f.read) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_io.py

示例7: test_alias_nofallback

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_alias_nofallback(self):
        if _have_soundcard():
            # Note that this is not the same as asserting RuntimeError
            # will get raised:  you cannot convert this to
            # self.assertRaises(...) form.  The attempt may or may not
            # raise RuntimeError, but it shouldn't raise anything other
            # than RuntimeError, and that's all we're trying to test
            # here.  The MS docs aren't clear about whether the SDK
            # PlaySound() with SND_ALIAS and SND_NODEFAULT will return
            # True or False when the alias is unknown.  On Tim's WinXP
            # box today, it returns True (no exception is raised).  What
            # we'd really like to test is that no sound is played, but
            # that requires first wiring an eardrum class into unittest
            # <wink>.
            try:
                winsound.PlaySound(
                    '!"$%&/(#+*',
                    winsound.SND_ALIAS | winsound.SND_NODEFAULT
                )
            except RuntimeError:
                pass
        else:
            self.assertRaises(
                RuntimeError,
                winsound.PlaySound,
                '!"$%&/(#+*', winsound.SND_ALIAS | winsound.SND_NODEFAULT
            ) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:29,代码来源:test_winsound.py

示例8: setUpModule

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def setUpModule():
    try:
        import signal
        # The default handler for SIGXFSZ is to abort the process.
        # By ignoring it, system calls exceeding the file size resource
        # limit will raise OSError instead of crashing the interpreter.
        signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
    except (ImportError, AttributeError):
        pass

    # On Windows and Mac OSX this test comsumes large resources; It
    # takes a long time to build the >2GB file and takes >2GB of disk
    # space therefore the resource must be enabled to run this test.
    # If not, nothing after this line stanza will be executed.
    if sys.platform[:3] == 'win' or sys.platform == 'darwin':
        requires('largefile',
                 'test requires %s bytes and a long time to run' % str(size))
    else:
        # Only run if the current filesystem supports large files.
        # (Skip this test on Windows, since we now always support
        # large files.)
        f = open(TESTFN, 'wb', buffering=0)
        try:
            # 2**31 == 2147483648
            f.seek(2147483649)
            # Seeking is not enough of a test: you must write and flush, too!
            f.write(b'x')
            f.flush()
        except (OSError, OverflowError):
            raise unittest.SkipTest("filesystem does not have "
                                    "largefile support")
        finally:
            f.close()
            unlink(TESTFN) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:36,代码来源:test_largefile.py

示例9: test_bad_address

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_bad_address(self):
        # Make sure proper exception is raised when connecting to a bogus
        # address.

        # as indicated by the comment below, this might fail with some ISP,
        # so we run the test only when -unetwork/-uall is specified to
        # mitigate the problem a bit (see #17564)
        support.requires('network')
        self.assertRaises(OSError,
                          # Given that both VeriSign and various ISPs have in
                          # the past or are presently hijacking various invalid
                          # domain name requests in an attempt to boost traffic
                          # to their own sites, finding a domain name to use
                          # for this test is difficult.  RFC2606 leads one to
                          # believe that '.invalid' should work, but experience
                          # seemed to indicate otherwise.  Single character
                          # TLDs are likely to remain invalid, so this seems to
                          # be the best choice. The trailing '.' prevents a
                          # related problem: The normal DNS resolver appends
                          # the domain names from the search path if there is
                          # no '.' the end and, and if one of those domains
                          # implements a '*' rule a result is returned.
                          # However, none of this will prevent the test from
                          # failing if the ISP hijacks all invalid domain
                          # requests.  The real solution would be to be able to
                          # parameterize the framework with a mock resolver.
                          urllib.request.urlopen,
                          "http://sadflkjsasf.i.nvali.d./") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:30,代码来源:test_urllib2_localnet.py

示例10: test_networked

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_networked(self):
        # Default settings: requires a valid cert from a trusted CA
        import ssl
        support.requires('network')
        with support.transient_internet('self-signed.pythontest.net'):
            h = client.HTTPSConnection('self-signed.pythontest.net', 443)
            with self.assertRaises(ssl.SSLError) as exc_info:
                h.request('GET', '/')
            self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_httplib.py

示例11: test_networked_noverification

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_networked_noverification(self):
        # Switch off cert verification
        import ssl
        support.requires('network')
        with support.transient_internet('self-signed.pythontest.net'):
            context = ssl._create_unverified_context()
            h = client.HTTPSConnection('self-signed.pythontest.net', 443,
                                       context=context)
            h.request('GET', '/')
            resp = h.getresponse()
            h.close()
            self.assertIn('nginx', resp.getheader('server')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_httplib.py

示例12: test_networked_trusted_by_default_cert

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_networked_trusted_by_default_cert(self):
        # Default settings: requires a valid cert from a trusted CA
        support.requires('network')
        with support.transient_internet('www.python.org'):
            h = client.HTTPSConnection('www.python.org', 443)
            h.request('GET', '/')
            resp = h.getresponse()
            content_type = resp.getheader('content-type')
            h.close()
            self.assertIn('text/html', content_type) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_httplib.py

示例13: test_networked_good_cert

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_networked_good_cert(self):
        # We feed the server's cert as a validating cert
        import ssl
        support.requires('network')
        with support.transient_internet('self-signed.pythontest.net'):
            context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            context.verify_mode = ssl.CERT_REQUIRED
            context.load_verify_locations(CERT_selfsigned_pythontestdotnet)
            h = client.HTTPSConnection('self-signed.pythontest.net', 443, context=context)
            h.request('GET', '/')
            resp = h.getresponse()
            server_string = resp.getheader('server')
            h.close()
            self.assertIn('nginx', server_string) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_httplib.py

示例14: test_networked_bad_cert

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_networked_bad_cert(self):
        # We feed a "CA" cert that is unrelated to the server's cert
        import ssl
        support.requires('network')
        with support.transient_internet('self-signed.pythontest.net'):
            context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            context.verify_mode = ssl.CERT_REQUIRED
            context.load_verify_locations(CERT_localhost)
            h = client.HTTPSConnection('self-signed.pythontest.net', 443, context=context)
            with self.assertRaises(ssl.SSLError) as exc_info:
                h.request('GET', '/')
            self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_httplib.py

示例15: test_main

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import requires [as 别名]
def test_main():
    support.requires("network")
    support.run_unittest(PythonBuildersTest) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_xmlrpc_net.py


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