Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(29066)

Delta Between Two Patch Sets: Lib/test/test_codecs.py

Issue 17839: base64 module should use memoryview
Left Patch Set: Created 6 years, 4 months ago
Right Patch Set: Created 6 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_base64.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import _testcapi 1 import _testcapi
2 import codecs 2 import codecs
3 import io 3 import io
4 import locale 4 import locale
5 import sys 5 import sys
6 import unittest 6 import unittest
7 import warnings 7 import warnings
8 8
9 from test import support 9 from test import support
10 10
(...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 2278
2279 def test_readline(self): 2279 def test_readline(self):
2280 for encoding in bytes_transform_encodings: 2280 for encoding in bytes_transform_encodings:
2281 if encoding in ['uu_codec', 'zlib_codec']: 2281 if encoding in ['uu_codec', 'zlib_codec']:
2282 continue 2282 continue
2283 sin = codecs.encode(b"\x80", encoding) 2283 sin = codecs.encode(b"\x80", encoding)
2284 reader = codecs.getreader(encoding)(io.BytesIO(sin)) 2284 reader = codecs.getreader(encoding)(io.BytesIO(sin))
2285 sout = reader.readline() 2285 sout = reader.readline()
2286 self.assertEqual(sout, b"\x80") 2286 self.assertEqual(sout, b"\x80")
2287 2287
2288 def test_buffer_api_usage(self):
2289 # We check all the transform codecs accept memoryview input
2290 # for encoding and decoding
2291 # and also that they roundtrip correctly
2292 original = b"12345\x80"
2293 for encoding in bytes_transform_encodings:
2294 data = original
2295 view = memoryview(data)
2296 data = codecs.encode(data, encoding)
2297 view_encoded = codecs.encode(view, encoding)
2298 self.assertEqual(view_encoded, data)
2299 view = memoryview(data)
2300 data = codecs.decode(data, encoding)
2301 self.assertEqual(data, original)
2302 view_decoded = codecs.decode(view, encoding)
2303 self.assertEqual(view_decoded, data)
2304
2305
2288 2306
2289 @unittest.skipUnless(sys.platform == 'win32', 2307 @unittest.skipUnless(sys.platform == 'win32',
2290 'code pages are specific to Windows') 2308 'code pages are specific to Windows')
2291 class CodePageTest(unittest.TestCase): 2309 class CodePageTest(unittest.TestCase):
2292 # CP_UTF8 is already tested by CP65001Test 2310 # CP_UTF8 is already tested by CP65001Test
2293 CP_UTF8 = 65001 2311 CP_UTF8 = 65001
2294 2312
2295 def test_invalid_code_page(self): 2313 def test_invalid_code_page(self):
2296 self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a') 2314 self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a')
2297 self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a') 2315 self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a')
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 self.assertEqual(decoded, ('\u9a3e\u9a3e', 4)) 2448 self.assertEqual(decoded, ('\u9a3e\u9a3e', 4))
2431 2449
2432 decoded = codecs.code_page_decode(932, 2450 decoded = codecs.code_page_decode(932,
2433 b'abc', 'strict', 2451 b'abc', 'strict',
2434 False) 2452 False)
2435 self.assertEqual(decoded, ('abc', 3)) 2453 self.assertEqual(decoded, ('abc', 3))
2436 2454
2437 2455
2438 if __name__ == "__main__": 2456 if __name__ == "__main__":
2439 unittest.main() 2457 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+