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
821fcb2d
Commit
821fcb2d
authored
Aug 12, 2015
by
Tamir Duberstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use assertIsInstance
parent
09831c87
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
17 deletions
+13
-17
message_test.py
python/google/protobuf/internal/message_test.py
+8
-11
reflection_test.py
python/google/protobuf/internal/reflection_test.py
+3
-3
service_reflection_test.py
python/google/protobuf/internal/service_reflection_test.py
+2
-3
No files found.
python/google/protobuf/internal/message_test.py
View file @
821fcb2d
...
...
@@ -683,9 +683,7 @@ class MessageTest(unittest.TestCase):
in the value being converted to a Unicode string."""
m
=
message_module
.
TestAllTypes
()
m
.
optional_string
=
str
(
''
)
self
.
assertTrue
(
isinstance
(
m
.
optional_string
,
six
.
text_type
))
# TODO(haberman): why are these tests Google-internal only?
self
.
assertIsInstance
(
m
.
optional_string
,
six
.
text_type
)
def
testLongValuedSlice
(
self
,
message_module
):
"""It should be possible to use long-valued indicies in slices
...
...
@@ -1071,14 +1069,13 @@ class Proto2Test(unittest.TestCase):
repeated_nested_enum
=
[
'FOO'
,
unittest_pb2
.
TestAllTypes
.
BAR
],
default_int32
=
800
,
oneof_string
=
'y'
)
self
.
assert
True
(
isinstance
(
message
,
unittest_pb2
.
TestAllTypes
)
)
self
.
assert
IsInstance
(
message
,
unittest_pb2
.
TestAllTypes
)
self
.
assertEqual
(
100
,
message
.
optional_int32
)
self
.
assertEqual
(
200
,
message
.
optional_fixed32
)
self
.
assertEqual
(
300.5
,
message
.
optional_float
)
self
.
assertEqual
(
b
'x'
,
message
.
optional_bytes
)
self
.
assertEqual
(
400
,
message
.
optionalgroup
.
a
)
self
.
assertTrue
(
isinstance
(
message
.
optional_nested_message
,
unittest_pb2
.
TestAllTypes
.
NestedMessage
))
self
.
assertIsInstance
(
message
.
optional_nested_message
,
unittest_pb2
.
TestAllTypes
.
NestedMessage
)
self
.
assertEqual
(
500
,
message
.
optional_nested_message
.
bb
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
BAZ
,
message
.
optional_nested_enum
)
...
...
@@ -1236,7 +1233,7 @@ class Proto3Test(unittest.TestCase):
self
.
assertTrue
(
'abc'
in
msg
.
map_string_string
)
self
.
assertTrue
(
888
in
msg
.
map_int32_enum
)
self
.
assert
True
(
isinstance
(
msg
.
map_string_string
[
'abc'
],
six
.
text_type
)
)
self
.
assert
IsInstance
(
msg
.
map_string_string
[
'abc'
],
six
.
text_type
)
# Accessing an unset key still throws TypeError of the type of the key
# is incorrect.
...
...
@@ -1315,7 +1312,7 @@ class Proto3Test(unittest.TestCase):
msg
=
map_unittest_pb2
.
TestMap
()
unicode_obj
=
u'
\u1234
'
bytes_obj
=
unicode_obj
.
encode
(
'utf8'
)
bytes_obj
=
unicode_obj
.
encode
(
'utf8'
)
msg
.
map_string_string
[
bytes_obj
]
=
bytes_obj
...
...
@@ -1324,8 +1321,8 @@ class Proto3Test(unittest.TestCase):
self
.
assertEqual
(
key
,
unicode_obj
)
self
.
assertEqual
(
value
,
unicode_obj
)
self
.
assert
True
(
isinstance
(
key
,
six
.
text_type
)
)
self
.
assert
True
(
isinstance
(
value
,
six
.
text_type
)
)
self
.
assert
IsInstance
(
key
,
six
.
text_type
)
self
.
assert
IsInstance
(
value
,
six
.
text_type
)
def
testMessageMap
(
self
):
msg
=
map_unittest_pb2
.
TestMap
()
...
...
@@ -1493,7 +1490,7 @@ class Proto3Test(unittest.TestCase):
submsg
=
msg
.
map_int32_foreign_message
[
111
]
self
.
assertIs
(
submsg
,
msg
.
map_int32_foreign_message
[
111
])
self
.
assert
True
(
isinstance
(
submsg
,
unittest_pb2
.
ForeignMessage
)
)
self
.
assert
IsInstance
(
submsg
,
unittest_pb2
.
ForeignMessage
)
submsg
.
c
=
5
...
...
python/google/protobuf/internal/reflection_test.py
View file @
821fcb2d
...
...
@@ -614,10 +614,10 @@ class ReflectionTest(unittest.TestCase):
def
TestGetAndDeserialize
(
field_name
,
value
,
expected_type
):
proto
=
unittest_pb2
.
TestAllTypes
()
setattr
(
proto
,
field_name
,
value
)
self
.
assert
True
(
isinstance
(
getattr
(
proto
,
field_name
),
expected_type
)
)
self
.
assert
IsInstance
(
getattr
(
proto
,
field_name
),
expected_type
)
proto2
=
unittest_pb2
.
TestAllTypes
()
proto2
.
ParseFromString
(
proto
.
SerializeToString
())
self
.
assert
True
(
isinstance
(
getattr
(
proto2
,
field_name
),
expected_type
)
)
self
.
assert
IsInstance
(
getattr
(
proto2
,
field_name
),
expected_type
)
TestGetAndDeserialize
(
'optional_int32'
,
1
,
int
)
TestGetAndDeserialize
(
'optional_int32'
,
1
<<
30
,
int
)
...
...
@@ -903,7 +903,7 @@ class ReflectionTest(unittest.TestCase):
self
.
assertTrue
(
proto
.
repeated_nested_message
)
self
.
assertEqual
(
2
,
len
(
proto
.
repeated_nested_message
))
self
.
assertListsEqual
([
m0
,
m1
],
proto
.
repeated_nested_message
)
self
.
assert
True
(
isinstance
(
m0
,
unittest_pb2
.
TestAllTypes
.
NestedMessage
)
)
self
.
assert
IsInstance
(
m0
,
unittest_pb2
.
TestAllTypes
.
NestedMessage
)
# Test out-of-bounds indices.
self
.
assertRaises
(
IndexError
,
proto
.
repeated_nested_message
.
__getitem__
,
...
...
python/google/protobuf/internal/service_reflection_test.py
View file @
821fcb2d
...
...
@@ -83,7 +83,7 @@ class FooUnitTest(unittest.TestCase):
self
.
assertEqual
(
'Method Bar not implemented.'
,
rpc_controller
.
failure_message
)
self
.
assertEqual
(
None
,
self
.
callback_response
)
class
MyServiceImpl
(
unittest_pb2
.
TestService
):
def
Foo
(
self
,
rpc_controller
,
request
,
done
):
self
.
foo_called
=
True
...
...
@@ -128,8 +128,7 @@ class FooUnitTest(unittest.TestCase):
# Invoke method.
stub
.
Foo
(
rpc_controller
,
request
,
MyCallback
)
self
.
assertTrue
(
isinstance
(
self
.
callback_response
,
unittest_pb2
.
FooResponse
))
self
.
assertIsInstance
(
self
.
callback_response
,
unittest_pb2
.
FooResponse
)
self
.
assertEqual
(
request
,
channel
.
request
)
self
.
assertEqual
(
rpc_controller
,
channel
.
controller
)
self
.
assertEqual
(
stub
.
GetDescriptor
()
.
methods
[
0
],
channel
.
method
)
...
...
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