Example #1
0
def test_basic():
    test_support.requires('network')

    import urllib

    if test_support.verbose:
        print ("test_basic ...")

    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)

    try:
        f = urllib.urlopen('https://sf.net')
    except IOError as exc:
        if exc.errno == errno.ETIMEDOUT:
            raise test_support.ResourceDenied('HTTPS connection is timing out')
        else:
            raise
    buf = f.read()
    f.close()
Example #2
0
 def setUp(self):
     self.assertTrue(self.python)
     self.assertTrue(self.module)
     self.assertTrue(self.error)
     test_support.requires("xpickle")
     if not have_python_version(self.python):
         self.skipTest('%s not available' % self.python)
 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 #4
0
def test_timeout():
    test_support.requires('network')

    def error_msg(extra_msg):
        print >> sys.stderr, """\
    WARNING:  an attempt to connect to %r %s, in
    test_timeout.  That may be legitimate, but is not the outcome we hoped
    for.  If this message is seen often, test_timeout should be changed to
    use a more reliable address.""" % (ADDR, extra_msg)

    if test_support.verbose:
        print "test_timeout ..."

    # A service which issues a welcome banner (without need to write
    # anything).
    # XXX ("gmail.org", 995) has been unreliable so far, from time to time
    # XXX non-responsive for hours on end (& across all buildbot slaves,
    # XXX so that's not just a local thing).
    ADDR = "gmail.org", 995

    s = socket.socket()
    s.settimeout(30.0)
    try:
        s.connect(ADDR)
    except socket.timeout:
        error_msg('timed out')
        return
    except socket.error, exc:  # In case connection is refused.
        if exc.args[0] == errno.ECONNREFUSED:
            error_msg('was refused')
            return
        else:
            raise
 def testPythonOrg(self):
     test_support.requires('network')
     parser = robotparser.RobotFileParser(
         "http://www.python.org/robots.txt")
     parser.read()
     self.assertTrue(parser.can_fetch("*",
                                      "http://www.python.org/robots.txt"))
Example #6
0
 def setUpClass(cls):
     requires("gui")
     cls.root = Tk()
     cls.TV = TV = tv.TextViewer
     TV.transient = Func()
     TV.grab_set = Func()
     TV.wait_window = Func()
 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 #8
0
def test_timeout():
    test_support.requires('network')

    def error_msg(extra_msg):
        print >> sys.stderr, """\
    WARNING:  an attempt to connect to %r %s, in
    test_timeout.  That may be legitimate, but is not the outcome we hoped
    for.  If this message is seen often, test_timeout should be changed to
    use a more reliable address.""" % (ADDR, extra_msg)

    if test_support.verbose:
        print "test_timeout ..."

    # A service which issues a welcome banner (without need to write
    # anything).
    ADDR = "pop.gmail.com", 995

    s = socket.socket()
    s.settimeout(30.0)
    try:
        s.connect(ADDR)
    except socket.timeout:
        error_msg('timed out')
        return
    except socket.error, exc:  # In case connection is refused.
        if exc.args[0] == errno.ECONNREFUSED:
            error_msg('was refused')
            return
        else:
            raise
Example #9
0
    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)
        test_support.requires('network')
        self.assertRaises(
            IOError,
            # 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.
            urllib2.urlopen,
            "http://sadflkjsasf.i.nvali.d./")
Example #10
0
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
0
 def setUpClass(cls):
     requires('gui')
     cls.root = Tk()
     cls.TV = TV = tv.TextViewer
     TV.transient = Func()
     TV.grab_set = Func()
     TV.wait_window = Func()
Example #12
0
    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)
        test_support.requires('network')
        self.assertRaises(IOError,
                          # 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.
                          urllib2.urlopen, "http://sadflkjsasf.i.nvali.d./")
Example #13
0
 def setUp(self):
     self.assertTrue(self.python)
     self.assertTrue(self.module)
     self.assertTrue(self.error)
     test_support.requires("xpickle")
     if not have_python_version(self.python):
         self.skipTest("%s not available" % self.python)
