Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
27028bcb
Commit
27028bcb
authored
Jul 27, 2010
by
kenton@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue 208.
parent
0c293def
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
reflection_test.py
python/google/protobuf/internal/reflection_test.py
+28
-2
reflection.py
python/google/protobuf/reflection.py
+5
-1
No files found.
python/google/protobuf/internal/reflection_test.py
View file @
27028bcb
...
...
@@ -200,6 +200,32 @@ class ReflectionTest(unittest.TestCase):
unittest_pb2
.
ForeignMessage
(
c
=
12
)],
list
(
proto
.
repeated_foreign_message
))
def
testConstructorTypeError
(
self
):
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
optional_int32
=
"foo"
)
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
optional_string
=
1234
)
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
optional_nested_message
=
1234
)
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
repeated_int32
=
1234
)
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
repeated_int32
=
[
"foo"
])
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
repeated_string
=
1234
)
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
repeated_string
=
[
1234
])
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
repeated_nested_message
=
1234
)
self
.
assertRaises
(
TypeError
,
unittest_pb2
.
TestAllTypes
,
repeated_nested_message
=
[
1234
])
def
testConstructorInvalidatesCachedByteSize
(
self
):
message
=
unittest_pb2
.
TestAllTypes
(
optional_int32
=
12
)
self
.
assertEquals
(
2
,
message
.
ByteSize
())
message
=
unittest_pb2
.
TestAllTypes
(
optional_nested_message
=
unittest_pb2
.
TestAllTypes
.
NestedMessage
())
self
.
assertEquals
(
3
,
message
.
ByteSize
())
message
=
unittest_pb2
.
TestAllTypes
(
repeated_int32
=
[
12
])
self
.
assertEquals
(
3
,
message
.
ByteSize
())
message
=
unittest_pb2
.
TestAllTypes
(
repeated_nested_message
=
[
unittest_pb2
.
TestAllTypes
.
NestedMessage
()])
self
.
assertEquals
(
3
,
message
.
ByteSize
())
def
testSimpleHasBits
(
self
):
# Test a scalar.
proto
=
unittest_pb2
.
TestAllTypes
()
...
...
@@ -1038,12 +1064,12 @@ class ReflectionTest(unittest.TestCase):
def
testMergeFromBug
(
self
):
message1
=
unittest_pb2
.
TestAllTypes
()
message2
=
unittest_pb2
.
TestAllTypes
()
# Cause optional_nested_message to be instantiated within message1, even
# though it is not considered to be "present".
message1
.
optional_nested_message
self
.
assertFalse
(
message1
.
HasField
(
'optional_nested_message'
))
# Merge into message2. This should not instantiate the field is message2.
message2
.
MergeFrom
(
message1
)
self
.
assertFalse
(
message2
.
HasField
(
'optional_nested_message'
))
...
...
python/google/protobuf/reflection.py
View file @
27028bcb
...
...
@@ -384,7 +384,7 @@ def _AddInitMethod(message_descriptor, cls):
copy
.
MergeFrom
(
field_value
)
self
.
_fields
[
field
]
=
copy
else
:
se
lf
.
_fields
[
field
]
=
field_value
se
tattr
(
self
,
field_name
,
field_value
)
init
.
__module__
=
None
init
.
__doc__
=
None
...
...
@@ -937,6 +937,10 @@ def _AddMergeFromMethod(cls):
CPPTYPE_MESSAGE
=
_FieldDescriptor
.
CPPTYPE_MESSAGE
def
MergeFrom
(
self
,
msg
):
if
not
isinstance
(
msg
,
cls
):
raise
TypeError
(
"Parameter to MergeFrom() must be instance of same class."
)
assert
msg
is
not
self
self
.
_Modified
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment