diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-08-05 22:05:53 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-08-05 22:05:53 (GMT) |
commit | 21603c96e85eed7e035b8ea177432bd8fbd6a294 (patch) | |
tree | 773929ed0de3fcde8c5d01a4940390d79aa409cb /Lib/test | |
parent | 4eda93723ee06c21332b17c2823ba0ff9896427f (diff) | |
parent | 636130ed65b8fbbc9b340ec1ceecad24c96234f5 (diff) | |
download | cpython-21603c96e85eed7e035b8ea177432bd8fbd6a294.zip cpython-21603c96e85eed7e035b8ea177432bd8fbd6a294.tar.gz cpython-21603c96e85eed7e035b8ea177432bd8fbd6a294.tar.bz2 |
merge heads
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_httpservers.py | 12 | ||||
-rw-r--r-- | Lib/test/test_ipaddress.py | 25 |
2 files changed, 20 insertions, 17 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index 1430ff2..171361f 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -313,6 +313,8 @@ class CGIHTTPServerTestCase(BaseTestCase): class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler): pass + linesep = os.linesep.encode('ascii') + def setUp(self): BaseTestCase.setUp(self) self.cwd = os.getcwd() @@ -410,7 +412,7 @@ class CGIHTTPServerTestCase(BaseTestCase): def test_headers_and_content(self): res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_post(self): @@ -419,7 +421,7 @@ class CGIHTTPServerTestCase(BaseTestCase): headers = {'Content-type' : 'application/x-www-form-urlencoded'} res = self.request('/cgi-bin/file2.py', 'POST', params, headers) - self.assertEqual(res.read(), b'1, python, 123456\n') + self.assertEqual(res.read(), b'1, python, 123456' + self.linesep) def test_invaliduri(self): res = self.request('/cgi-bin/invalid') @@ -430,20 +432,20 @@ class CGIHTTPServerTestCase(BaseTestCase): headers = {b'Authorization' : b'Basic ' + base64.b64encode(b'username:pass')} res = self.request('/cgi-bin/file1.py', 'GET', headers=headers) - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_no_leading_slash(self): # http://bugs.python.org/issue2254 res = self.request('cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_os_environ_is_not_altered(self): signature = "Test CGI Server" os.environ['SERVER_SOFTWARE'] = signature res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) self.assertEqual(os.environ['SERVER_SOFTWARE'], signature) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 619fa44..09b4a5e 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -7,6 +7,7 @@ import unittest import re import contextlib +import operator import ipaddress class BaseTestCase(unittest.TestCase): @@ -72,6 +73,14 @@ class CommonTestMixin: with self.assertAddressError(re.escape(repr("1.0"))): self.factory(1.0) + def test_not_an_index_issue15559(self): + # Implementing __index__ makes for a very nasty interaction with the + # bytes constructor. Thus, we disallow implicit use as an integer + self.assertRaises(TypeError, operator.index, self.factory(1)) + self.assertRaises(TypeError, hex, self.factory(1)) + self.assertRaises(TypeError, bytes, self.factory(1)) + + class CommonTestMixin_v4(CommonTestMixin): def test_leading_zeros(self): @@ -599,7 +608,6 @@ class IpaddrUnitTest(unittest.TestCase): self.assertEqual(first, last) self.assertEqual(128, ipaddress._count_righthand_zero_bits(0, 128)) self.assertEqual("IPv4Network('1.2.3.0/24')", repr(self.ipv4_network)) - self.assertEqual('0x1020318', hex(self.ipv4_network)) def testMissingAddressVersion(self): class Broken(ipaddress._BaseAddress): @@ -639,8 +647,8 @@ class IpaddrUnitTest(unittest.TestCase): ipv4 = ipaddress.ip_network('1.2.3.4') ipv6 = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1') - self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4))) - self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6))) + self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4.network_address))) + self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6.network_address))) v6_int = 42540616829182469433547762482097946625 self.assertEqual(self.ipv6_interface._ip, @@ -723,8 +731,8 @@ class IpaddrUnitTest(unittest.TestCase): '2001:658:22a:cafe:ffff:ffff:ffff:ffff') def testGetPrefixlen(self): - self.assertEqual(self.ipv4_interface.prefixlen, 24) - self.assertEqual(self.ipv6_interface.prefixlen, 64) + self.assertEqual(self.ipv4_interface.network.prefixlen, 24) + self.assertEqual(self.ipv6_interface.network.prefixlen, 64) def testGetSupernet(self): self.assertEqual(self.ipv4_network.supernet().prefixlen, 23) @@ -1545,13 +1553,6 @@ class IpaddrUnitTest(unittest.TestCase): self.assertEqual(42540616829182469433547762482097946625, int(self.ipv6_address)) - def testHexRepresentation(self): - self.assertEqual(hex(0x1020304), - hex(self.ipv4_address)) - - self.assertEqual(hex(0x20010658022ACAFE0200000000000001), - hex(self.ipv6_address)) - def testForceVersion(self): self.assertEqual(ipaddress.ip_network(1).version, 4) self.assertEqual(ipaddress.IPv6Network(1).version, 6) |