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


Python wrappers_pb2.Int32Value方法代码示例

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


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

示例1: testInvalidAny

# 需要导入模块: from google.protobuf import wrappers_pb2 [as 别名]
# 或者: from google.protobuf.wrappers_pb2 import Int32Value [as 别名]
def testInvalidAny(self):
    message = any_pb2.Any()
    text = '{"@type": "type.googleapis.com/google.protobuf.Int32Value"}'
    self.assertRaisesRegex(
        KeyError,
        'value',
        json_format.Parse, text, message)
    text = '{"value": 1234}'
    self.assertRaisesRegex(
        json_format.ParseError,
        '@type is missing when parsing any message.',
        json_format.Parse, text, message)
    text = '{"@type": "type.googleapis.com/MessageNotExist", "value": 1234}'
    self.assertRaisesRegex(
        TypeError,
        'Can not find message descriptor by type_url: '
        'type.googleapis.com/MessageNotExist.',
        json_format.Parse, text, message)
    # Only last part is to be used: b/25630112
    text = (r'{"@type": "incorrect.googleapis.com/google.protobuf.Int32Value",'
            r'"value": 1234}')
    json_format.Parse(text, message) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:24,代码来源:json_format_test.py

示例2: testInvalidAny

# 需要导入模块: from google.protobuf import wrappers_pb2 [as 别名]
# 或者: from google.protobuf.wrappers_pb2 import Int32Value [as 别名]
def testInvalidAny(self):
    message = any_pb2.Any()
    text = '{"@type": "type.googleapis.com/google.protobuf.Int32Value"}'
    self.assertRaisesRegexp(
        KeyError,
        'value',
        json_format.Parse, text, message)
    text = '{"value": 1234}'
    self.assertRaisesRegexp(
        json_format.ParseError,
        '@type is missing when parsing any message.',
        json_format.Parse, text, message)
    text = '{"@type": "type.googleapis.com/MessageNotExist", "value": 1234}'
    self.assertRaisesRegexp(
        TypeError,
        'Can not find message descriptor by type_url: '
        'type.googleapis.com/MessageNotExist.',
        json_format.Parse, text, message)
    # Only last part is to be used: b/25630112
    text = (r'{"@type": "incorrect.googleapis.com/google.protobuf.Int32Value",'
            r'"value": 1234}')
    json_format.Parse(text, message) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:24,代码来源:json_format_test.py

示例3: test__to_protobuf_limit_only

# 需要导入模块: from google.protobuf import wrappers_pb2 [as 别名]
# 或者: from google.protobuf.wrappers_pb2 import Int32Value [as 别名]
def test__to_protobuf_limit_only(self):
        from google.protobuf import wrappers_pb2
        from google.cloud.firestore_v1.proto import query_pb2

        parent = mock.Mock(id="donut", spec=["id"])
        query1 = self._make_one(parent)
        limit = 31
        query2 = query1.limit(limit)

        structured_query_pb = query2._to_protobuf()
        query_kwargs = {
            "from": [
                query_pb2.StructuredQuery.CollectionSelector(collection_id=parent.id)
            ],
            "limit": wrappers_pb2.Int32Value(value=limit),
        }
        expected_pb = query_pb2.StructuredQuery(**query_kwargs)

        self.assertEqual(structured_query_pb, expected_pb) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:21,代码来源:test_query.py

示例4: test__to_protobuf_limit_only

# 需要导入模块: from google.protobuf import wrappers_pb2 [as 别名]
# 或者: from google.protobuf.wrappers_pb2 import Int32Value [as 别名]
def test__to_protobuf_limit_only(self):
        from google.protobuf import wrappers_pb2
        from google.cloud.firestore_v1beta1.proto import query_pb2

        parent = mock.Mock(id="donut", spec=["id"])
        query1 = self._make_one(parent)
        limit = 31
        query2 = query1.limit(limit)

        structured_query_pb = query2._to_protobuf()
        query_kwargs = {
            "from": [
                query_pb2.StructuredQuery.CollectionSelector(collection_id=parent.id)
            ],
            "limit": wrappers_pb2.Int32Value(value=limit),
        }
        expected_pb = query_pb2.StructuredQuery(**query_kwargs)

        self.assertEqual(structured_query_pb, expected_pb) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:21,代码来源:test_query.py

示例5: _to_protobuf

# 需要导入模块: from google.protobuf import wrappers_pb2 [as 别名]
# 或者: from google.protobuf.wrappers_pb2 import Int32Value [as 别名]
def _to_protobuf(self):
        """Convert the current query into the equivalent protobuf.

        Returns:
            :class:`google.cloud.firestore_v1.types.StructuredQuery`:
            The query protobuf.
        """
        projection = self._normalize_projection(self._projection)
        orders = self._normalize_orders()
        start_at = self._normalize_cursor(self._start_at, orders)
        end_at = self._normalize_cursor(self._end_at, orders)

        query_kwargs = {
            "select": projection,
            "from": [
                query_pb2.StructuredQuery.CollectionSelector(
                    collection_id=self._parent.id, all_descendants=self._all_descendants
                )
            ],
            "where": self._filters_pb(),
            "order_by": orders,
            "start_at": _cursor_pb(start_at),
            "end_at": _cursor_pb(end_at),
        }
        if self._offset is not None:
            query_kwargs["offset"] = self._offset
        if self._limit is not None:
            query_kwargs["limit"] = wrappers_pb2.Int32Value(value=self._limit)

        return query_pb2.StructuredQuery(**query_kwargs) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:32,代码来源:query.py

