当前位置: 首页>>代码示例>>Python>>正文


Python JsonBuilder.put方法代码示例

本文整理汇总了Python中frontik.json_builder.JsonBuilder.put方法的典型用法代码示例。如果您正苦于以下问题:Python JsonBuilder.put方法的具体用法?Python JsonBuilder.put怎么用?Python JsonBuilder.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在frontik.json_builder.JsonBuilder的用法示例。


在下文中一共展示了JsonBuilder.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_clear

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_clear(self):
        j = JsonBuilder()
        j.put({'a': 'b'})
        j.clear()

        self.assertTrue(j.is_empty())
        self.assertEqual(j.to_string(), '{}')
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:9,代码来源:test_json_builder.py

示例2: test_failed_future

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_failed_future(self):
        j = JsonBuilder()
        f = Future()
        result = TestDoc.get_test_request_result()
        result._data_parse_error = DataParseError(reason='error', code='code')
        f.set_result(result)
        j.put(f)

        self.assertEqual(j.to_dict(), {'error': {'reason': 'error', 'code': 'code'}})
开发者ID:hhru,项目名称:frontik,代码行数:11,代码来源:test_json_builder.py

示例3: test_failed_future

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_failed_future(self):
        j = JsonBuilder()
        f = Future()
        result = RequestResult()
        result.set_exception(FailedRequestException(reason='error', code='code'))
        f.set_result(result)
        j.put(f)

        self.assertEqual(j.to_string(), """{"error": {"reason": "error", "code": "code"}}""")
开发者ID:damirazo,项目名称:frontik,代码行数:11,代码来源:test_json_builder.py

示例4: test_failed_future

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_failed_future(self):
        j = JsonBuilder()
        f = Future()
        result = RequestResult()
        result.set_exception(FailedRequestException(reason='error', code='code'))
        f.set_result(result)
        j.put(f)

        self.assertJsonEqual(j.to_dict(), {'error': {'reason': 'error', 'code': 'code'}})
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:11,代码来源:test_json_builder.py

示例5: test_future_string_value

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_future_string_value(self):
        j = JsonBuilder()
        f = Future()
        result = TestDoc.get_test_request_result()
        result._content_type = 'xml'
        result._data = '<test>test</test>'
        f.set_result(result)
        j.put(f)

        self.assertEqual(j.to_dict(), {})
开发者ID:hhru,项目名称:frontik,代码行数:12,代码来源:test_json_builder.py

示例6: test_future

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_future(self):
        j = JsonBuilder()
        f = Future()
        j.put(f)

        self.assertFalse(j.is_empty())
        self.assertEqual(j.to_string(), """{}""")

        f.set_result({'a': 'b'})

        self.assertEqual(j.to_dict()['a'], 'b')
        self.assertEqual(j.to_string(), """{"a": "b"}""")
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:14,代码来源:test_json_builder.py

示例7: test_simple

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_simple(self):
        j = JsonBuilder()

        self.assertTrue(j.is_empty())

        j.put({})
        self.assertFalse(j.is_empty())
        self.assertEqual(j.to_string(), '{}')

        j.put({'a': 'b'})

        self.assertFalse(j.is_empty())
        self.assertEqual(j.to_string(), """{"a": "b"}""")
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:15,代码来源:test_json_builder.py

示例8: test_nested_future

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_nested_future(self):
        j = JsonBuilder()
        f1 = Future()
        f2 = Future()
        f3 = Future()

        f1.set_result({'nested': f2})
        j.put(f1)

        self.assertEqual(j.to_string(), """{"nested": null}""")

        f2.set_result({'a': f3})
        f3.set_result(['b', 'c'])

        self.assertEqual(j.to_string(), """{"nested": {"a": ["b", "c"]}}""")
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:17,代码来源:test_json_builder.py

