Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_urllib.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 85542715a249 |
| children | 6768b2350c57 |
| rev | line source |
|---|---|
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
1 """Regresssion tests for urllib""" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
2 |
| 14297 | 3 import urllib |
|
32252
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
4 import httplib |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
5 import unittest |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
6 from test import test_support |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
7 import os |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
8 import mimetools |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
9 import tempfile |
|
32252
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
10 import StringIO |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
11 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
12 def hexescape(char): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
13 """Escape char as RFC 2396 specifies""" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
14 hex_repr = hex(ord(char))[2:].upper() |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
15 if len(hex_repr) == 1: |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
16 hex_repr = "0%s" % hex_repr |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
17 return "%" + hex_repr |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
18 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
19 class urlopen_FileTests(unittest.TestCase): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
20 """Test urlopen() opening a temporary file. |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
21 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
22 Try to test as much functionality as possible so as to cut down on reliance |
| 32439 | 23 on connecting to the Net for testing. |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
24 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
25 """ |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
26 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
27 def setUp(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
28 """Setup of a temp file to use for testing""" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
29 self.text = "test_urllib: %s\n" % self.__class__.__name__ |
|
28832
e4a5f38ff008
Fix the tests on Windows, by writing the test data file in binary
Guido van Rossum <guido@python.org>
parents:
28821
diff
changeset
|
30 FILE = file(test_support.TESTFN, 'wb') |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
31 try: |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
32 FILE.write(self.text) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
33 finally: |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
34 FILE.close() |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
35 self.pathname = test_support.TESTFN |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
36 self.returned_obj = urllib.urlopen("file:%s" % self.pathname) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
37 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
38 def tearDown(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
39 """Shut down the open object""" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
40 self.returned_obj.close() |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
41 os.remove(test_support.TESTFN) |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
42 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
43 def test_interface(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
44 # Make sure object returned by urlopen() has the specified methods |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
45 for attr in ("read", "readline", "readlines", "fileno", |
|
44817
3f34d3b0350d
#1178141: add addinfourl.code to get http status code from urllib.
Georg Brandl <georg@python.org>
parents:
44424
diff
changeset
|
46 "close", "info", "geturl", "getcode", "__iter__"): |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
47 self.assert_(hasattr(self.returned_obj, attr), |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
48 "object returned by urlopen() lacks %s attribute" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
49 attr) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
50 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
51 def test_read(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
52 self.assertEqual(self.text, self.returned_obj.read()) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
53 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
54 def test_readline(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
55 self.assertEqual(self.text, self.returned_obj.readline()) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
56 self.assertEqual('', self.returned_obj.readline(), |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
57 "calling readline() after exhausting the file did not" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
58 " return an empty string") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
59 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
60 def test_readlines(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
61 lines_list = self.returned_obj.readlines() |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
62 self.assertEqual(len(lines_list), 1, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
63 "readlines() returned the wrong number of lines") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
64 self.assertEqual(lines_list[0], self.text, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
65 "readlines() returned improper text") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
66 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
67 def test_fileno(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
68 file_num = self.returned_obj.fileno() |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
69 self.assert_(isinstance(file_num, int), |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
70 "fileno() did not return an int") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
71 self.assertEqual(os.read(file_num, len(self.text)), self.text, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
72 "Reading on the file descriptor returned by fileno() " |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
73 "did not return the expected text") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
74 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
75 def test_close(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
76 # Test close() by calling it hear and then having it be called again |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
77 # by the tearDown() method for the test |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
78 self.returned_obj.close() |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
79 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
80 def test_info(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
81 self.assert_(isinstance(self.returned_obj.info(), mimetools.Message)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
82 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
83 def test_geturl(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
84 self.assertEqual(self.returned_obj.geturl(), self.pathname) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
85 |
|
44817
3f34d3b0350d
#1178141: add addinfourl.code to get http status code from urllib.
Georg Brandl <georg@python.org>
parents:
44424
diff
changeset
|
86 def test_getcode(self): |
|
3f34d3b0350d
#1178141: add addinfourl.code to get http status code from urllib.
Georg Brandl <georg@python.org>
parents:
44424
diff
changeset
|
87 self.assertEqual(self.returned_obj.getcode(), None) |
|
3f34d3b0350d
#1178141: add addinfourl.code to get http status code from urllib.
Georg Brandl <georg@python.org>
parents:
44424
diff
changeset
|
88 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
89 def test_iter(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
90 # Test iterator |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
91 # Don't need to count number of iterations since test would fail the |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
92 # instant it returned anything beyond the first line from the |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
93 # comparison |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
94 for line in self.returned_obj.__iter__(): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
95 self.assertEqual(line, self.text) |
| 14297 | 96 |
|
49260
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
97 |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
98 class ProxyTests(unittest.TestCase): |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
99 |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
100 def setUp(self): |
|
53484
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
53297
diff
changeset
|
101 # Records changes to env vars |
|
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
53297
diff
changeset
|
102 self.env = test_support.EnvironmentVarGuard() |
|
49260
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
103 # Delete all proxy related env vars |
|
53484
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
53297
diff
changeset
|
104 for k, v in os.environ.iteritems(): |
|
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
53297
diff
changeset
|
105 if 'proxy' in k.lower(): |
|
53644
85542715a249
Make test.test_support.EnvironmentVarGuard behave like a dictionary.
Walter Dörwald <walter@livinglogic.de>
parents:
53484
diff
changeset
|
106 del env[k] |
|
49260
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
107 |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
108 def tearDown(self): |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
109 # Restore all proxy related env vars |
|
53484
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
53297
diff
changeset
|
110 self.env.__exit__() |
|
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
53297
diff
changeset
|
111 del self.env |
|
49260
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
112 |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
113 def test_getproxies_environment_keep_no_proxies(self): |
|
53484
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
53297
diff
changeset
|
114 self.env.set('NO_PROXY', 'localhost') |
|
49260
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
115 proxies = urllib.getproxies_environment() |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
116 # getproxies_environment use lowered case truncated (no '_proxy') keys |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
117 self.assertEquals('localhost', proxies['no']) |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
118 |
|
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
119 |
|
32252
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
120 class urlopen_HttpTests(unittest.TestCase): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
121 """Test urlopen() opening a fake http connection.""" |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
122 |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
123 def fakehttp(self, fakedata): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
124 class FakeSocket(StringIO.StringIO): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
125 def sendall(self, str): pass |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
126 def makefile(self, mode, name): return self |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
127 def read(self, amt=None): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
128 if self.closed: return '' |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
129 return StringIO.StringIO.read(self, amt) |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
130 def readline(self, length=None): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
131 if self.closed: return '' |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
132 return StringIO.StringIO.readline(self, length) |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
133 class FakeHTTPConnection(httplib.HTTPConnection): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
134 def connect(self): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
135 self.sock = FakeSocket(fakedata) |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
136 assert httplib.HTTP._connection_class == httplib.HTTPConnection |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
137 httplib.HTTP._connection_class = FakeHTTPConnection |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
138 |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
139 def unfakehttp(self): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
140 httplib.HTTP._connection_class = httplib.HTTPConnection |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
141 |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
142 def test_read(self): |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
143 self.fakehttp('Hello!') |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
144 try: |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
145 fp = urllib.urlopen("http://python.org/") |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
146 self.assertEqual(fp.readline(), 'Hello!') |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
147 self.assertEqual(fp.readline(), '') |
|
44817
3f34d3b0350d
#1178141: add addinfourl.code to get http status code from urllib.
Georg Brandl <georg@python.org>
parents:
44424
diff
changeset
|
148 self.assertEqual(fp.geturl(), 'http://python.org/') |
|
3f34d3b0350d
#1178141: add addinfourl.code to get http status code from urllib.
Georg Brandl <georg@python.org>
parents:
44424
diff
changeset
|
149 self.assertEqual(fp.getcode(), 200) |
|
32252
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
150 finally: |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
151 self.unfakehttp() |
|
a72bc4257336
Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang <hyeshik@gmail.com>
parents:
29087
diff
changeset
|
152 |
| 44423 | 153 def test_read_bogus(self): |
|
44424
66bea91324cd
Change docstrings to comments so test output will display normally.
Kurt B. Kaiser <kbk@shore.net>
parents:
44423
diff
changeset
|
154 # urlopen() should raise IOError for many error codes. |
| 44423 | 155 self.fakehttp('''HTTP/1.1 401 Authentication Required |
| 156 Date: Wed, 02 Jan 2008 03:03:54 GMT | |
| 157 Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e | |
| 158 Connection: close | |
| 159 Content-Type: text/html; charset=iso-8859-1 | |
| 160 ''') | |
| 161 try: | |
| 162 self.assertRaises(IOError, urllib.urlopen, "http://python.org/") | |
| 163 finally: | |
| 164 self.unfakehttp() | |
| 165 | |
|
41186
c301b5bcdfdc
Bug #767111: fix long-standing bug in urllib which caused an
Georg Brandl <georg@python.org>
parents:
35723
diff
changeset
|
166 def test_empty_socket(self): |
|
44424
66bea91324cd
Change docstrings to comments so test output will display normally.
Kurt B. Kaiser <kbk@shore.net>
parents:
44423
diff
changeset
|
167 # urlopen() raises IOError if the underlying socket does not send any |
|
66bea91324cd
Change docstrings to comments so test output will display normally.
Kurt B. Kaiser <kbk@shore.net>
parents:
44423
diff
changeset
|
168 # data. (#1680230) |
|
41186
c301b5bcdfdc
Bug #767111: fix long-standing bug in urllib which caused an
Georg Brandl <georg@python.org>
parents:
35723
diff
changeset
|
169 self.fakehttp('') |
|
c301b5bcdfdc
Bug #767111: fix long-standing bug in urllib which caused an
Georg Brandl <georg@python.org>
parents:
35723
diff
changeset
|
170 try: |
|
c301b5bcdfdc
Bug #767111: fix long-standing bug in urllib which caused an
Georg Brandl <georg@python.org>
parents:
35723
diff
changeset
|
171 self.assertRaises(IOError, urllib.urlopen, 'http://something') |
|
c301b5bcdfdc
Bug #767111: fix long-standing bug in urllib which caused an
Georg Brandl <georg@python.org>
parents:
35723
diff
changeset
|
172 finally: |
|
c301b5bcdfdc
Bug #767111: fix long-standing bug in urllib which caused an
Georg Brandl <georg@python.org>
parents:
35723
diff
changeset
|
173 self.unfakehttp() |
|
c301b5bcdfdc
Bug #767111: fix long-standing bug in urllib which caused an
Georg Brandl <georg@python.org>
parents:
35723
diff
changeset
|
174 |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
175 class urlretrieve_FileTests(unittest.TestCase): |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
176 """Test urllib.urlretrieve() on local files""" |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
177 |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
178 def setUp(self): |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
179 # Create a list of temporary files. Each item in the list is a file |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
180 # name (absolute path or relative to the current working directory). |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
181 # All files in this list will be deleted in the tearDown method. Note, |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
182 # this only helps to makes sure temporary files get deleted, but it |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
183 # does nothing about trying to close files that may still be open. It |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
184 # is the responsibility of the developer to properly close files even |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
185 # when exceptional conditions occur. |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
186 self.tempFiles = [] |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
187 |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
188 # Create a temporary file. |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
189 self.registerFileForCleanUp(test_support.TESTFN) |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
190 self.text = 'testing urllib.urlretrieve' |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
191 try: |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
192 FILE = file(test_support.TESTFN, 'wb') |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
193 FILE.write(self.text) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
194 FILE.close() |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
195 finally: |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
196 try: FILE.close() |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
197 except: pass |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
198 |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
199 def tearDown(self): |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
200 # Delete the temporary files. |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
201 for each in self.tempFiles: |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
202 try: os.remove(each) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
203 except: pass |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
204 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
205 def constructLocalFileUrl(self, filePath): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
206 return "file://%s" % urllib.pathname2url(os.path.abspath(filePath)) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
207 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
208 def createNewTempFile(self, data=""): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
209 """Creates a new temporary file containing the specified data, |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
210 registers the file for deletion during the test fixture tear down, and |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
211 returns the absolute path of the file.""" |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
212 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
213 newFd, newFilePath = tempfile.mkstemp() |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
214 try: |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
215 self.registerFileForCleanUp(newFilePath) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
216 newFile = os.fdopen(newFd, "wb") |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
217 newFile.write(data) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
218 newFile.close() |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
219 finally: |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
220 try: newFile.close() |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
221 except: pass |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
222 return newFilePath |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
223 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
224 def registerFileForCleanUp(self, fileName): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
225 self.tempFiles.append(fileName) |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
226 |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
227 def test_basic(self): |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
228 # Make sure that a local file just gets its own location returned and |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
229 # a headers value is returned. |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
230 result = urllib.urlretrieve("file:%s" % test_support.TESTFN) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
231 self.assertEqual(result[0], test_support.TESTFN) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
232 self.assert_(isinstance(result[1], mimetools.Message), |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
233 "did not get a mimetools.Message instance as second " |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
234 "returned value") |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
235 |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
236 def test_copy(self): |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
237 # Test that setting the filename argument works. |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
238 second_temp = "%s.2" % test_support.TESTFN |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
239 self.registerFileForCleanUp(second_temp) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
240 result = urllib.urlretrieve(self.constructLocalFileUrl( |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
241 test_support.TESTFN), second_temp) |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
242 self.assertEqual(second_temp, result[0]) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
243 self.assert_(os.path.exists(second_temp), "copy of the file was not " |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
244 "made") |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
245 FILE = file(second_temp, 'rb') |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
246 try: |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
247 text = FILE.read() |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
248 FILE.close() |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
249 finally: |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
250 try: FILE.close() |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
251 except: pass |
|
28876
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
252 self.assertEqual(self.text, text) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
253 |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
254 def test_reporthook(self): |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
255 # Make sure that the reporthook works. |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
256 def hooktester(count, block_size, total_size, count_holder=[0]): |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
257 self.assert_(isinstance(count, int)) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
258 self.assert_(isinstance(block_size, int)) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
259 self.assert_(isinstance(total_size, int)) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
260 self.assertEqual(count, count_holder[0]) |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
261 count_holder[0] = count_holder[0] + 1 |
|
9eb5be937990
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon <bcannon@gmail.com>
parents:
28832
diff
changeset
|
262 second_temp = "%s.2" % test_support.TESTFN |
|
35457
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
263 self.registerFileForCleanUp(second_temp) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
264 urllib.urlretrieve(self.constructLocalFileUrl(test_support.TESTFN), |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
265 second_temp, hooktester) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
266 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
267 def test_reporthook_0_bytes(self): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
268 # Test on zero length file. Should call reporthook only 1 time. |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
269 report = [] |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
270 def hooktester(count, block_size, total_size, _report=report): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
271 _report.append((count, block_size, total_size)) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
272 srcFileName = self.createNewTempFile() |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
273 urllib.urlretrieve(self.constructLocalFileUrl(srcFileName), |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
274 test_support.TESTFN, hooktester) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
275 self.assertEqual(len(report), 1) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
276 self.assertEqual(report[0][2], 0) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
277 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
278 def test_reporthook_5_bytes(self): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
279 # Test on 5 byte file. Should call reporthook only 2 times (once when |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
280 # the "network connection" is established and once when the block is |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
281 # read). Since the block size is 8192 bytes, only one block read is |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
282 # required to read the entire file. |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
283 report = [] |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
284 def hooktester(count, block_size, total_size, _report=report): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
285 _report.append((count, block_size, total_size)) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
286 srcFileName = self.createNewTempFile("x" * 5) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
287 urllib.urlretrieve(self.constructLocalFileUrl(srcFileName), |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
288 test_support.TESTFN, hooktester) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
289 self.assertEqual(len(report), 2) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
290 self.assertEqual(report[0][1], 8192) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
291 self.assertEqual(report[0][2], 5) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
292 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
293 def test_reporthook_8193_bytes(self): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
294 # Test on 8193 byte file. Should call reporthook only 3 times (once |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
295 # when the "network connection" is established, once for the next 8192 |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
296 # bytes, and once for the last byte). |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
297 report = [] |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
298 def hooktester(count, block_size, total_size, _report=report): |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
299 _report.append((count, block_size, total_size)) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
300 srcFileName = self.createNewTempFile("x" * 8193) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
301 urllib.urlretrieve(self.constructLocalFileUrl(srcFileName), |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
302 test_support.TESTFN, hooktester) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
303 self.assertEqual(len(report), 3) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
304 self.assertEqual(report[0][1], 8192) |
|
9d41afa63b79
backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl <georg@python.org>
parents:
32439
diff
changeset
|
305 self.assertEqual(report[0][2], 8193) |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
306 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
307 class QuotingTests(unittest.TestCase): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
308 """Tests for urllib.quote() and urllib.quote_plus() |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
309 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
310 According to RFC 2396 ("Uniform Resource Identifiers), to escape a |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
311 character you write it as '%' + <2 character US-ASCII hex value>. The Python |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
312 code of ``'%' + hex(ord(<character>))[2:]`` escapes a character properly. |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
313 Case does not matter on the hex letters. |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
314 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
315 The various character sets specified are: |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
316 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
317 Reserved characters : ";/?:@&=+$," |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
318 Have special meaning in URIs and must be escaped if not being used for |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
319 their special meaning |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
320 Data characters : letters, digits, and "-_.!~*'()" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
321 Unreserved and do not need to be escaped; can be, though, if desired |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
322 Control characters : 0x00 - 0x1F, 0x7F |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
323 Have no use in URIs so must be escaped |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
324 space : 0x20 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
325 Must be escaped |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
326 Delimiters : '<>#%"' |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
327 Must be escaped |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
328 Unwise : "{}|\^[]`" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
329 Must be escaped |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
330 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
331 """ |
| 14297 | 332 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
333 def test_never_quote(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
334 # Make sure quote() does not quote letters, digits, and "_,.-" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
335 do_not_quote = '' .join(["ABCDEFGHIJKLMNOPQRSTUVWXYZ", |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
336 "abcdefghijklmnopqrstuvwxyz", |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
337 "0123456789", |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
338 "_.-"]) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
339 result = urllib.quote(do_not_quote) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
340 self.assertEqual(do_not_quote, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
341 "using quote(): %s != %s" % (do_not_quote, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
342 result = urllib.quote_plus(do_not_quote) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
343 self.assertEqual(do_not_quote, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
344 "using quote_plus(): %s != %s" % (do_not_quote, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
345 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
346 def test_default_safe(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
347 # Test '/' is default value for 'safe' parameter |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
348 self.assertEqual(urllib.quote.func_defaults[0], '/') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
349 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
350 def test_safe(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
351 # Test setting 'safe' parameter does what it should do |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
352 quote_by_default = "<>" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
353 result = urllib.quote(quote_by_default, safe=quote_by_default) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
354 self.assertEqual(quote_by_default, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
355 "using quote(): %s != %s" % (quote_by_default, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
356 result = urllib.quote_plus(quote_by_default, safe=quote_by_default) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
357 self.assertEqual(quote_by_default, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
358 "using quote_plus(): %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
359 (quote_by_default, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
360 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
361 def test_default_quoting(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
362 # Make sure all characters that should be quoted are by default sans |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
363 # space (separate test for that). |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
364 should_quote = [chr(num) for num in range(32)] # For 0x00 - 0x1F |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
365 should_quote.append('<>#%"{}|\^[]`') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
366 should_quote.append(chr(127)) # For 0x7F |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
367 should_quote = ''.join(should_quote) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
368 for char in should_quote: |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
369 result = urllib.quote(char) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
370 self.assertEqual(hexescape(char), result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
371 "using quote(): %s should be escaped to %s, not %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
372 (char, hexescape(char), result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
373 result = urllib.quote_plus(char) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
374 self.assertEqual(hexescape(char), result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
375 "using quote_plus(): " |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
376 "%s should be escapes to %s, not %s" % |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
377 (char, hexescape(char), result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
378 del should_quote |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
379 partial_quote = "ab[]cd" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
380 expected = "ab%5B%5Dcd" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
381 result = urllib.quote(partial_quote) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
382 self.assertEqual(expected, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
383 "using quote(): %s != %s" % (expected, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
384 self.assertEqual(expected, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
385 "using quote_plus(): %s != %s" % (expected, result)) |
| 14297 | 386 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
387 def test_quoting_space(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
388 # Make sure quote() and quote_plus() handle spaces as specified in |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
389 # their unique way |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
390 result = urllib.quote(' ') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
391 self.assertEqual(result, hexescape(' '), |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
392 "using quote(): %s != %s" % (result, hexescape(' '))) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
393 result = urllib.quote_plus(' ') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
394 self.assertEqual(result, '+', |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
395 "using quote_plus(): %s != +" % result) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
396 given = "a b cd e f" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
397 expect = given.replace(' ', hexescape(' ')) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
398 result = urllib.quote(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
399 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
400 "using quote(): %s != %s" % (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
401 expect = given.replace(' ', '+') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
402 result = urllib.quote_plus(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
403 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
404 "using quote_plus(): %s != %s" % (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
405 |
|
35530
363e6dd079fc
Revert 1.170. Add tests.
Raymond Hettinger <python@rcn.com>
parents:
35457
diff
changeset
|
406 def test_quoting_plus(self): |
|
363e6dd079fc
Revert 1.170. Add tests.
Raymond Hettinger <python@rcn.com>
parents:
35457
diff
changeset
|
407 self.assertEqual(urllib.quote_plus('alpha+beta gamma'), |
|
363e6dd079fc
Revert 1.170. Add tests.
Raymond Hettinger <python@rcn.com>
parents:
35457
diff
changeset
|
408 'alpha%2Bbeta+gamma') |
|
363e6dd079fc
Revert 1.170. Add tests.
Raymond Hettinger <python@rcn.com>
parents:
35457
diff
changeset
|
409 self.assertEqual(urllib.quote_plus('alpha+beta gamma', '+'), |
|
363e6dd079fc
Revert 1.170. Add tests.
Raymond Hettinger <python@rcn.com>
parents:
35457
diff
changeset
|
410 'alpha+beta+gamma') |
|
363e6dd079fc
Revert 1.170. Add tests.
Raymond Hettinger <python@rcn.com>
parents:
35457
diff
changeset
|
411 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
412 class UnquotingTests(unittest.TestCase): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
413 """Tests for unquote() and unquote_plus() |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
414 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
415 See the doc string for quoting_Tests for details on quoting and such. |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
416 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
417 """ |
|
14551
28df4f45967f
Remove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14297
diff
changeset
|
418 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
419 def test_unquoting(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
420 # Make sure unquoting of all ASCII values works |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
421 escape_list = [] |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
422 for num in range(128): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
423 given = hexescape(chr(num)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
424 expect = chr(num) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
425 result = urllib.unquote(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
426 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
427 "using unquote(): %s != %s" % (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
428 result = urllib.unquote_plus(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
429 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
430 "using unquote_plus(): %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
431 (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
432 escape_list.append(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
433 escape_string = ''.join(escape_list) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
434 del escape_list |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
435 result = urllib.unquote(escape_string) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
436 self.assertEqual(result.count('%'), 1, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
437 "using quote(): not all characters escaped; %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
438 result) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
439 result = urllib.unquote(escape_string) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
440 self.assertEqual(result.count('%'), 1, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
441 "using unquote(): not all characters escaped: " |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
442 "%s" % result) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
443 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
444 def test_unquoting_parts(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
445 # Make sure unquoting works when have non-quoted characters |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
446 # interspersed |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
447 given = 'ab%sd' % hexescape('c') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
448 expect = "abcd" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
449 result = urllib.unquote(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
450 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
451 "using quote(): %s != %s" % (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
452 result = urllib.unquote_plus(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
453 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
454 "using unquote_plus(): %s != %s" % (expect, result)) |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
455 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
456 def test_unquoting_plus(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
457 # Test difference between unquote() and unquote_plus() |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
458 given = "are+there+spaces..." |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
459 expect = given |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
460 result = urllib.unquote(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
461 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
462 "using unquote(): %s != %s" % (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
463 expect = given.replace('+', ' ') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
464 result = urllib.unquote_plus(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
465 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
466 "using unquote_plus(): %s != %s" % (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
467 |
|
35723
ae539af4afc5
Teach unquote() to handle unicode inputs
Raymond Hettinger <python@rcn.com>
parents:
35530
diff
changeset
|
468 def test_unquote_with_unicode(self): |
|
ae539af4afc5
Teach unquote() to handle unicode inputs
Raymond Hettinger <python@rcn.com>
parents:
35530
diff
changeset
|
469 r = urllib.unquote(u'br%C3%BCckner_sapporo_20050930.doc') |
|
ae539af4afc5
Teach unquote() to handle unicode inputs
Raymond Hettinger <python@rcn.com>
parents:
35530
diff
changeset
|
470 self.assertEqual(r, u'br\xc3\xbcckner_sapporo_20050930.doc') |
|
ae539af4afc5
Teach unquote() to handle unicode inputs
Raymond Hettinger <python@rcn.com>
parents:
35530
diff
changeset
|
471 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
472 class urlencode_Tests(unittest.TestCase): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
473 """Tests for urlencode()""" |
|
14551
28df4f45967f
Remove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14297
diff
changeset
|
474 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
475 def help_inputtype(self, given, test_type): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
476 """Helper method for testing different input types. |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
477 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
478 'given' must lead to only the pairs: |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
479 * 1st, 1 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
480 * 2nd, 2 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
481 * 3rd, 3 |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
482 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
483 Test cannot assume anything about order. Docs make no guarantee and |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
484 have possible dictionary input. |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
485 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
486 """ |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
487 expect_somewhere = ["1st=1", "2nd=2", "3rd=3"] |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
488 result = urllib.urlencode(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
489 for expected in expect_somewhere: |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
490 self.assert_(expected in result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
491 "testing %s: %s not found in %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
492 (test_type, expected, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
493 self.assertEqual(result.count('&'), 2, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
494 "testing %s: expected 2 '&'s; got %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
495 (test_type, result.count('&'))) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
496 amp_location = result.index('&') |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
497 on_amp_left = result[amp_location - 1] |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
498 on_amp_right = result[amp_location + 1] |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
499 self.assert_(on_amp_left.isdigit() and on_amp_right.isdigit(), |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
500 "testing %s: '&' not located in proper place in %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
501 (test_type, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
502 self.assertEqual(len(result), (5 * 3) + 2, #5 chars per thing and amps |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
503 "testing %s: " |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
504 "unexpected number of characters: %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
505 (test_type, len(result), (5 * 3) + 2)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
506 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
507 def test_using_mapping(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
508 # Test passing in a mapping object as an argument. |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
509 self.help_inputtype({"1st":'1', "2nd":'2', "3rd":'3'}, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
510 "using dict as input type") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
511 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
512 def test_using_sequence(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
513 # Test passing in a sequence of two-item sequences as an argument. |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
514 self.help_inputtype([('1st', '1'), ('2nd', '2'), ('3rd', '3')], |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
515 "using sequence of two-item tuples as input") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
516 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
517 def test_quoting(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
518 # Make sure keys and values are quoted using quote_plus() |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
519 given = {"&":"="} |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
520 expect = "%s=%s" % (hexescape('&'), hexescape('=')) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
521 result = urllib.urlencode(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
522 self.assertEqual(expect, result) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
523 given = {"key name":"A bunch of pluses"} |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
524 expect = "key+name=A+bunch+of+pluses" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
525 result = urllib.urlencode(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
526 self.assertEqual(expect, result) |
|
14551
28df4f45967f
Remove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14297
diff
changeset
|
527 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
528 def test_doseq(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
529 # Test that passing True for 'doseq' parameter works correctly |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
530 given = {'sequence':['1', '2', '3']} |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
531 expect = "sequence=%s" % urllib.quote_plus(str(['1', '2', '3'])) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
532 result = urllib.urlencode(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
533 self.assertEqual(expect, result) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
534 result = urllib.urlencode(given, True) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
535 for value in given["sequence"]: |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
536 expect = "sequence=%s" % value |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
537 self.assert_(expect in result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
538 "%s not found in %s" % (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
539 self.assertEqual(result.count('&'), 2, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
540 "Expected 2 '&'s, got %s" % result.count('&')) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
541 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
542 class Pathname_Tests(unittest.TestCase): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
543 """Test pathname2url() and url2pathname()""" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
544 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
545 def test_basic(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
546 # Make sure simple tests pass |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
547 expected_path = os.path.join("parts", "of", "a", "path") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
548 expected_url = "parts/of/a/path" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
549 result = urllib.pathname2url(expected_path) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
550 self.assertEqual(expected_url, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
551 "pathname2url() failed; %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
552 (result, expected_url)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
553 result = urllib.url2pathname(expected_url) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
554 self.assertEqual(expected_path, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
555 "url2pathame() failed; %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
556 (result, expected_path)) |
|
14551
28df4f45967f
Remove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14297
diff
changeset
|
557 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
558 def test_quoting(self): |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
559 # Test automatic quoting and unquoting works for pathnam2url() and |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
560 # url2pathname() respectively |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
561 given = os.path.join("needs", "quot=ing", "here") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
562 expect = "needs/%s/here" % urllib.quote("quot=ing") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
563 result = urllib.pathname2url(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
564 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
565 "pathname2url() failed; %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
566 (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
567 expect = given |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
568 result = urllib.url2pathname(result) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
569 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
570 "url2pathname() failed; %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
571 (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
572 given = os.path.join("make sure", "using_quote") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
573 expect = "%s/using_quote" % urllib.quote("make sure") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
574 result = urllib.pathname2url(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
575 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
576 "pathname2url() failed; %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
577 (expect, result)) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
578 given = "make+sure/using_unquote" |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
579 expect = os.path.join("make+sure", "using_unquote") |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
580 result = urllib.url2pathname(given) |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
581 self.assertEqual(expect, result, |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
582 "url2pathname() failed; %s != %s" % |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
583 (expect, result)) |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
584 |
|
52476
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
585 class Utility_Tests(unittest.TestCase): |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
586 """Testcase to test the various utility functions in the urllib.""" |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
587 |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
588 def test_splitpasswd(self): |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
589 """Some of the password examples are not sensible, but it is added to |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
590 confirming to RFC2617 and addressing issue4675. |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
591 """ |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
592 self.assertEqual(('user', 'ab'),urllib.splitpasswd('user:ab')) |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
593 self.assertEqual(('user', 'a\nb'),urllib.splitpasswd('user:a\nb')) |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
594 self.assertEqual(('user', 'a\tb'),urllib.splitpasswd('user:a\tb')) |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
595 self.assertEqual(('user', 'a\rb'),urllib.splitpasswd('user:a\rb')) |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
596 self.assertEqual(('user', 'a\fb'),urllib.splitpasswd('user:a\fb')) |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
597 self.assertEqual(('user', 'a\vb'),urllib.splitpasswd('user:a\vb')) |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
598 self.assertEqual(('user', 'a:b'),urllib.splitpasswd('user:a:b')) |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
599 |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
600 |
|
53297
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
601 class URLopener_Tests(unittest.TestCase): |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
602 """Testcase to test the open method of URLopener class.""" |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
603 |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
604 def test_quoted_open(self): |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
605 class DummyURLopener(urllib.URLopener): |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
606 def open_spam(self, url): |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
607 return url |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
608 |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
609 self.assertEqual(DummyURLopener().open( |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
610 'spam://example/ /'),'//example/%20/') |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
611 |
|
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
612 |
|
41867
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
613 # Just commented them out. |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
614 # Can't really tell why keep failing in windows and sparc. |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
615 # Everywhere else they work ok, but on those machines, someteimes |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
616 # fail in one of the tests, sometimes in other. I have a linux, and |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
617 # the tests go ok. |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
618 # If anybody has one of the problematic enviroments, please help! |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
619 # . Facundo |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
620 # |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
621 # def server(evt): |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
622 # import socket, time |
|
41867
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
623 # serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
624 # serv.settimeout(3) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
625 # serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
626 # serv.bind(("", 9093)) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
627 # serv.listen(5) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
628 # try: |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
629 # conn, addr = serv.accept() |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
630 # conn.send("1 Hola mundo\n") |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
631 # cantdata = 0 |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
632 # while cantdata < 13: |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
633 # data = conn.recv(13-cantdata) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
634 # cantdata += len(data) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
635 # time.sleep(.3) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
636 # conn.send("2 No more lines\n") |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
637 # conn.close() |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
638 # except socket.timeout: |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
639 # pass |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
640 # finally: |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
641 # serv.close() |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
642 # evt.set() |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
643 # |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
644 # class FTPWrapperTests(unittest.TestCase): |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
645 # |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
646 # def setUp(self): |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
647 # import ftplib, time, threading |
|
41867
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
648 # ftplib.FTP.port = 9093 |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
649 # self.evt = threading.Event() |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
650 # threading.Thread(target=server, args=(self.evt,)).start() |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
651 # time.sleep(.1) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
652 # |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
653 # def tearDown(self): |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
654 # self.evt.wait() |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
655 # |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
656 # def testBasic(self): |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
657 # # connects |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
658 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, []) |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
659 # ftp.close() |
|
41867
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
660 # |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
661 # def testTimeoutNone(self): |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
662 # # global default timeout is ignored |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
663 # import socket |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
664 # self.assert_(socket.getdefaulttimeout() is None) |
|
41867
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
665 # socket.setdefaulttimeout(30) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
666 # try: |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
667 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, []) |
|
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
668 # finally: |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
669 # socket.setdefaulttimeout(None) |
|
41867
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
670 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30) |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
671 # ftp.close() |
|
41867
2c8ba3faaf40
Commenting out the tests until find out who can test them in
Facundo Batista <facundobatista@gmail.com>
parents:
41866
diff
changeset
|
672 # |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
673 # def testTimeoutDefault(self): |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
674 # # global default timeout is used |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
675 # import socket |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
676 # self.assert_(socket.getdefaulttimeout() is None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
677 # socket.setdefaulttimeout(30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
678 # try: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
679 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, []) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
680 # finally: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
681 # socket.setdefaulttimeout(None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
682 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
683 # ftp.close() |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
684 # |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
685 # def testTimeoutValue(self): |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
686 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [], |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
687 # timeout=30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
688 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
45468
diff
changeset
|
689 # ftp.close() |
|
41854
10426ad5a6e0
Added an optional timeout parameter to urllib.ftpwrapper, with tests
Facundo Batista <facundobatista@gmail.com>
parents:
41444
diff
changeset
|
690 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
691 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
692 |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
693 def test_main(): |
|
47871
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
694 import warnings |
|
49099
ff96a313cd1c
warnings.catch_warnings() now returns a list or None instead of the custom
Brett Cannon <bcannon@gmail.com>
parents:
47871
diff
changeset
|
695 with warnings.catch_warnings(): |
|
47871
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
696 warnings.filterwarnings('ignore', ".*urllib\.urlopen.*Python 3.0", |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
697 DeprecationWarning) |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
698 test_support.run_unittest( |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
699 urlopen_FileTests, |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
700 urlopen_HttpTests, |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
701 urlretrieve_FileTests, |
|
49260
6b679ca24369
#3879 fix a regression in urllib.getproxies_environment
Benjamin Peterson <benjamin@python.org>
parents:
49099
diff
changeset
|
702 ProxyTests, |
|
47871
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
703 QuotingTests, |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
704 UnquotingTests, |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
705 urlencode_Tests, |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
706 Pathname_Tests, |
|
52476
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
49677
diff
changeset
|
707 Utility_Tests, |
|
53297
c8a75710ab25
Fix for the Issue918368 - urllib doesn't correct server returned urls
Senthil Kumaran <orsenthil@gmail.com>
parents:
52476
diff
changeset
|
708 URLopener_Tests, |
|
47871
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
709 #FTPWrapperTests, |
|
801754201b11
Handle urllib's renaming for Python 3.0:
Brett Cannon <bcannon@gmail.com>
parents:
47372
diff
changeset
|
710 ) |
|
16071
af7d7914fbf9
added some tests for urlencode
Skip Montanaro <skip@pobox.com>
parents:
16027
diff
changeset
|
711 |
|
16325
330239575e1e
added several more urlencode test cases - part of patch 103391
Skip Montanaro <skip@pobox.com>
parents:
16071
diff
changeset
|
712 |
|
330239575e1e
added several more urlencode test cases - part of patch 103391
Skip Montanaro <skip@pobox.com>
parents:
16071
diff
changeset
|
713 |
|
28821
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
714 if __name__ == '__main__': |
|
64cb657b0338
Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon <bcannon@gmail.com>
parents:
24364
diff
changeset
|
715 test_main() |
