Python codecs.code_page_encode() Examples
The following are 10
code examples of codecs.code_page_encode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
codecs
, or try the search function
.
Example #1
Source File: test_codecs.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_invalid_code_page(self): self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a') self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a') self.assertRaises(OSError, codecs.code_page_encode, 123, 'a') self.assertRaises(OSError, codecs.code_page_decode, 123, b'a')
Example #2
Source File: test_codecs.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_code_page_name(self): self.assertRaisesRegex(UnicodeEncodeError, 'cp932', codecs.code_page_encode, 932, '\xff') self.assertRaisesRegex(UnicodeDecodeError, 'cp932', codecs.code_page_decode, 932, b'\x81\x00', 'strict', True) self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8', codecs.code_page_decode, self.CP_UTF8, b'\xff', 'strict', True)
Example #3
Source File: test_codecs.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def check_encode(self, cp, tests): for text, errors, expected in tests: if expected is not None: try: encoded = codecs.code_page_encode(cp, text, errors) except UnicodeEncodeError as err: self.fail('Unable to encode %a to "cp%s" with ' 'errors=%r: %s' % (text, cp, errors, err)) self.assertEqual(encoded[0], expected, '%a.encode("cp%s", %r)=%a != %a' % (text, cp, errors, encoded[0], expected)) self.assertEqual(encoded[1], len(text)) else: self.assertRaises(UnicodeEncodeError, codecs.code_page_encode, cp, text, errors)
Example #4
Source File: test_codecs.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_invalid_code_page(self): self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a') self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a') self.assertRaises(OSError, codecs.code_page_encode, 123, 'a') self.assertRaises(OSError, codecs.code_page_decode, 123, b'a')
Example #5
Source File: test_codecs.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_code_page_name(self): self.assertRaisesRegex(UnicodeEncodeError, 'cp932', codecs.code_page_encode, 932, '\xff') self.assertRaisesRegex(UnicodeDecodeError, 'cp932', codecs.code_page_decode, 932, b'\x81\x00') self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8', codecs.code_page_decode, self.CP_UTF8, b'\xff')
Example #6
Source File: test_codecs.py From ironpython3 with Apache License 2.0 | 5 votes |
def check_encode(self, cp, tests): for text, errors, expected in tests: if expected is not None: try: encoded = codecs.code_page_encode(cp, text, errors) except UnicodeEncodeError as err: self.fail('Unable to encode %a to "cp%s" with ' 'errors=%r: %s' % (text, cp, errors, err)) self.assertEqual(encoded[0], expected, '%a.encode("cp%s", %r)=%a != %a' % (text, cp, errors, encoded[0], expected)) self.assertEqual(encoded[1], len(text)) else: self.assertRaises(UnicodeEncodeError, codecs.code_page_encode, cp, text, errors)
Example #7
Source File: test_codecs.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_code_page_encode(self): # Sanity self.assertEqual(codecs.code_page_encode(1252, "aaaa"), (b"aaaa", 4)) self.assertRaises(TypeError, codecs.code_page_encode, b"abc") self.assertRaises(TypeError, codecs.code_page_encode, None) self.assertRaises(TypeError, codecs.code_page_encode, None, None)
Example #8
Source File: test_codecs.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_invalid_code_page(self): self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a') self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a') self.assertRaises(OSError, codecs.code_page_encode, 123, 'a') self.assertRaises(OSError, codecs.code_page_decode, 123, b'a')
Example #9
Source File: test_codecs.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_code_page_name(self): self.assertRaisesRegex(UnicodeEncodeError, 'cp932', codecs.code_page_encode, 932, '\xff') self.assertRaisesRegex(UnicodeDecodeError, 'cp932', codecs.code_page_decode, 932, b'\x81\x00', 'strict', True) self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8', codecs.code_page_decode, self.CP_UTF8, b'\xff', 'strict', True)
Example #10
Source File: test_codecs.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def check_encode(self, cp, tests): for text, errors, expected in tests: if expected is not None: try: encoded = codecs.code_page_encode(cp, text, errors) except UnicodeEncodeError as err: self.fail('Unable to encode %a to "cp%s" with ' 'errors=%r: %s' % (text, cp, errors, err)) self.assertEqual(encoded[0], expected, '%a.encode("cp%s", %r)=%a != %a' % (text, cp, errors, encoded[0], expected)) self.assertEqual(encoded[1], len(text)) else: self.assertRaises(UnicodeEncodeError, codecs.code_page_encode, cp, text, errors)