示例6: test__to_protobuf_all_fields

# 需要导入模块: from google.protobuf import wrappers_pb2 [as 别名]
# 或者: from google.protobuf.wrappers_pb2 import Int32Value [as 别名]
def test__to_protobuf_all_fields(self):
        from google.protobuf import wrappers_pb2
        from google.cloud.firestore_v1.gapic import enums
        from google.cloud.firestore_v1.proto import document_pb2
        from google.cloud.firestore_v1.proto import query_pb2

        parent = mock.Mock(id="cat", spec=["id"])
        query1 = self._make_one(parent)
        query2 = query1.select(["X", "Y", "Z"])
        query3 = query2.where("Y", ">", 2.5)
        query4 = query3.order_by("X")
        query5 = query4.limit(17)
        query6 = query5.offset(3)
        query7 = query6.start_at({"X": 10})
        query8 = query7.end_at({"X": 25})

        structured_query_pb = query8._to_protobuf()
        query_kwargs = {
            "from": [
                query_pb2.StructuredQuery.CollectionSelector(collection_id=parent.id)
            ],
            "select": query_pb2.StructuredQuery.Projection(
                fields=[
                    query_pb2.StructuredQuery.FieldReference(field_path=field_path)
                    for field_path in ["X", "Y", "Z"]
                ]
            ),
            "where": query_pb2.StructuredQuery.Filter(
                field_filter=query_pb2.StructuredQuery.FieldFilter(
                    field=query_pb2.StructuredQuery.FieldReference(field_path="Y"),
                    op=enums.StructuredQuery.FieldFilter.Operator.GREATER_THAN,
                    value=document_pb2.Value(double_value=2.5),
                )
            ),
            "order_by": [
                _make_order_pb("X", enums.StructuredQuery.Direction.ASCENDING)
            ],
            "start_at": query_pb2.Cursor(
                values=[document_pb2.Value(integer_value=10)], before=True
            ),
            "end_at": query_pb2.Cursor(values=[document_pb2.Value(integer_value=25)]),
            "offset": 3,
            "limit": wrappers_pb2.Int32Value(value=17),
        }
        expected_pb = query_pb2.StructuredQuery(**query_kwargs)
        self.assertEqual(structured_query_pb, expected_pb) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:48,代码来源:test_query.py

示例7: test__to_protobuf_all_fields

# 需要导入模块: from google.protobuf import wrappers_pb2 [as 别名]
# 或者: from google.protobuf.wrappers_pb2 import Int32Value [as 别名]
def test__to_protobuf_all_fields(self):
        from google.protobuf import wrappers_pb2
        from google.cloud.firestore_v1beta1.gapic import enums
        from google.cloud.firestore_v1beta1.proto import document_pb2
        from google.cloud.firestore_v1beta1.proto import query_pb2

        parent = mock.Mock(id="cat", spec=["id"])
        query1 = self._make_one(parent)
        query2 = query1.select(["X", "Y", "Z"])
        query3 = query2.where("Y", ">", 2.5)
        query4 = query3.order_by("X")
        query5 = query4.limit(17)
        query6 = query5.offset(3)
        query7 = query6.start_at({"X": 10})
        query8 = query7.end_at({"X": 25})

        structured_query_pb = query8._to_protobuf()
        query_kwargs = {
            "from": [
                query_pb2.StructuredQuery.CollectionSelector(collection_id=parent.id)
            ],
            "select": query_pb2.StructuredQuery.Projection(
                fields=[
                    query_pb2.StructuredQuery.FieldReference(field_path=field_path)
                    for field_path in ["X", "Y", "Z"]
                ]
            ),
            "where": query_pb2.StructuredQuery.Filter(
                field_filter=query_pb2.StructuredQuery.FieldFilter(
                    field=query_pb2.StructuredQuery.FieldReference(field_path="Y"),
                    op=enums.StructuredQuery.FieldFilter.Operator.GREATER_THAN,
                    value=document_pb2.Value(double_value=2.5),
                )
            ),
            "order_by": [
                _make_order_pb("X", enums.StructuredQuery.Direction.ASCENDING)
            ],
            "start_at": query_pb2.Cursor(
                values=[document_pb2.Value(integer_value=10)], before=True
            ),
            "end_at": query_pb2.Cursor(values=[document_pb2.Value(integer_value=25)]),
            "offset": 3,
            "limit": wrappers_pb2.Int32Value(value=17),
        }
        expected_pb = query_pb2.StructuredQuery(**query_kwargs)
        self.assertEqual(structured_query_pb, expected_pb) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:48,代码来源:test_query.py


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