def test_fail_set_non_utf8_value(self): obj = self.Dummy() try: obj.field = u('привет').encode('cp1251') except UnicodeDecodeError: pass else: self.fail('%s expected' % UnicodeDecodeError)
def f(s, e='latin-1'): return u(s).format(STX=u(STX), ETX=u(ETX), ETB=u(ETB), CR=u(CR), LF=u(LF), CRLF=u(CRLF)).encode(e)
def test_common(self): msg = u('2P|1|2776833|||王^大^明||||||||||||||||||||\x0D\x03') self.assertEqual(b'CF', codec.make_checksum(msg))
def test_decode_nonascii_chars_as_unicode(self): msg = f('привет|мир|!', 'utf8') res = [u('привет'), u('мир'), '!'] self.assertEqual(res, codec.decode_record(msg, 'utf8'))
def test_raw_value(self): obj = self.Dummy() obj.field = u('привет') self.assertEqual(obj._data['field'], u('привет'))
def test_set_utf8_value(self): obj = self.Dummy() obj.field = u('привет').encode('utf-8') self.assertEqual(obj.field, u('привет'))
def test_decode_message_with_nonascii(self): msg = f("{STX}1Й|Ц|У|К{CR}{ETX}F1{CRLF}", "cp1251") res = [[u("Й"), u("Ц"), u("У"), u("К")]] self.assertEqual(res, codec.decode(msg, "cp1251"))
def test_bytes(self): msg = u("2P|1|2776833|||王^大^明||||||||||||||||||||\x0D\x03").encode("utf8") self.assertEqual(b"4B", codec.make_checksum(msg))
def test_common(self): msg = u("2P|1|2776833|||王^大^明||||||||||||||||||||\x0D\x03") self.assertEqual(b"CF", codec.make_checksum(msg))
def f(s, e="latin-1"): return u(s).format(STX=u(STX), ETX=u(ETX), ETB=u(ETB), CR=u(CR), LF=u(LF), CRLF=u(CRLF)).encode(e)
def test_decode_nonascii_chars_as_unicode(self): msg = f("привет|мир|!", "utf8") res = [u("привет"), u("мир"), "!"] self.assertEqual(res, codec.decode_record(msg, "utf8"))
def test_bytes(self): msg = u('2P|1|2776833|||王^大^明||||||||||||||||||||\x0D\x03').encode( 'utf8') self.assertEqual(b'4B', codec.make_checksum(msg))
def test_set_value(self): obj = self.Dummy() obj.field = u('привет') self.assertEqual(obj.field, u('привет'))
def test_decode_message_with_nonascii(self): msg = f('{STX}1Й|Ц|У|К{CR}{ETX}F1{CRLF}', 'cp1251') res = [[u('Й'), u('Ц'), u('У'), u('К')]] self.assertEqual(res, codec.decode(msg, 'cp1251'))