Python test.test_support.requires() Examples
The following are 30
code examples of test.test_support.requires().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.test_support
, or try the search function
.
Example #1
Source File: test_robotparser.py From BinderFilter with MIT License | 6 votes |
def testPasswordProtectedSite(self): test_support.requires('network') with test_support.transient_internet('mueblesmoraleda.com'): url = 'http://mueblesmoraleda.com' robots_url = url + "/robots.txt" # First check the URL is usable for our purposes, since the # test site is a bit flaky. try: urlopen(robots_url) except HTTPError as e: if e.code not in {401, 403}: self.skipTest( "%r should return a 401 or 403 HTTP error, not %r" % (robots_url, e.code)) else: self.skipTest( "%r should return a 401 or 403 HTTP error, not succeed" % (robots_url)) parser = robotparser.RobotFileParser() parser.set_url(url) try: parser.read() except IOError: self.skipTest('%s is unavailable' % url) self.assertEqual(parser.can_fetch("*", robots_url), False)
Example #2
Source File: test_searchengine.py From oss-ftp with MIT License | 6 votes |
def setUpClass(cls): cls.engine = se.SearchEngine(None) ## requires('gui') ## cls.root = Tk() ## cls.text = Text(master=cls.root) cls.text = mockText() # search_backward calls index('end-1c') cls.text.index = lambda index: '4.0' test_text = ( 'First line\n' 'Line with target\n' 'Last line\n') cls.text.insert('1.0', test_text) cls.pat = re.compile('target') cls.res = (2, (10, 16)) # line, slice indexes of 'target' cls.failpat = re.compile('xyz') # not in text cls.emptypat = re.compile('\w*') # empty match possible
Example #3
Source File: test_searchengine.py From oss-ftp with MIT License | 6 votes |
def setUpClass(cls): ## requires('gui') ## cls.root = Tk() ## cls.text = Text(master=cls.root) cls.text = mockText() test_text = ( 'First line\n' 'Line with target\n' 'Last line\n') cls.text.insert('1.0', test_text) cls.pat = re.compile('target') cls.engine = se.SearchEngine(None) cls.engine.search_forward = lambda *args: ('f', args) cls.engine.search_backward = lambda *args: ('b', args) ## @classmethod ## def tearDownClass(cls): ## cls.root.destroy() ## del cls.root
Example #4
Source File: test_file2k.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_write_full(self): devfull = '/dev/full' if not (os.path.exists(devfull) and stat.S_ISCHR(os.stat(devfull).st_mode)): # Issue #21934: OpenBSD does not have a /dev/full character device self.skipTest('requires %r' % devfull) with open(devfull, 'wb', 1) as f: with self.assertRaises(IOError): f.write('hello\n') with open(devfull, 'wb', 1) as f: with self.assertRaises(IOError): # Issue #17976 f.write('hello') f.write('\n') with open(devfull, 'wb', 0) as f: with self.assertRaises(IOError): f.write('h')
Example #5
Source File: test_robotparser.py From oss-ftp with MIT License | 6 votes |
def testPasswordProtectedSite(self): test_support.requires('network') with test_support.transient_internet('mueblesmoraleda.com'): url = 'http://mueblesmoraleda.com' robots_url = url + "/robots.txt" # First check the URL is usable for our purposes, since the # test site is a bit flaky. try: urlopen(robots_url) except HTTPError as e: if e.code not in {401, 403}: self.skipTest( "%r should return a 401 or 403 HTTP error, not %r" % (robots_url, e.code)) else: self.skipTest( "%r should return a 401 or 403 HTTP error, not succeed" % (robots_url)) parser = robotparser.RobotFileParser() parser.set_url(url) try: parser.read() except IOError: self.skipTest('%s is unavailable' % url) self.assertEqual(parser.can_fetch("*", robots_url), False)
Example #6
Source File: test_robotparser.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testPasswordProtectedSite(self): test_support.requires('network') with test_support.transient_internet('mueblesmoraleda.com'): url = 'http://mueblesmoraleda.com' robots_url = url + "/robots.txt" # First check the URL is usable for our purposes, since the # test site is a bit flaky. try: urlopen(robots_url) except HTTPError as e: if e.code not in {401, 403}: self.skipTest( "%r should return a 401 or 403 HTTP error, not %r" % (robots_url, e.code)) else: self.skipTest( "%r should return a 401 or 403 HTTP error, not succeed" % (robots_url)) parser = robotparser.RobotFileParser() parser.set_url(url) try: parser.read() except IOError: self.skipTest('%s is unavailable' % url) self.assertEqual(parser.can_fetch("*", robots_url), False)
Example #7
Source File: test_socket_ssl.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_basic(): test_support.requires('network') import urllib socket.RAND_status() try: socket.RAND_egd(1) except TypeError: pass else: print "didn't raise TypeError" socket.RAND_add("this is a random string", 75.0) f = urllib.urlopen('https://sf.net') buf = f.read() f.close()
Example #8
Source File: test_httplib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_networked_bad_cert(self): # We feed a "CA" cert that is unrelated to the server's cert import ssl test_support.requires('network') with test_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 = httplib.HTTPSConnection('self-signed.pythontest.net', 443, context=context) with self.assertRaises(ssl.SSLError) as exc_info: h.request('GET', '/') if test_support.is_jython: return # FIXME: SSLError.reason not yet available for Jython self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
Example #9
Source File: test_urllib2net.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_main(): test_support.requires("network") test_support.run_unittest(AuthTests, OtherNetworkTests, CloseSocketTest, TimeoutTest, )
Example #10
Source File: test_urllibnet.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_main(): test_support.requires('network') with test_support.check_py3k_warnings( ("urllib.urlopen.. has been removed", DeprecationWarning)): test_support.run_unittest(URLTimeoutTest, urlopenNetworkTests, urlretrieveNetworkTests)
Example #11
Source File: test_httplib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_networked_trusted_by_default_cert(self): # Default settings: requires a valid cert from a trusted CA test_support.requires('network') with test_support.transient_internet('www.python.org'): h = httplib.HTTPSConnection('www.python.org', 443) h.request('GET', '/') resp = h.getresponse() content_type = resp.getheader('content-type') self.assertIn('text/html', content_type)
Example #12
Source File: test_urllib2net.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_main(): test_support.requires("network") test_support.run_unittest(AuthTests, OtherNetworkTests, CloseSocketTest, TimeoutTest, )
Example #13
Source File: test_urllibnet.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_main(): test_support.requires('network') with test_support.check_py3k_warnings( ("urllib.urlopen.. has been removed", DeprecationWarning)): test_support.run_unittest(URLTimeoutTest, urlopenNetworkTests, urlretrieveNetworkTests)
Example #14
Source File: test_urllib2_localnet.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_main(): # We will NOT depend on the network resource flag # (Lib/test/regrtest.py -u network) since all tests here are only # localhost. However, if this is a bad rationale, then uncomment # the next line. #test_support.requires("network") test_support.run_unittest(ProxyAuthTests, TestUrlopen)
Example #15
Source File: test_httplib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_networked(self): # Default settings: requires a valid cert from a trusted CA import ssl test_support.requires('network') with test_support.transient_internet('self-signed.pythontest.net'): h = httplib.HTTPSConnection('self-signed.pythontest.net', 443) with self.assertRaises(ssl.SSLError) as exc_info: h.request('GET', '/') if test_support.is_jython: return # FIXME: SSLError.reason not yet available for Jython self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
Example #16
Source File: test_subprocess.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_main(): # Spawning many new jython processes takes a long time test_support.requires('subprocess') test_support.run_unittest(ProcessTestCase) if hasattr(test_support, "reap_children"): test_support.reap_children()
Example #17
Source File: test_io.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: test_subprocess.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_main(): # Spawning many new jython processes takes a long time test_support.requires('subprocess') test_support.run_unittest(ProcessTestCase) if hasattr(test_support, "reap_children"): test_support.reap_children()
Example #19
Source File: test_winsound.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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 )
Example #20
Source File: test_winsound.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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 )
Example #21
Source File: test_timeout.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_main(): test_support.requires('network') test_support.run_unittest(CreationTestCase, TimeoutTestCase)
Example #22
Source File: test_httplib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_networked(self): # Default settings: requires a valid cert from a trusted CA import ssl test_support.requires('network') with test_support.transient_internet('self-signed.pythontest.net'): h = httplib.HTTPSConnection('self-signed.pythontest.net', 443) with self.assertRaises(ssl.SSLError) as exc_info: h.request('GET', '/') if test_support.is_jython: return # FIXME: SSLError.reason not yet available for Jython self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
Example #23
Source File: test_urllib2_localnet.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_main(): # We will NOT depend on the network resource flag # (Lib/test/regrtest.py -u network) since all tests here are only # localhost. However, if this is a bad rationale, then uncomment # the next line. #test_support.requires("network") test_support.run_unittest(ProxyAuthTests)
Example #24
Source File: test_urllibnet.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_main(): test_support.requires('network') test_support.run_unittest(URLTimeoutTest, urlopenNetworkTests, urlretrieveNetworkTests)
Example #25
Source File: test_urllib2net.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_main(): test_support.requires("network") test_support.run_unittest(URLTimeoutTest, urlopenNetworkTests, AuthTests, OtherNetworkTests, CloseSocketTest, )
Example #26
Source File: test_timeout.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_main(): test_support.requires('network') test_support.run_unittest(CreationTestCase, TimeoutTestCase)
Example #27
Source File: test_robotparser.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testPythonOrg(self): test_support.requires('network') with test_support.transient_internet('www.python.org'): parser = robotparser.RobotFileParser( "http://www.python.org/robots.txt") parser.read() self.assertTrue( parser.can_fetch("*", "http://www.python.org/robots.txt"))
Example #28
Source File: test_urllib2_localnet.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_main(): # We will NOT depend on the network resource flag # (Lib/test/regrtest.py -u network) since all tests here are only # localhost. However, if this is a bad rationale, then uncomment # the next line. #test_support.requires("network") test_support.run_unittest(ProxyAuthTests, TestUrlopen)
Example #29
Source File: test_urllibnet.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_main(): test_support.requires('network') with test_support.check_py3k_warnings( ("urllib.urlopen.. has been removed", DeprecationWarning)): test_support.run_unittest(URLTimeoutTest, urlopenNetworkTests, urlretrieveNetworkTests)
Example #30
Source File: test_urllib2net.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_main(): test_support.requires("network") test_support.run_unittest(AuthTests, OtherNetworkTests, CloseSocketTest, TimeoutTest, )