示例9: test_serializable

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_serializable(self):
        class Serializable(object):
            def __init__(self, name, values):
                self.name = name
                self.values = values

            def to_dict(self):
                return {self.name: self.values}

        j = JsonBuilder()
        j.put(Serializable('some', ['test1', 'test2', 'test3']))

        self.assertJsonEqual(
            j.to_dict(), {'some': ['test1', 'test2', 'test3']}
        )
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:17,代码来源:test_json_builder.py

示例10: test_encoder

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_encoder(self):
        class CustomValue(object):
            def __iter__(self):
                return iter((1, 2, 3))

            def to_json(self):
                return '1.2.3'

        class JSONEncoder(json.JSONEncoder):
            def default(self, obj):
                if hasattr(obj, 'to_json'):
                    return obj.to_json()
                return json.JSONEncoder.default(self, obj)

        j = JsonBuilder(json_encoder=JSONEncoder)
        j.put({'a': CustomValue()})

        self.assertEqual(j.to_string(), """{"a": "1.2.3"}""")
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:20,代码来源:test_json_builder.py

示例11: test_nested_future_error_node

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_nested_future_error_node(self):
        j = JsonBuilder()
        f1 = Future()
        f2 = Future()

        f1.set_result({'nested': f2})
        j.put(f1)

        self.assertEqual(j.to_string(), """{"nested": null}""")
        result = TestDoc.get_test_request_result()
        result._data_parse_error = DataParseError(reason='error', code='code')

        f2.set_result(
            {'a': result}
        )

        self.assertEqual(
            j.to_dict(), {'nested': {'a': {'error': {'reason': 'error', 'code': 'code'}}}}
        )
开发者ID:hhru,项目名称:frontik,代码行数:21,代码来源:test_json_builder.py

示例12: test_nested_future_error_node

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_nested_future_error_node(self):
        j = JsonBuilder()
        f1 = Future()
        f2 = Future()

        f1.set_result({'nested': f2})
        j.put(f1)

        self.assertEqual(j.to_string(), """{"nested": null}""")
        result = RequestResult()
        result.set_exception(FailedRequestException(reason='error', code='code'))

        f2.set_result(
            {'a': result}
        )

        self.assertJsonEqual(
            j.to_dict(), {'nested': {'a': {'error': {'reason': 'error', 'code': 'code'}}}}
        )
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:21,代码来源:test_json_builder.py

示例13: test_nested_future_error_node

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_nested_future_error_node(self):
        j = JsonBuilder()
        f1 = Future()
        f2 = Future()

        f1.set_result({'nested': f2})
        j.put(f1)

        self.assertEqual(j.to_string(), """{"nested": null}""")
        result = RequestResult()
        result.set_exception(FailedRequestException(reason='error', code='code'))

        f2.set_result(
            {'a': result}
        )

        self.assertEqual(
            j.to_string(), """{"nested": {"a": {"error": {"reason": "error", "code": "code"}}}}"""
        )
开发者ID:damirazo,项目名称:frontik,代码行数:21,代码来源:test_json_builder.py

示例14: test_nested_json_builder

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_nested_json_builder(self):
        j1 = JsonBuilder()
        j1.put(k1='v1')

        j2 = JsonBuilder()
        j2.put(k2='v2')

        j1.put(j2)

        self.assertEqual(
            j1.to_string(), """{"k2": "v2", "k1": "v1"}"""
        )
开发者ID:damirazo,项目名称:frontik,代码行数:14,代码来源:test_json_builder.py

示例15: test_nested_json_builder

# 需要导入模块: from frontik.json_builder import JsonBuilder [as 别名]
# 或者: from frontik.json_builder.JsonBuilder import put [as 别名]
    def test_nested_json_builder(self):
        j1 = JsonBuilder()
        j1.put(k1='v1')

        j2 = JsonBuilder()
        j2.put(k2='v2')

        j1.put(j2)

        self.assertJsonEqual(
            j1.to_dict(), {'k2': 'v2', 'k1': 'v1'}
        )
开发者ID:bokshitsky,项目名称:hh_git_2__no_testing_-NOT_FOR_USAGE-,代码行数:14,代码来源:test_json_builder.py


注:本文中的frontik.json_builder.JsonBuilder.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。