Example #14
0
def test_timeout():
    test_support.requires('network')

    if test_support.verbose:
        print "test_timeout ..."

    # A service which issues a welcome banner (without need to write
    # anything).
    # XXX ("gmail.org", 995) has been unreliable so far, from time to time
    # XXX non-responsive for hours on end (& across all buildbot slaves,
    # XXX so that's not just a local thing).
    ADDR = "gmail.org", 995

    s = socket.socket()
    s.settimeout(30.0)
    try:
        s.connect(ADDR)
    except socket.timeout:
        print >> sys.stderr, """\
    WARNING:  an attempt to connect to %r timed out, in
    test_timeout.  That may be legitimate, but is not the outcome we hoped
    for.  If this message is seen often, test_timeout should be changed to
    use a more reliable address.""" % (ADDR, )
        return

    ss = socket.ssl(s)
    # Read part of return welcome banner twice.
    ss.read(1)
    ss.read(1)
    s.close()
Example #15
0
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 #16
0
def test_main():
    test_support.requires("network")
    test_support.run_unittest(AuthTests,
                              OtherNetworkTests,
                              CloseSocketTest,
                              TimeoutTest,
                              )
def test_timeout():
    test_support.requires('network')

    def error_msg(extra_msg):
        print >> sys.stderr, """\
    WARNING:  an attempt to connect to %r %s, in
    test_timeout.  That may be legitimate, but is not the outcome we hoped
    for.  If this message is seen often, test_timeout should be changed to
    use a more reliable address.""" % (ADDR, extra_msg)

    if test_support.verbose:
        print "test_timeout ..."

    # A service which issues a welcome banner (without need to write
    # anything).
    # XXX ("gmail.org", 995) has been unreliable so far, from time to time
    # XXX non-responsive for hours on end (& across all buildbot slaves,
    # XXX so that's not just a local thing).
    ADDR = "gmail.org", 995

    s = socket.socket()
    s.settimeout(30.0)
    try:
        s.connect(ADDR)
    except socket.timeout:
        error_msg('timed out')
        return
    except socket.error, exc:  # In case connection is refused.
        if exc.args[0] == errno.ECONNREFUSED:
            error_msg('was refused')
            return
        else:
            raise
Example #18
0
def test_timeout():
    test_support.requires('network')

    def error_msg(extra_msg):
        print >> sys.stderr, """\
    WARNING:  an attempt to connect to %r %s, in
    test_timeout.  That may be legitimate, but is not the outcome we hoped
    for.  If this message is seen often, test_timeout should be changed to
    use a more reliable address.""" % (ADDR, extra_msg)

    if test_support.verbose:
        print "test_timeout ..."

    # A service which issues a welcome banner (without need to write
    # anything).
    ADDR = "pop.gmail.com", 995

    s = socket.socket()
    s.settimeout(30.0)
    try:
        s.connect(ADDR)
    except socket.timeout:
        error_msg('timed out')
        return
    except socket.error, exc:  # In case connection is refused.
        if exc.args[0] == errno.ECONNREFUSED:
            error_msg('was refused')
            return
        else:
            raise
Example #19
0
def test_main():
    test_support.requires("network")
    test_support.run_unittest(AuthTests,
                              OtherNetworkTests,
                              CloseSocketTest,
                              TimeoutTest,
                              )
Example #20
0
def test_timeout():
    test_support.requires('network')

    if test_support.verbose:
        print "test_timeout ..."

    # A service which issues a welcome banner (without need to write
    # anything).
    # XXX ("gmail.org", 995) has been unreliable so far, from time to time
    # XXX non-responsive for hours on end (& across all buildbot slaves,
    # XXX so that's not just a local thing).
    ADDR = "gmail.org", 995

    s = socket.socket()
    s.settimeout(30.0)
    try:
        s.connect(ADDR)
    except socket.timeout:
        print >> sys.stderr, """\
    WARNING:  an attempt to connect to %r timed out, in
    test_timeout.  That may be legitimate, but is not the outcome we hoped
    for.  If this message is seen often, test_timeout should be changed to
    use a more reliable address.""" % (ADDR,)
        return

    ss = socket.ssl(s)
    # Read part of return welcome banner twice.
    ss.read(1)
    ss.read(1)
    s.close()
 def testPythonOrg(self):
     test_support.requires('network')
     parser = robotparser.RobotFileParser(
         "http://www.python.org/robots.txt")
     parser.read()
     self.assertTrue(
         parser.can_fetch("*", "http://www.python.org/robots.txt"))
