示例#1
0
 def test_write_encoding_mismatch(self):
     '''
     Attempt to decode a unicode character with the ASCII encoding
     and assert that this raises an error.
     '''
     rule = rules.Bytes('ascii')
     self.assertRaises(ValueError, rule.write, 'ጷ'.encode('utf8'))
示例#2
0
 def test_read_encoding_mismatch(self):
     '''
     Attempt to encode a unicode character with the ASCII encoding
     and assert that this raises an error.
     '''
     rule = rules.Bytes('ascii')
     self.assertRaises(ValueError, rule.read, 'ጷ')
示例#3
0
 def test_write_utf16(self):
     rule = rules.Bytes('utf16')
     self.assertEqual(rule.write('hello'.encode('utf16')), 'hello')
示例#4
0
 def test_write(self):
     rule = rules.Bytes()
     self.assertEqual(rule.write(b'hello'), 'hello')
示例#5
0
 def test_read_utf16(self):
     rule = rules.Bytes('utf16')
     self.assertEqual(rule.read('hello'), 'hello'.encode('utf16'))
示例#6
0
 def test_read(self):
     rule = rules.Bytes()
     self.assertEqual(rule.read('hello'), b'hello')