def test_ping_result_message_decode(self): """ This is an example message received from an actual ping server. Let's try to make sense of it. """ repsonse = b'ds8:messagesb1;' # As returned by the "requests" lib result = bpickle.loads(repsonse) expected = {"messages": True} self.assertEqual(expected, result)
def test_real_registration_answer_loading(self): """ We succeed at decoding a real-world example.""" expected = { 'server-api': '3.3', 'server-uuid': 'server-uuid', 'messages': [{ 'types': ['register', 'test'], 'type': 'accepted-types' }, { 'id': 'secure-id', 'insecure-id': 999999, 'type': 'set-id' }] } result = bpickle.loads(REAL_ANSWER) self.assertEqual(expected, result)
def test_long(self): long = 99999999999999999999999999999 self.assertEqual(bpickle.loads(bpickle.dumps(long)), long)
def test_bool(self): self.assertEqual(bpickle.loads(bpickle.dumps(True)), True)
def test_dict(self): dumped_tostr = bpickle.dumps({True: "hello"}) self.assertEqual(bpickle.loads(dumped_tostr), {True: "hello"}) dumped_tobool = bpickle.dumps({True: False}) self.assertEqual(bpickle.loads(dumped_tobool), {True: False})
def test_none(self): self.assertEqual(bpickle.loads(bpickle.dumps(None)), None)
def test_unicode(self): self.assertEqual(bpickle.loads(bpickle.dumps(u'\xc0')), u'\xc0')
def test_inverted_lists(self, l): assert bpickle.loads(bpickle.dumps(l)) == l
def test_tuple(self): data = bpickle.dumps((1, [], 2, 'hello', 3.0)) self.assertEqual(bpickle.loads(data), (1, [], 2, 'hello', 3.0))
def test_list(self): self.assertEqual(bpickle.loads(bpickle.dumps([1, 2, 'hello', 3.0])), [1, 2, 'hello', 3.0])
def test_string(self, s): assert bpickle.loads(bpickle.dumps(s)) == s
def test_float_scientific_notation(self): number = 0.00005 self.assertTrue("e" in repr(number)) self.assertAlmostEquals(bpickle.loads(bpickle.dumps(number)), number)
def test_float(self): self.assertAlmostEquals(bpickle.loads(bpickle.dumps(2.3)), 2.3)
def test_int(self, i): assert bpickle.loads(bpickle.dumps(i)) == i