def test_main():
    test_support.requires('network')
    from warnings import filterwarnings, catch_warnings
    with catch_warnings():
        filterwarnings('ignore', '.*urllib\.urlopen.*Python 3.0',
                       DeprecationWarning)
        test_support.run_unittest(URLTimeoutTest, urlopenNetworkTests,
                                  urlretrieveNetworkTests)
Example #23
0
 def runTest(self):
     test_support.requires('network')
     # whole site is password-protected.
     url = 'http://mueblesmoraleda.com'
     parser = robotparser.RobotFileParser()
     parser.set_url(url)
     parser.read()
     self.assertEqual(parser.can_fetch("*", url + "/robots.txt"), False)
Example #24
0
 def testPythonOrg(self):
     support.requires('network')
     with 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 #25
0
def test_main():
    if not test_support.due_to_ironpython_bug("http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=303467"): 
        test_support.requires('network')
    with test_support.check_py3k_warnings(
            ("urllib.urlopen.. has been removed", DeprecationWarning)):
        test_support.run_unittest(URLTimeoutTest,
                                  urlopenNetworkTests,
                                  urlretrieveNetworkTests)
 def runTest(self):
     test_support.requires('network')
     # whole site is password-protected.
     url = 'http://mueblesmoraleda.com'
     parser = robotparser.RobotFileParser()
     parser.set_url(url)
     parser.read()
     self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
 def setUpClass(cls):
     if 'Tkinter' in str(Text):
         requires('gui')
         cls.tk = Tk()
         cls.text = Text(cls.tk)
     else:
         cls.text = Text()
     cls.auto_expand = AutoExpand(Dummy_Editwin(cls.text))
Example #28
0
 def setUpClass(cls):
     if 'Tkinter' in str(Text):
         requires('gui')
         cls.tk = Tk()
         cls.text = Text(cls.tk)
     else:
         cls.text = Text()
     cls.auto_expand = AutoExpand(Dummy_Editwin(cls.text))
def test_main():
    if not test_support.due_to_ironpython_bug("http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=303467"): 
        test_support.requires("network")
    test_support.run_unittest(AuthTests,
                              OtherNetworkTests,
                              CloseSocketTest,
                              TimeoutTest,
                              )
 def testPythonOrg(self):
     test_support.requires('network')
     with test_support.transient_internet('www.python.org'):
         parser = robotparser.RobotFileParser(
             "https://www.python.org/robots.txt")
         parser.read()
         self.assertTrue(
             parser.can_fetch("*", "https://www.python.org/robots.txt"))
Example #31
0
 def setUpClass(cls):
     requires('gui')
     cls.root = root = tk.Tk()
     PyShell.fix_x11_paste(root)
     cls.text = tk.Text(root)
     cls.entry = tk.Entry(root)
     cls.spin = tk.Spinbox(root)
     root.clipboard_clear()
     root.clipboard_append('two')
 def setUpClass(cls):
     requires('gui')
     cls.root = root = tk.Tk()
     PyShell.fix_x11_paste(root)
     cls.text = tk.Text(root)
     cls.entry = tk.Entry(root)
     cls.spin = tk.Spinbox(root)
     root.clipboard_clear()
     root.clipboard_append('two')
Example #33
0
def test_main():
    if not test_support.due_to_ironpython_bug(
            "http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=303467"
    ):
        test_support.requires('network')
    with test_support.check_py3k_warnings(
        ("urllib.urlopen.. has been removed", DeprecationWarning)):
        test_support.run_unittest(URLTimeoutTest, urlopenNetworkTests,
                                  urlretrieveNetworkTests)
