diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-20 07:00:36 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-20 07:00:36 (GMT) |
commit | 8490f5acfee7269ac0eb41257a3a214dfb31a655 (patch) | |
tree | 7cd039c0f6418571d9f8cc89741c3ec4938f2ebc /Lib | |
parent | 0eac13052c498e21cbb60ed321e5a9ea10d07b35 (diff) | |
download | cpython-8490f5acfee7269ac0eb41257a3a214dfb31a655.zip cpython-8490f5acfee7269ac0eb41257a3a214dfb31a655.tar.gz cpython-8490f5acfee7269ac0eb41257a3a214dfb31a655.tar.bz2 |
Issue #23001: Few functions in modules mmap, ossaudiodev, socket, ssl, and
codecs, that accepted only read-only bytes-like object now accept writable
bytes-like object too.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_codecs.py | 1 | ||||
-rw-r--r-- | Lib/test/test_mmap.py | 8 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 10 | ||||
-rw-r--r-- | Lib/test/test_ssl.py | 2 |
4 files changed, 19 insertions, 2 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 4d5d7bb..fb3db77 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1086,6 +1086,7 @@ class UTF8SigTest(UTF8Test, unittest.TestCase): class EscapeDecodeTest(unittest.TestCase): def test_empty(self): self.assertEqual(codecs.escape_decode(b""), (b"", 0)) + self.assertEqual(codecs.escape_decode(bytearray()), (b"", 0)) def test_raw(self): decode = codecs.escape_decode diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 4d23f16..3de84e8 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -282,6 +282,7 @@ class MmapTests(unittest.TestCase): self.assertEqual(m.find(b'one', 1), 8) self.assertEqual(m.find(b'one', 1, -1), 8) self.assertEqual(m.find(b'one', 1, -2), -1) + self.assertEqual(m.find(bytearray(b'one')), 0) def test_rfind(self): @@ -300,6 +301,7 @@ class MmapTests(unittest.TestCase): self.assertEqual(m.rfind(b'one', 0, -2), 0) self.assertEqual(m.rfind(b'one', 1, -1), 8) self.assertEqual(m.rfind(b'one', 1, -2), -1) + self.assertEqual(m.rfind(bytearray(b'one')), 8) def test_double_close(self): @@ -601,8 +603,10 @@ class MmapTests(unittest.TestCase): m.write(b"bar") self.assertEqual(m.tell(), 6) self.assertEqual(m[:], b"012bar6789") - m.seek(8) - self.assertRaises(ValueError, m.write, b"bar") + m.write(bytearray(b"baz")) + self.assertEqual(m.tell(), 9) + self.assertEqual(m[:], b"012barbaz9") + self.assertRaises(ValueError, m.write, b"ba") def test_non_ascii_byte(self): for b in (129, 200, 255): # > 128 diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d43e56d..72eac0d 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1074,6 +1074,7 @@ class GeneralModuleTests(unittest.TestCase): assertInvalid(f, b'\x00' * 3) assertInvalid(f, b'\x00' * 5) assertInvalid(f, b'\x00' * 16) + self.assertEqual('170.85.170.85', f(bytearray(b'\xaa\x55\xaa\x55'))) self.assertEqual('1.0.1.0', g(b'\x01\x00\x01\x00')) self.assertEqual('170.85.170.85', g(b'\xaa\x55\xaa\x55')) @@ -1081,6 +1082,7 @@ class GeneralModuleTests(unittest.TestCase): assertInvalid(g, b'\x00' * 3) assertInvalid(g, b'\x00' * 5) assertInvalid(g, b'\x00' * 16) + self.assertEqual('170.85.170.85', g(bytearray(b'\xaa\x55\xaa\x55'))) @unittest.skipUnless(hasattr(socket, 'inet_ntop'), 'test needs socket.inet_ntop()') @@ -1110,6 +1112,7 @@ class GeneralModuleTests(unittest.TestCase): 'aef:b01:506:1001:ffff:9997:55:170', f(b'\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70') ) + self.assertEqual('::1', f(bytearray(b'\x00' * 15 + b'\x01'))) assertInvalid(b'\x12' * 15) assertInvalid(b'\x12' * 17) @@ -1497,6 +1500,7 @@ class BasicCANTest(unittest.TestCase): s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, can_filter) self.assertEqual(can_filter, s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, 8)) + s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, bytearray(can_filter)) @unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.') @@ -4508,6 +4512,12 @@ class TestLinuxAbstractNamespace(unittest.TestCase): finally: s.close() + def testBytearrayName(self): + # Check that an abstract name can be passed as a bytearray. + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: + s.bind(bytearray(b"\x00python\x00test\x00")) + self.assertEqual(s.getsockname(), b"\x00python\x00test\x00") + @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'test needs socket.AF_UNIX') class TestUnixDomain(unittest.TestCase): diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 0cf9cc2..15d6b82 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -171,6 +171,8 @@ class BasicSocketTests(unittest.TestCase): self.assertRaises(TypeError, ssl.RAND_egd, 1) self.assertRaises(TypeError, ssl.RAND_egd, 'foo', 1) ssl.RAND_add("this is a random string", 75.0) + ssl.RAND_add(b"this is a random bytes object", 75.0) + ssl.RAND_add(bytearray(b"this is a random bytearray object"), 75.0) @unittest.skipUnless(os.name == 'posix', 'requires posix') def test_random_fork(self): |