Example #1
0
    def test_dump_normal2(self):
        text = r'[{"name":"benjamin", "age":21}]'
        obj = objson.loads(text)
        expected = objson.dumps(obj)
        self.assertEqual(json.loads(text), json.loads(expected))

        expected = objson.dumps([dict(name="benjamin", age=21)])
        self.assertEqual(json.loads(text), json.loads(expected))
Example #2
0
    def delete_container_2(self, name):
        """

        :param name: `class`:`str`, container name
        :return: `class`:`bool`, return True if delete success, otherwise return False
        """
        code, container = self.get_container(name)
        if code == httplib.NOT_FOUND:
            return True
        elif code != httplib.OK:
            self.logger.error("Container %s on %s not exists. %d", name, self._host, code)
            return False

        if container.status.Running:
            code, message = self.change_container(name)
            if code != httplib.OK:
                self.logger.error(
                    "Stop container %s on %s error, status code %d, message %s",
                    name,
                    self._host,
                    code,
                    objson.dumps(message),
                )
                return False

        code, message = self.delete_container(name)
        if code != httplib.OK:
            self.logger.error(
                "Delete container %s on %s error, status code %d, message %s",
                name,
                self._host,
                code,
                objson.dumps(message),
            )
            return False
        return True
Example #3
0
def benchmark_objson_dumps(text, times=100000):
    obj = objson.loads(text)
    for _ in xrange(times):
        objson.dumps(obj)
Example #4
0
 def test_dumps(self):
     text = r'{"sort":true, "name":{"first":"benjamin", "last": "yan"}}'
     obj = objson.loads(text)
     actual = objson.dumps(obj)
     self.assertDictEqual(json.loads(text), json.loads(actual))