Example #34
0
def test_main():
    test_support.requires('network')
    from warnings import filterwarnings, catch_warnings
    with catch_warnings():
        filterwarnings('ignore', '.*urllib\.urlopen.*Python 3.0',
                        DeprecationWarning)
        test_support.run_unittest(URLTimeoutTest,
                                  urlopenNetworkTests,
                                  urlretrieveNetworkTests)
 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', '/')
         self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
 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)
 def testPasswordProtectedSite(self):
     test_support.requires('network')
     # XXX it depends on an external resource which could be unavailable
     url = 'http://mueblesmoraleda.com'
     parser = robotparser.RobotFileParser()
     parser.set_url(url)
     try:
         parser.read()
     except IOError:
         self.skipTest('%s is unavailable' % url)
     self.assertEqual(parser.can_fetch("*", url + "/robots.txt"), False)
 def testPasswordProtectedSite(self):
     test_support.requires('network')
     # XXX it depends on an external resource which could be unavailable
     url = 'http://mueblesmoraleda.com'
     parser = robotparser.RobotFileParser()
     parser.set_url(url)
     try:
         parser.read()
     except IOError:
         self.skipTest('%s is unavailable' % url)
     self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
 def test_networked_noverification(self):
     # Switch off cert verification
     import ssl
     test_support.requires('network')
     with test_support.transient_internet('self-signed.pythontest.net'):
         context = ssl._create_stdlib_context()
         h = httplib.HTTPSConnection('self-signed.pythontest.net', 443,
                                     context=context)
         h.request('GET', '/')
         resp = h.getresponse()
         self.assertIn('nginx', resp.getheader('server'))
Example #40
0
 def testPasswordProtectedSite(self):
     test_support.requires('network')
     with test_support.transient_internet('mueblesmoraleda.com'):
         url = 'http://mueblesmoraleda.com'
         parser = robotparser.RobotFileParser()
         parser.set_url(url)
         try:
             parser.read()
         except IOError:
             self.skipTest('%s is unavailable' % url)
         self.assertEqual(parser.can_fetch("*", url + "/robots.txt"), False)
 def testPasswordProtectedSite(self):
     test_support.requires('network')
     with test_support.transient_internet('mueblesmoraleda.com'):
         url = 'http://mueblesmoraleda.com'
         parser = robotparser.RobotFileParser()
         parser.set_url(url)
         try:
             parser.read()
         except IOError:
             self.skipTest('%s is unavailable' % url)
         self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
Example #42
0
 def test_very_long_line(self, size):
     # Issue #22526
     requires('largefile')
     with open(TESTFN, "wb") as fp:
         fp.seek(size - 1)
         fp.write("\0")
     with open(TESTFN, "rb") as fp:
         for l in fp:
             pass
     self.assertEqual(len(l), size)
     self.assertEqual(l.count("\0"), size)
     l = None
Example #43
0
 def test_very_long_line(self, size):
     # Issue #22526
     requires("largefile")
     with open(TESTFN, "wb") as fp:
         fp.seek(size - 1)
         fp.write("\0")
     with open(TESTFN, "rb") as fp:
         for l in fp:
             pass
     self.assertEqual(len(l), size)
     self.assertEqual(l.count("\0"), size)
     l = None
Example #44
0
 def _make_test_file(self, num_zeroes, tail):
     if sys.platform[:3] == "win" or sys.platform == "darwin":
         requires("largefile", "test requires %s bytes and a long time to run" % str(0x180000000))
     f = open(TESTFN, "w+b")
     try:
         f.seek(num_zeroes)
         f.write(tail)
         f.flush()
     except (IOError, OverflowError):
         f.close()
         raise unittest.SkipTest("filesystem does not have largefile support")
     return f
 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', '/')
         self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
Example #46
0
 def _make_test_file(self, num_zeroes, tail):
     if sys.platform[:3] == 'win' or sys.platform == 'darwin':
         requires('largefile',
             'test requires %s bytes and a long time to run' % str(0x180000000))
     f = open(TESTFN, 'w+b')
     try:
         f.seek(num_zeroes)
         f.write(tail)
         f.flush()
     except (IOError, OverflowError):
         f.close()
         raise unittest.SkipTest("filesystem does not have largefile support")
     return f
 def test_networked_good_cert(self):
     # We feed the server's cert as a validating 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_selfsigned_pythontestdotnet)
         h = httplib.HTTPSConnection('self-signed.pythontest.net', 443, context=context)
         h.request('GET', '/')
         resp = h.getresponse()
         server_string = resp.getheader('server')
         self.assertIn('nginx', server_string)
