def test_extra_tabs(self): self.assertEqual(TextProtocol().write(u'foo', u'bar\tbaz'), b'foo\tbar\tbaz') self.assertEqual(TextProtocol().write(u'foo\tbar', u'baz'), b'foo\tbar\tbaz') self.assertEqual(TextProtocol().read(b'foo\tbar\tbaz'), (u'foo', u'bar\tbaz'))
def test_no_tabs(self): self.assertEqual(TextProtocol().write(u'foo', None), b'foo') self.assertEqual(TextProtocol().write(None, u'foo'), b'foo') self.assertEqual(TextProtocol().read(b'foo'), (u'foo', None)) self.assertEqual(TextProtocol().write(u'', None), b'') self.assertEqual(TextProtocol().write(None, None), b'') self.assertEqual(TextProtocol().write(None, u''), b'') self.assertEqual(TextProtocol().read(b''), (u'', None))
def test_latin_1_fallback(self): # we fall back to latin-1 for the whole line, not individual fields self.assertEqual(TextProtocol().read(b'caf\xe9\tol\xc3\xa9'), (u'caf\xe9', u'ol\xc3\xa9'))
def test_utf_8(self): self.assertEqual(TextProtocol().read(b'caf\xc3\xa9\tol\xc3\xa9'), (u'caf\xe9', u'ol\xe9'))
def test_no_strip(self): self.assertEqual(TextProtocol().read(b'foo\t \n\n'), (u'foo', u' \n\n'))
def test_round_trip(self): self.assertRoundTripOK(TextProtocol(), u'foo', u'bar') self.assertRoundTripOK(TextProtocol(), u'foo', None) self.assertRoundTripOK(TextProtocol(), u'foo', u'') self.assertRoundTripOK(TextProtocol(), u'caf\xe9', u'\Xe90\c1a')