~pythoneers/ubuntu/lucid/python2.7/ltsppa

« back to all changes in this revision

Viewing changes to Lib/test/test_urllib.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-30 06:44:23 UTC
  • mfrom: (27.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110530064423-3w1ka5db2ddn48a3
Tags: 2.7.2~rc1-1
* Python 2.7.2 release candidate 1.
* Update libpython symbols file for m68k (Thorsten Glaser). Closes: #627458.
* Apply proposed patch for issue #670664. LP: #357067.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import unittest
6
6
from test import test_support
7
7
import os
 
8
import sys
8
9
import mimetools
9
10
import tempfile
10
11
import StringIO
148
149
        finally:
149
150
            self.unfakehttp()
150
151
 
 
152
    def test_url_fragment(self):
 
153
        # Issue #11703: geturl() omits fragments in the original URL.
 
154
        url = 'http://docs.python.org/library/urllib.html#OK'
 
155
        self.fakehttp('Hello!')
 
156
        try:
 
157
            fp = urllib.urlopen(url)
 
158
            self.assertEqual(fp.geturl(), url)
 
159
        finally:
 
160
            self.unfakehttp()
 
161
 
151
162
    def test_read_bogus(self):
152
163
        # urlopen() should raise IOError for many error codes.
153
164
        self.fakehttp('''HTTP/1.1 401 Authentication Required
161
172
        finally:
162
173
            self.unfakehttp()
163
174
 
 
175
    def test_invalid_redirect(self):
 
176
        # urlopen() should raise IOError for many error codes.
 
177
        self.fakehttp("""HTTP/1.1 302 Found
 
178
Date: Wed, 02 Jan 2008 03:03:54 GMT
 
179
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
 
180
Location: file:README
 
181
Connection: close
 
182
Content-Type: text/html; charset=iso-8859-1
 
183
""")
 
184
        try:
 
185
            self.assertRaises(IOError, urllib.urlopen, "http://python.org/")
 
186
        finally:
 
187
            self.unfakehttp()
 
188
 
164
189
    def test_empty_socket(self):
165
190
        # urlopen() raises IOError if the underlying socket does not send any
166
191
        # data. (#1680230)
606
631
                         "url2pathname() failed; %s != %s" %
607
632
                         (expect, result))
608
633
 
 
634
    @unittest.skipUnless(sys.platform == 'win32',
 
635
                         'test specific to the nturl2path library')
 
636
    def test_ntpath(self):
 
637
        given = ('/C:/', '///C:/', '/C|//')
 
638
        expect = 'C:\\'
 
639
        for url in given:
 
640
            result = urllib.url2pathname(url)
 
641
            self.assertEqual(expect, result,
 
642
                             'nturl2path.url2pathname() failed; %s != %s' %
 
643
                             (expect, result))
 
644
        given = '///C|/path'
 
645
        expect = 'C:\\path'
 
646
        result = urllib.url2pathname(given)
 
647
        self.assertEqual(expect, result,
 
648
                         'nturl2path.url2pathname() failed; %s != %s' %
 
649
                         (expect, result))
 
650
 
609
651
class Utility_Tests(unittest.TestCase):
610
652
    """Testcase to test the various utility functions in the urllib."""
611
653
 
641
683
 
642
684
# Just commented them out.
643
685
# Can't really tell why keep failing in windows and sparc.
644
 
# Everywhere else they work ok, but on those machines, someteimes
 
686
# Everywhere else they work ok, but on those machines, sometimes
645
687
# fail in one of the tests, sometimes in other. I have a linux, and
646
688
# the tests go ok.
647
689
# If anybody has one of the problematic enviroments, please help!