def test_main():
    # 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 (IOError, OverflowError):
            f.close()
            unlink(TESTFN)
            raise unittest.SkipTest(
                "filesystem does not have largefile support")
        else:
            f.close()
    suite = unittest.TestSuite()
    for _open, prefix in [(io.open, 'C'), (pyio.open, 'Py'),
                          (open, 'Builtin')]:

        class TestCase(LargeFileTest):
            pass

        TestCase.open = staticmethod(_open)
        TestCase.new_io = _open is not open
        TestCase.__name__ = prefix + LargeFileTest.__name__
        suite.addTest(TestCase('test_seek'))
        suite.addTest(TestCase('test_osstat'))
        suite.addTest(TestCase('test_seek_read'))
        suite.addTest(TestCase('test_lseek'))
        with _open(TESTFN, 'wb') as f:
            if hasattr(f, 'truncate'):
                suite.addTest(TestCase('test_truncate'))
        suite.addTest(TestCase('test_seekable'))
        unlink(TESTFN)
    try:
        run_unittest(suite)
    finally:
        unlink(TESTFN)
Example #49
0
    def test_large_filesize(self):
        if sys.platform[:3] == 'win' or sys.platform == 'darwin':
            requires('largefile',
                'test requires %s bytes and a long time to run' % str(0x180000000))
        self._working_largefile()
        with open(TESTFN, 'wb') as f:
            f.seek(0x17FFFFFFF)
            f.write(b" ")

        with open(TESTFN, 'rb') as f:
            m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
            try:
                self.assertEqual(m.size(), 0x180000000)
            finally:
                m.close()
Example #50
0
    def test_large_filesize(self):
        if sys.platform[:3] == 'win' or sys.platform == 'darwin':
            requires(
                'largefile', 'test requires %s bytes and a long time to run' %
                str(0x180000000))
        self._working_largefile()
        with open(TESTFN, 'wb') as f:
            f.seek(0x17FFFFFFF)
            f.write(b" ")

        with open(TESTFN, 'rb') as f:
            m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
            try:
                self.assertEqual(m.size(), 0x180000000)
            finally:
                m.close()
Example #51
0
def test_main():
    # 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 (IOError, OverflowError):
            f.close()
            unlink(TESTFN)
            raise unittest.SkipTest("filesystem does not have largefile support")
        else:
            f.close()
    suite = unittest.TestSuite()
    for _open, prefix in [(io.open, 'C'), (pyio.open, 'Py'),
                          (open, 'Builtin')]:
        class TestCase(LargeFileTest):
            pass
        TestCase.open = staticmethod(_open)
        TestCase.new_io = _open is not open
        TestCase.__name__ = prefix + LargeFileTest.__name__
        suite.addTest(TestCase('test_seek'))
        suite.addTest(TestCase('test_osstat'))
        suite.addTest(TestCase('test_seek_read'))
        suite.addTest(TestCase('test_lseek'))
        with _open(TESTFN, 'wb') as f:
            if hasattr(f, 'truncate'):
                suite.addTest(TestCase('test_truncate'))
        suite.addTest(TestCase('test_seekable'))
        unlink(TESTFN)
    try:
        run_unittest(suite)
    finally:
        unlink(TESTFN)
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()
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()
def test_main():
    # 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')
        try:
            # 2**31 == 2147483648
            f.seek(2147483649L)
            # Seeking is not enough of a test: you must write and
            # flush, too!
            f.write("x")
            f.flush()
        except (IOError, OverflowError):
            f.close()
            unlink(TESTFN)
            raise TestSkipped, "filesystem does not have largefile support"
        else:
            f.close()
    suite = unittest.TestSuite()
    suite.addTest(TestCase('test_seek'))
    suite.addTest(TestCase('test_osstat'))
    suite.addTest(TestCase('test_seek_read'))
    suite.addTest(TestCase('test_lseek'))
    with open(TESTFN, 'w') as f:
        if hasattr(f, 'truncate'):
            suite.addTest(TestCase('test_truncate'))
    unlink(TESTFN)
    try:
        run_unittest(suite)
    finally:
        unlink(TESTFN)