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

Side by Side Diff: Lib/test/test_binascii.py

Issue 25357: Add an optional newline parameter to binascii.b2a_base64() to not add a newline
Patch Set: Created 4 years 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:
View unified diff | Download patch
OLDNEW
1 """Test the binascii C module.""" 1 """Test the binascii C module."""
2 2
3 import unittest 3 import unittest
4 import binascii 4 import binascii
5 import array 5 import array
6 6
7 # Note: "*_hex" functions are aliases for "(un)hexlify" 7 # Note: "*_hex" functions are aliases for "(un)hexlify"
8 b2a_functions = ['b2a_base64', 'b2a_hex', 'b2a_hqx', 'b2a_qp', 'b2a_uu', 8 b2a_functions = ['b2a_base64', 'b2a_hex', 'b2a_hqx', 'b2a_qp', 'b2a_uu',
9 'hexlify', 'rlecode_hqx'] 9 'hexlify', 'rlecode_hqx']
10 a2b_functions = ['a2b_base64', 'a2b_hex', 'a2b_hqx', 'a2b_qp', 'a2b_uu', 10 a2b_functions = ['a2b_base64', 'a2b_hex', 'a2b_hqx', 'a2b_qp', 'a2b_uu',
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if fb == 'b2a_hqx': 254 if fb == 'b2a_hqx':
255 # b2a_hqx returns a tuple 255 # b2a_hqx returns a tuple
256 res, _ = res 256 res, _ = res
257 binary_res, _ = binary_res 257 binary_res, _ = binary_res
258 self.assertEqual(res, raw, "{}/{} conversion: " 258 self.assertEqual(res, raw, "{}/{} conversion: "
259 "{!r} != {!r}".format(fb, fa, res, raw)) 259 "{!r} != {!r}".format(fb, fa, res, raw))
260 self.assertEqual(res, binary_res) 260 self.assertEqual(res, binary_res)
261 self.assertIsInstance(res, bytes) 261 self.assertIsInstance(res, bytes)
262 # non-ASCII string 262 # non-ASCII string
263 self.assertRaises(ValueError, a2b, "\x80") 263 self.assertRaises(ValueError, a2b, "\x80")
264
265 def test_b2a_base64_newline(self):
266 # Issue #25357: test newline parameter
267 b = self.type2test(b'hello')
268 self.assertEqual(binascii.b2a_base64(b),
269 b'aGVsbG8=\n')
270 self.assertEqual(binascii.b2a_base64(b, newline=True),
271 b'aGVsbG8=\n')
272 self.assertEqual(binascii.b2a_base64(b, newline=False),
273 b'aGVsbG8=')
264 274
265 275
266 class ArrayBinASCIITest(BinASCIITest): 276 class ArrayBinASCIITest(BinASCIITest):
267 def type2test(self, s): 277 def type2test(self, s):
268 return array.array('B', list(s)) 278 return array.array('B', list(s))
269 279
270 280
271 class BytearrayBinASCIITest(BinASCIITest): 281 class BytearrayBinASCIITest(BinASCIITest):
272 type2test = bytearray 282 type2test = bytearray
273 283
274 284
275 class MemoryviewBinASCIITest(BinASCIITest): 285 class MemoryviewBinASCIITest(BinASCIITest):
276 type2test = memoryview 286 type2test = memoryview
277 287
278 288
279 if __name__ == "__main__": 289 if __name__ == "__main__":
280 unittest.main() 290 unittest.main()
OLDNEW

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