當前位置: 首頁>>代碼示例>>Python>>正文


Python json_builder.JsonBuilder類代碼示例

本文整理匯總了Python中frontik.json_builder.JsonBuilder的典型用法代碼示例。如果您正苦於以下問題:Python JsonBuilder類的具體用法?Python JsonBuilder怎麽用?Python JsonBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了JsonBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_failed_future

    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,代碼行數:9,代碼來源:test_json_builder.py

示例2: test_failed_future

    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,代碼行數:9,代碼來源:test_json_builder.py

示例3: test_failed_future

    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-,代碼行數:9,代碼來源:test_json_builder.py

示例4: test_future_string_value

    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,代碼行數:10,代碼來源:test_json_builder.py

示例5: test_simple

    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-,代碼行數:13,代碼來源:test_json_builder.py

示例6: test_multiple_items

    def test_multiple_items(self):
        j = JsonBuilder()
        j.put({'a': 'b'})
        j.put({'c': 'd'})

        self.assertJsonEqual(j.to_dict(), {'a': 'b', 'c': 'd'})

        j.put({'a': 'x'}, {'e': 'f'})

        self.assertJsonEqual(j.to_dict(), {'a': 'x', 'c': 'd', 'e': 'f'})

        j.put(e='x')

        self.assertJsonEqual(j.to_dict(), {'a': 'x', 'c': 'd', 'e': 'x'})
開發者ID:bokshitsky,項目名稱:hh_git_2__no_testing_-NOT_FOR_USAGE-,代碼行數:14,代碼來源:test_json_builder.py

示例7: test_multiple_items

    def test_multiple_items(self):
        j = JsonBuilder()
        j.put({'a': 'b'})
        j.put({'c': 'd'})

        self.assertEqual(j.to_string(), """{"a": "b", "c": "d"}""")

        j.put({'a': 'x'}, {'e': 'f'})

        self.assertEqual(j.to_string(), """{"a": "x", "c": "d", "e": "f"}""")

        j.put(e='x')

        self.assertEqual(j.to_string(), """{"a": "x", "c": "d", "e": "x"}""")
開發者ID:damirazo,項目名稱:frontik,代碼行數:14,代碼來源:test_json_builder.py

示例8: test_nested_future

    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-,代碼行數:15,代碼來源:test_json_builder.py

示例9: test_serializable

    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-,代碼行數:15,代碼來源:test_json_builder.py

示例10: test_nested_json_builder

    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-,代碼行數:12,代碼來源:test_json_builder.py

示例11: test_nested_json_builder

    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,代碼行數:12,代碼來源:test_json_builder.py

示例12: test_clear

    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-,代碼行數:7,代碼來源:test_json_builder.py

示例13: test_encoder

    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-,代碼行數:18,代碼來源:test_json_builder.py

示例14: test_nested_future_error_node

    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,代碼行數:19,代碼來源:test_json_builder.py

示例15: test_nested_future_error_node

    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-,代碼行數:19,代碼來源:test_json_builder.py


注:本文中的frontik.json_builder.JsonBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。