Exemple #1
0
 def test_dict(self):
     token = LiveMessageToken({'1': "foo", '2': 3})
     self.assert_dict(token, {'1': "foo", '2': 3})
     # The order of keys are undefined
     serialized = token.serialize()
     if serialized != b'h1:13:foo1:2i3ss':
         self.assertEqual(serialized, b'h1:2i3s1:13:foos')
Exemple #2
0
 def test_deserialize_invalid(self):
     self.assertIs(None, LiveMessageToken.deserialize(b'i')[0])
     self.assertIs(None, LiveMessageToken.deserialize(b'l')[0])
     self.assertIs(None, LiveMessageToken.deserialize(b'h')[0])
     self.assertIs(None, LiveMessageToken.deserialize(b'hi1s')[0])
     self.assertIs(None, LiveMessageToken.deserialize(b'u')[0])
     self.assertIs(None, LiveMessageToken.deserialize(b'u7:YWxpdmU')[0])
Exemple #3
0
 def test_empty_list(self):
     token = LiveMessageToken([])
     self.assert_list(token, [])
     self.assertEqual(token.serialize(), b'ls')
Exemple #4
0
 def test_base64(self):
     token = LiveMessageToken(b'foobar123456')
     self.assert_base64(token, b'foobar123456')
     self.assertEqual(token.serialize(), b'u10:Zm9vYmFyMTIzNDU2')
Exemple #5
0
 def test_string(self):
     a_ring = b'\xc3\xa5'.decode('utf-8')
     token = LiveMessageToken("foobar123456" + a_ring)
     self.assert_string(token, "foobar123456" + a_ring)
     self.assertEqual(token.serialize(), b'E:foobar123456\xc3\xa5')
Exemple #6
0
 def test_int(self):
     token = LiveMessageToken(10)
     self.assert_int(token, 10)
     self.assertEqual(token.serialize(), b'iAs')
Exemple #7
0
 def test_deserialize_empty_list(self):
     (token, rest) = LiveMessageToken.deserialize(b'ls')
     self.assert_list(token, [])
     self.assertFalse(rest)
Exemple #8
0
 def test_deserialize_empty(self):
     self.assertIs(None, LiveMessageToken.deserialize(b'')[0])
Exemple #9
0
 def test_deserialize_base64(self):
     (token, rest) = LiveMessageToken.deserialize(b'u8:YWxpdmU=')
     self.assert_base64(token, b'alive')
     self.assertFalse(rest)
Exemple #10
0
 def test_deserialize_empty_base64(self):
     (token, rest) = LiveMessageToken.deserialize(b'u0:')
     self.assert_base64(token, b'')
     self.assertFalse(rest)
Exemple #11
0
 def test_deserialize_dict_with_list(self):
     (token,
      rest) = LiveMessageToken.deserialize(b'h1:1li1Es1:Alss1:2h1:3hsss')
     self.assert_dict(token, {'1': [0x1e, "A", []], '2': {'3': {}}})
     self.assertFalse(rest)
Exemple #12
0
 def test_deserialize_dict(self):
     (token, rest) = LiveMessageToken.deserialize(b'h1:13:foo1:26:foobars')
     self.assert_dict(token, {'1': "foo", '2': "foobar"})
     self.assertFalse(rest)
Exemple #13
0
 def test_deserialize_empty_dict(self):
     (token, rest) = LiveMessageToken.deserialize(b'hs')
     self.assert_dict(token, {})
     self.assertFalse(rest)
Exemple #14
0
 def test_deserialize_list(self):
     (token, rest) = LiveMessageToken.deserialize(b'li1siAss')
     self.assert_list(token, [1, 10])
     self.assertFalse(rest)
Exemple #15
0
 def test_list(self):
     token = LiveMessageToken([1, "foo"])
     self.assert_list(token, [1, "foo"])
     self.assertEqual(token.serialize(), b'li1s3:foos')
Exemple #16
0
 def test_empty_dict(self):
     token = LiveMessageToken({})
     self.assert_dict(token, {})
     self.assertEqual(token.serialize(), b'hs')
Exemple #17
0
 def test_deserialize_empty_string(self):
     (token, rest) = LiveMessageToken.deserialize(b'0:')
     self.assert_string(token, "")
     self.assertFalse(rest)
Exemple #18
0
 def test_dict_in_list_in_dict(self):
     token = LiveMessageToken({'a': [{'b': 1}, 2]})
     self.assertIs(type(token.value['a']), list)
     self.assertEqual(token.serialize(), b'h1:alh1:bi1ssi2sss')
Exemple #19
0
 def test_deserialize_string(self):
     (token, rest) = LiveMessageToken.deserialize(b'10:123456789abcdefP')
     self.assert_string(token, "123456789abcdefP")
     self.assertFalse(rest)
Exemple #20
0
 def test_empty_token(self):
     self.assert_invalid(LiveMessageToken())
Exemple #21
0
 def test_deserialize_int(self):
     (token, rest) = LiveMessageToken.deserialize(b'i1A2s')
     self.assert_int(token, 0x1a2)
     self.assertFalse(rest)