def test_random_tree(self): for i in xrange(0, 16): p = {} populate(p, 256, 4) sp = dumps(p) p2 = loads(sp) self.assertEquals(p, p2)
def test_datetime(self): now = datetime.now(pytz.utc) obj = {"now": now} serialized = dumps(obj) obj2 = loads(serialized) td = obj2["now"] - now seconds_delta = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6 self.assertTrue(abs(seconds_delta) < 0.001)
def test_datetime(self): now = datetime.now(pytz.utc) obj = {"now" : now} serialized = dumps(obj) obj2 = loads(serialized) td = obj2["now"] - now seconds_delta = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6 self.assertTrue(abs(seconds_delta) < 0.001)
def test_codec(self): import_class(TestData) data = TestData(u"Lorem ipsum dolor sit amet", "consectetur adipisicing elit", 42) data2 = TestData(u"She's got both hands in her pockets", "and she won't look at you won't look at you eh", 66, 23.54, None, True, False, u"Alejandro") data2.nested = data serialized = dumps(data2) data3 = loads(serialized) self.assertTrue(data2 == data3)
def _gzip_recvobj(self): sock_buf = self.recvbytes(4) if sock_buf is None: return None message_length = _bintoint(sock_buf.getvalue()) sock_buf = self.recvbytes(message_length) if sock_buf is None: return None sock_buf.seek(0) fd = gzip.GzipFile(mode="rb", fileobj=sock_buf) data = fd.read() retval = loads(data) return retval
def _recvobj(self): """ Atomic read of a BSON message. This function either returns a dict, None, or raises a socket error. If the return value is None, it means the socket is closed by the other side. """ sock_buf = self.recvbytes(4) if sock_buf is None: return None message_length = _bintoint(sock_buf.getvalue()) sock_buf = self.recvbytes(message_length - 4, sock_buf) if sock_buf is None: return None retval = loads(sock_buf.getvalue()) return retval
def test_long_array(self): serialized = dumps(self.doc) doc2 = loads(serialized) self.assertEquals(self.doc, doc2)