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
a2abc947
Commit
a2abc947
authored
Jan 13, 2015
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Straddle Python 2.6, 2.7, 3.3, 3.4.
parent
3d5460dd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
73 additions
and
73 deletions
+73
-73
descriptor_database_test.py
python/google/protobuf/internal/descriptor_database_test.py
+6
-6
descriptor_pool_test.py
python/google/protobuf/internal/descriptor_pool_test.py
+0
-0
descriptor_test.py
python/google/protobuf/internal/descriptor_test.py
+1
-1
generator_test.py
python/google/protobuf/internal/generator_test.py
+8
-8
message_factory_test.py
python/google/protobuf/internal/message_factory_test.py
+4
-4
message_test.py
python/google/protobuf/internal/message_test.py
+9
-9
reflection_test.py
python/google/protobuf/internal/reflection_test.py
+21
-21
symbol_database_test.py
python/google/protobuf/internal/symbol_database_test.py
+11
-11
text_encoding_test.py
python/google/protobuf/internal/text_encoding_test.py
+4
-4
text_format_test.py
python/google/protobuf/internal/text_format_test.py
+9
-9
No files found.
python/google/protobuf/internal/descriptor_database_test.py
View file @
a2abc947
...
...
@@ -49,17 +49,17 @@ class DescriptorDatabaseTest(unittest.TestCase):
factory_test2_pb2
.
DESCRIPTOR
.
serialized_pb
)
db
.
Add
(
file_desc_proto
)
self
.
assertEqual
s
(
file_desc_proto
,
db
.
FindFileByName
(
self
.
assertEqual
(
file_desc_proto
,
db
.
FindFileByName
(
'google/protobuf/internal/factory_test2.proto'
))
self
.
assertEqual
s
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
self
.
assertEqual
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
'google.protobuf.python.internal.Factory2Message'
))
self
.
assertEqual
s
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
self
.
assertEqual
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
'google.protobuf.python.internal.Factory2Message.NestedFactory2Message'
))
self
.
assertEqual
s
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
self
.
assertEqual
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
'google.protobuf.python.internal.Factory2Enum'
))
self
.
assertEqual
s
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
self
.
assertEqual
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
'google.protobuf.python.internal.Factory2Message.NestedFactory2Enum'
))
self
.
assertEqual
s
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
self
.
assertEqual
(
file_desc_proto
,
db
.
FindFileContainingSymbol
(
'google.protobuf.python.internal.MessageWithNestedEnumOnly.NestedEnum'
))
if
__name__
==
'__main__'
:
...
...
python/google/protobuf/internal/descriptor_pool_test.py
View file @
a2abc947
This diff is collapsed.
Click to expand it.
python/google/protobuf/internal/descriptor_test.py
View file @
a2abc947
...
...
@@ -673,7 +673,7 @@ class MakeDescriptorTest(unittest.TestCase):
reformed_descriptor
=
descriptor
.
MakeDescriptor
(
descriptor_proto
)
options
=
reformed_descriptor
.
GetOptions
()
self
.
assertEqual
s
(
101
,
self
.
assertEqual
(
101
,
options
.
Extensions
[
unittest_custom_options_pb2
.
msgopt
]
.
i
)
if
__name__
==
'__main__'
:
...
...
python/google/protobuf/internal/generator_test.py
View file @
a2abc947
...
...
@@ -154,7 +154,7 @@ class GeneratorTest(unittest.TestCase):
# extension and for its value to be set to -789.
def
testNestedTypes
(
self
):
self
.
assertEqual
s
(
self
.
assertEqual
(
set
(
unittest_pb2
.
TestAllTypes
.
DESCRIPTOR
.
nested_types
),
set
([
unittest_pb2
.
TestAllTypes
.
NestedMessage
.
DESCRIPTOR
,
...
...
@@ -306,36 +306,36 @@ class SymbolDatabaseRegistrationTest(unittest.TestCase):
"""Checks that messages, enums and files are correctly registered."""
def
testGetSymbol
(
self
):
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
,
symbol_database
.
Default
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes'
))
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
NestedMessage
,
symbol_database
.
Default
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes.NestedMessage'
))
with
self
.
assertRaises
(
KeyError
):
symbol_database
.
Default
()
.
GetSymbol
(
'protobuf_unittest.NestedMessage'
)
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
OptionalGroup
,
symbol_database
.
Default
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes.OptionalGroup'
))
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
RepeatedGroup
,
symbol_database
.
Default
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes.RepeatedGroup'
))
def
testEnums
(
self
):
self
.
assertEqual
s
(
self
.
assertEqual
(
'protobuf_unittest.ForeignEnum'
,
symbol_database
.
Default
()
.
pool
.
FindEnumTypeByName
(
'protobuf_unittest.ForeignEnum'
)
.
full_name
)
self
.
assertEqual
s
(
self
.
assertEqual
(
'protobuf_unittest.TestAllTypes.NestedEnum'
,
symbol_database
.
Default
()
.
pool
.
FindEnumTypeByName
(
'protobuf_unittest.TestAllTypes.NestedEnum'
)
.
full_name
)
def
testFindFileByName
(
self
):
self
.
assertEqual
s
(
self
.
assertEqual
(
'google/protobuf/unittest.proto'
,
symbol_database
.
Default
()
.
pool
.
FindFileByName
(
'google/protobuf/unittest.proto'
)
.
name
)
...
...
python/google/protobuf/internal/message_factory_test.py
View file @
a2abc947
...
...
@@ -82,9 +82,9 @@ class MessageFactoryTest(unittest.TestCase):
serialized
=
msg
.
SerializeToString
()
converted
=
factory_test2_pb2
.
Factory2Message
.
FromString
(
serialized
)
reserialized
=
converted
.
SerializeToString
()
self
.
assertEqual
s
(
serialized
,
reserialized
)
self
.
assertEqual
(
serialized
,
reserialized
)
result
=
cls
.
FromString
(
reserialized
)
self
.
assertEqual
s
(
msg
,
result
)
self
.
assertEqual
(
msg
,
result
)
def
testGetPrototype
(
self
):
db
=
descriptor_database
.
DescriptorDatabase
()
...
...
@@ -125,8 +125,8 @@ class MessageFactoryTest(unittest.TestCase):
'google.protobuf.python.internal.another_field'
]
msg1
.
Extensions
[
ext1
]
=
'test1'
msg1
.
Extensions
[
ext2
]
=
'test2'
self
.
assertEqual
s
(
'test1'
,
msg1
.
Extensions
[
ext1
])
self
.
assertEqual
s
(
'test2'
,
msg1
.
Extensions
[
ext2
])
self
.
assertEqual
(
'test1'
,
msg1
.
Extensions
[
ext1
])
self
.
assertEqual
(
'test2'
,
msg1
.
Extensions
[
ext2
])
if
__name__
==
'__main__'
:
...
...
python/google/protobuf/internal/message_test.py
View file @
a2abc947
...
...
@@ -98,7 +98,7 @@ class MessageTest(unittest.TestCase):
golden_message
.
ParseFromString
(
golden_data
)
all_set
=
unittest_pb2
.
TestAllExtensions
()
test_util
.
SetAllExtensions
(
all_set
)
self
.
assertEqual
s
(
all_set
,
golden_message
)
self
.
assertEqual
(
all_set
,
golden_message
)
self
.
assertEqual
(
golden_data
,
golden_message
.
SerializeToString
())
golden_copy
=
copy
.
deepcopy
(
golden_message
)
self
.
assertEqual
(
golden_data
,
golden_copy
.
SerializeToString
())
...
...
@@ -109,7 +109,7 @@ class MessageTest(unittest.TestCase):
golden_message
.
ParseFromString
(
golden_data
)
all_set
=
unittest_pb2
.
TestPackedTypes
()
test_util
.
SetAllPackedFields
(
all_set
)
self
.
assertEqual
s
(
all_set
,
golden_message
)
self
.
assertEqual
(
all_set
,
golden_message
)
self
.
assertEqual
(
golden_data
,
all_set
.
SerializeToString
())
golden_copy
=
copy
.
deepcopy
(
golden_message
)
self
.
assertEqual
(
golden_data
,
golden_copy
.
SerializeToString
())
...
...
@@ -120,7 +120,7 @@ class MessageTest(unittest.TestCase):
golden_message
.
ParseFromString
(
golden_data
)
all_set
=
unittest_pb2
.
TestPackedExtensions
()
test_util
.
SetAllPackedExtensions
(
all_set
)
self
.
assertEqual
s
(
all_set
,
golden_message
)
self
.
assertEqual
(
all_set
,
golden_message
)
self
.
assertEqual
(
golden_data
,
all_set
.
SerializeToString
())
golden_copy
=
copy
.
deepcopy
(
golden_message
)
self
.
assertEqual
(
golden_data
,
golden_copy
.
SerializeToString
())
...
...
@@ -132,7 +132,7 @@ class MessageTest(unittest.TestCase):
pickled_message
=
pickle
.
dumps
(
golden_message
)
unpickled_message
=
pickle
.
loads
(
pickled_message
)
self
.
assertEqual
s
(
unpickled_message
,
golden_message
)
self
.
assertEqual
(
unpickled_message
,
golden_message
)
def
testPickleIncompleteProto
(
self
):
...
...
@@ -140,8 +140,8 @@ class MessageTest(unittest.TestCase):
pickled_message
=
pickle
.
dumps
(
golden_message
)
unpickled_message
=
pickle
.
loads
(
pickled_message
)
self
.
assertEqual
s
(
unpickled_message
,
golden_message
)
self
.
assertEqual
s
(
unpickled_message
.
a
,
1
)
self
.
assertEqual
(
unpickled_message
,
golden_message
)
self
.
assertEqual
(
unpickled_message
.
a
,
1
)
# This is still an incomplete proto - so serializing should fail
self
.
assertRaises
(
message
.
EncodeError
,
unpickled_message
.
SerializeToString
)
...
...
@@ -344,11 +344,11 @@ class MessageTest(unittest.TestCase):
msg
.
repeated_nested_message
.
add
(
bb
=
3
)
msg
.
repeated_nested_message
.
add
(
bb
=
4
)
self
.
assertEqual
s
([
1
,
2
,
3
,
4
],
self
.
assertEqual
([
1
,
2
,
3
,
4
],
[
m
.
bb
for
m
in
msg
.
repeated_nested_message
])
self
.
assertEqual
s
([
4
,
3
,
2
,
1
],
self
.
assertEqual
([
4
,
3
,
2
,
1
],
[
m
.
bb
for
m
in
reversed
(
msg
.
repeated_nested_message
)])
self
.
assertEqual
s
([
4
,
3
,
2
,
1
],
self
.
assertEqual
([
4
,
3
,
2
,
1
],
[
m
.
bb
for
m
in
msg
.
repeated_nested_message
[::
-
1
]])
def
testSortingRepeatedScalarFieldsDefaultComparator
(
self
):
...
...
python/google/protobuf/internal/reflection_test.py
View file @
a2abc947
...
...
@@ -141,10 +141,10 @@ class ReflectionTest(unittest.TestCase):
repeated_bool
=
[
True
,
False
,
False
],
repeated_string
=
[
"optional_string"
])
self
.
assertEqual
s
([
1
,
2
,
3
,
4
],
list
(
proto
.
repeated_int32
))
self
.
assertEqual
s
([
1.23
,
54.321
],
list
(
proto
.
repeated_double
))
self
.
assertEqual
s
([
True
,
False
,
False
],
list
(
proto
.
repeated_bool
))
self
.
assertEqual
s
([
"optional_string"
],
list
(
proto
.
repeated_string
))
self
.
assertEqual
([
1
,
2
,
3
,
4
],
list
(
proto
.
repeated_int32
))
self
.
assertEqual
([
1.23
,
54.321
],
list
(
proto
.
repeated_double
))
self
.
assertEqual
([
True
,
False
,
False
],
list
(
proto
.
repeated_bool
))
self
.
assertEqual
([
"optional_string"
],
list
(
proto
.
repeated_string
))
def
testRepeatedCompositeConstructor
(
self
):
# Constructor with only repeated composite types should succeed.
...
...
@@ -163,18 +163,18 @@ class ReflectionTest(unittest.TestCase):
unittest_pb2
.
TestAllTypes
.
RepeatedGroup
(
a
=
1
),
unittest_pb2
.
TestAllTypes
.
RepeatedGroup
(
a
=
2
)])
self
.
assertEqual
s
(
self
.
assertEqual
(
[
unittest_pb2
.
TestAllTypes
.
NestedMessage
(
bb
=
unittest_pb2
.
TestAllTypes
.
FOO
),
unittest_pb2
.
TestAllTypes
.
NestedMessage
(
bb
=
unittest_pb2
.
TestAllTypes
.
BAR
)],
list
(
proto
.
repeated_nested_message
))
self
.
assertEqual
s
(
self
.
assertEqual
(
[
unittest_pb2
.
ForeignMessage
(
c
=-
43
),
unittest_pb2
.
ForeignMessage
(
c
=
45324
),
unittest_pb2
.
ForeignMessage
(
c
=
12
)],
list
(
proto
.
repeated_foreign_message
))
self
.
assertEqual
s
(
self
.
assertEqual
(
[
unittest_pb2
.
TestAllTypes
.
RepeatedGroup
(),
unittest_pb2
.
TestAllTypes
.
RepeatedGroup
(
a
=
1
),
unittest_pb2
.
TestAllTypes
.
RepeatedGroup
(
a
=
2
)],
...
...
@@ -199,15 +199,15 @@ class ReflectionTest(unittest.TestCase):
self
.
assertEqual
(
24
,
proto
.
optional_int32
)
self
.
assertEqual
(
'optional_string'
,
proto
.
optional_string
)
self
.
assertEqual
s
([
1.23
,
54.321
],
list
(
proto
.
repeated_double
))
self
.
assertEqual
s
([
True
,
False
,
False
],
list
(
proto
.
repeated_bool
))
self
.
assertEqual
s
(
self
.
assertEqual
([
1.23
,
54.321
],
list
(
proto
.
repeated_double
))
self
.
assertEqual
([
True
,
False
,
False
],
list
(
proto
.
repeated_bool
))
self
.
assertEqual
(
[
unittest_pb2
.
TestAllTypes
.
NestedMessage
(
bb
=
unittest_pb2
.
TestAllTypes
.
FOO
),
unittest_pb2
.
TestAllTypes
.
NestedMessage
(
bb
=
unittest_pb2
.
TestAllTypes
.
BAR
)],
list
(
proto
.
repeated_nested_message
))
self
.
assertEqual
s
(
self
.
assertEqual
(
[
unittest_pb2
.
ForeignMessage
(
c
=-
43
),
unittest_pb2
.
ForeignMessage
(
c
=
45324
),
unittest_pb2
.
ForeignMessage
(
c
=
12
)],
...
...
@@ -235,18 +235,18 @@ class ReflectionTest(unittest.TestCase):
def
testConstructorInvalidatesCachedByteSize
(
self
):
message
=
unittest_pb2
.
TestAllTypes
(
optional_int32
=
12
)
self
.
assertEqual
s
(
2
,
message
.
ByteSize
())
self
.
assertEqual
(
2
,
message
.
ByteSize
())
message
=
unittest_pb2
.
TestAllTypes
(
optional_nested_message
=
unittest_pb2
.
TestAllTypes
.
NestedMessage
())
self
.
assertEqual
s
(
3
,
message
.
ByteSize
())
self
.
assertEqual
(
3
,
message
.
ByteSize
())
message
=
unittest_pb2
.
TestAllTypes
(
repeated_int32
=
[
12
])
self
.
assertEqual
s
(
3
,
message
.
ByteSize
())
self
.
assertEqual
(
3
,
message
.
ByteSize
())
message
=
unittest_pb2
.
TestAllTypes
(
repeated_nested_message
=
[
unittest_pb2
.
TestAllTypes
.
NestedMessage
()])
self
.
assertEqual
s
(
3
,
message
.
ByteSize
())
self
.
assertEqual
(
3
,
message
.
ByteSize
())
def
testSimpleHasBits
(
self
):
# Test a scalar.
...
...
@@ -1188,7 +1188,7 @@ class ReflectionTest(unittest.TestCase):
self
.
assertTrue
(
1
in
unittest_pb2
.
TestAllExtensions
.
_extensions_by_number
)
# Make sure extensions haven't been registered into types that shouldn't
# have any.
self
.
assertEqual
s
(
0
,
len
(
unittest_pb2
.
TestAllTypes
.
_extensions_by_name
))
self
.
assertEqual
(
0
,
len
(
unittest_pb2
.
TestAllTypes
.
_extensions_by_name
))
# If message A directly contains message B, and
# a.HasField('b') is currently False, then mutating any
...
...
@@ -1512,18 +1512,18 @@ class ReflectionTest(unittest.TestCase):
test_util
.
SetAllNonLazyFields
(
proto
)
# Clear the message.
proto
.
Clear
()
self
.
assertEqual
s
(
proto
.
ByteSize
(),
0
)
self
.
assertEqual
(
proto
.
ByteSize
(),
0
)
empty_proto
=
unittest_pb2
.
TestAllTypes
()
self
.
assertEqual
s
(
proto
,
empty_proto
)
self
.
assertEqual
(
proto
,
empty_proto
)
# Test if extensions which were set are cleared.
proto
=
unittest_pb2
.
TestAllExtensions
()
test_util
.
SetAllExtensions
(
proto
)
# Clear the message.
proto
.
Clear
()
self
.
assertEqual
s
(
proto
.
ByteSize
(),
0
)
self
.
assertEqual
(
proto
.
ByteSize
(),
0
)
empty_proto
=
unittest_pb2
.
TestAllExtensions
()
self
.
assertEqual
s
(
proto
,
empty_proto
)
self
.
assertEqual
(
proto
,
empty_proto
)
def
testDisconnectingBeforeClear
(
self
):
proto
=
unittest_pb2
.
TestAllTypes
()
...
...
@@ -2481,7 +2481,7 @@ class SerializationTest(unittest.TestCase):
# Check that the message parsed well.
extension_message1
=
unittest_mset_pb2
.
TestMessageSetExtension1
extension1
=
extension_message1
.
message_set_extension
self
.
assertEqual
s
(
12345
,
proto
.
Extensions
[
extension1
]
.
i
)
self
.
assertEqual
(
12345
,
proto
.
Extensions
[
extension1
]
.
i
)
def
testUnknownFields
(
self
):
proto
=
unittest_pb2
.
TestAllTypes
()
...
...
python/google/protobuf/internal/symbol_database_test.py
View file @
a2abc947
...
...
@@ -65,53 +65,53 @@ class SymbolDatabaseTest(unittest.TestCase):
messages
[
'protobuf_unittest.TestAllTypes'
])
def
testGetSymbol
(
self
):
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
,
self
.
_Database
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes'
))
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
NestedMessage
,
self
.
_Database
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes.NestedMessage'
))
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
OptionalGroup
,
self
.
_Database
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes.OptionalGroup'
))
self
.
assertEqual
s
(
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
RepeatedGroup
,
self
.
_Database
()
.
GetSymbol
(
'protobuf_unittest.TestAllTypes.RepeatedGroup'
))
def
testEnums
(
self
):
# Check registration of types in the pool.
self
.
assertEqual
s
(
self
.
assertEqual
(
'protobuf_unittest.ForeignEnum'
,
self
.
_Database
()
.
pool
.
FindEnumTypeByName
(
'protobuf_unittest.ForeignEnum'
)
.
full_name
)
self
.
assertEqual
s
(
self
.
assertEqual
(
'protobuf_unittest.TestAllTypes.NestedEnum'
,
self
.
_Database
()
.
pool
.
FindEnumTypeByName
(
'protobuf_unittest.TestAllTypes.NestedEnum'
)
.
full_name
)
def
testFindMessageTypeByName
(
self
):
self
.
assertEqual
s
(
self
.
assertEqual
(
'protobuf_unittest.TestAllTypes'
,
self
.
_Database
()
.
pool
.
FindMessageTypeByName
(
'protobuf_unittest.TestAllTypes'
)
.
full_name
)
self
.
assertEqual
s
(
self
.
assertEqual
(
'protobuf_unittest.TestAllTypes.NestedMessage'
,
self
.
_Database
()
.
pool
.
FindMessageTypeByName
(
'protobuf_unittest.TestAllTypes.NestedMessage'
)
.
full_name
)
def
testFindFindContainingSymbol
(
self
):
# Lookup based on either enum or message.
self
.
assertEqual
s
(
self
.
assertEqual
(
'google/protobuf/unittest.proto'
,
self
.
_Database
()
.
pool
.
FindFileContainingSymbol
(
'protobuf_unittest.TestAllTypes.NestedEnum'
)
.
name
)
self
.
assertEqual
s
(
self
.
assertEqual
(
'google/protobuf/unittest.proto'
,
self
.
_Database
()
.
pool
.
FindFileContainingSymbol
(
'protobuf_unittest.TestAllTypes'
)
.
name
)
def
testFindFileByName
(
self
):
self
.
assertEqual
s
(
self
.
assertEqual
(
'google/protobuf/unittest.proto'
,
self
.
_Database
()
.
pool
.
FindFileByName
(
'google/protobuf/unittest.proto'
)
.
name
)
...
...
python/google/protobuf/internal/text_encoding_test.py
View file @
a2abc947
...
...
@@ -54,15 +54,15 @@ TEST_VALUES = [
class
TextEncodingTestCase
(
unittest
.
TestCase
):
def
testCEscape
(
self
):
for
escaped
,
escaped_utf8
,
unescaped
in
TEST_VALUES
:
self
.
assertEqual
s
(
escaped
,
self
.
assertEqual
(
escaped
,
text_encoding
.
CEscape
(
unescaped
,
as_utf8
=
False
))
self
.
assertEqual
s
(
escaped_utf8
,
self
.
assertEqual
(
escaped_utf8
,
text_encoding
.
CEscape
(
unescaped
,
as_utf8
=
True
))
def
testCUnescape
(
self
):
for
escaped
,
escaped_utf8
,
unescaped
in
TEST_VALUES
:
self
.
assertEqual
s
(
unescaped
,
text_encoding
.
CUnescape
(
escaped
))
self
.
assertEqual
s
(
unescaped
,
text_encoding
.
CUnescape
(
escaped_utf8
))
self
.
assertEqual
(
unescaped
,
text_encoding
.
CUnescape
(
escaped
))
self
.
assertEqual
(
unescaped
,
text_encoding
.
CUnescape
(
escaped_utf8
))
if
__name__
==
"__main__"
:
...
...
python/google/protobuf/internal/text_format_test.py
View file @
a2abc947
...
...
@@ -233,7 +233,7 @@ class TextFormatTest(unittest.TestCase):
parsed_message
=
unittest_pb2
.
TestAllTypes
()
r
=
text_format
.
Parse
(
wire_text
,
parsed_message
)
self
.
assertIs
(
r
,
parsed_message
)
self
.
assertEqual
s
(
message
,
parsed_message
)
self
.
assertEqual
(
message
,
parsed_message
)
# Test as_utf8 = True.
wire_text
=
text_format
.
MessageToString
(
...
...
@@ -241,7 +241,7 @@ class TextFormatTest(unittest.TestCase):
parsed_message
=
unittest_pb2
.
TestAllTypes
()
r
=
text_format
.
Parse
(
wire_text
,
parsed_message
)
self
.
assertIs
(
r
,
parsed_message
)
self
.
assertEqual
s
(
message
,
parsed_message
,
self
.
assertEqual
(
message
,
parsed_message
,
'
\n
%
s !=
%
s'
%
(
message
,
parsed_message
))
def
testPrintRawUtf8String
(
self
):
...
...
@@ -251,7 +251,7 @@ class TextFormatTest(unittest.TestCase):
self
.
CompareToGoldenText
(
text
,
'repeated_string: "
\303\274\352\234\237
"
\n
'
)
parsed_message
=
unittest_pb2
.
TestAllTypes
()
text_format
.
Parse
(
text
,
parsed_message
)
self
.
assertEqual
s
(
message
,
parsed_message
,
self
.
assertEqual
(
message
,
parsed_message
,
'
\n
%
s !=
%
s'
%
(
message
,
parsed_message
))
def
testPrintFloatFormat
(
self
):
...
...
@@ -309,7 +309,7 @@ class TextFormatTest(unittest.TestCase):
message
=
unittest_pb2
.
TestAllTypes
()
test_util
.
SetAllFields
(
message
)
self
.
assertEqual
s
(
message
,
parsed_message
)
self
.
assertEqual
(
message
,
parsed_message
)
def
testParseGoldenExtensions
(
self
):
golden_text
=
'
\n
'
.
join
(
self
.
ReadGolden
(
...
...
@@ -319,7 +319,7 @@ class TextFormatTest(unittest.TestCase):
message
=
unittest_pb2
.
TestAllExtensions
()
test_util
.
SetAllExtensions
(
message
)
self
.
assertEqual
s
(
message
,
parsed_message
)
self
.
assertEqual
(
message
,
parsed_message
)
def
testParseAllFields
(
self
):
message
=
unittest_pb2
.
TestAllTypes
()
...
...
@@ -360,8 +360,8 @@ class TextFormatTest(unittest.TestCase):
text_format
.
Parse
(
text
,
message
)
ext1
=
unittest_mset_pb2
.
TestMessageSetExtension1
.
message_set_extension
ext2
=
unittest_mset_pb2
.
TestMessageSetExtension2
.
message_set_extension
self
.
assertEqual
s
(
23
,
message
.
message_set
.
Extensions
[
ext1
]
.
i
)
self
.
assertEqual
s
(
'foo'
,
message
.
message_set
.
Extensions
[
ext2
]
.
str
)
self
.
assertEqual
(
23
,
message
.
message_set
.
Extensions
[
ext1
]
.
i
)
self
.
assertEqual
(
'foo'
,
message
.
message_set
.
Extensions
[
ext2
]
.
str
)
def
testParseExotic
(
self
):
message
=
unittest_pb2
.
TestAllTypes
()
...
...
@@ -408,7 +408,7 @@ class TextFormatTest(unittest.TestCase):
message
=
unittest_pb2
.
TestAllTypes
()
text
=
''
text_format
.
Parse
(
text
,
message
)
self
.
assertEqual
s
(
unittest_pb2
.
TestAllTypes
(),
message
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
(),
message
)
def
testParseInvalidUtf8
(
self
):
message
=
unittest_pb2
.
TestAllTypes
()
...
...
@@ -581,7 +581,7 @@ class TextFormatTest(unittest.TestCase):
message
=
unittest_pb2
.
TestAllTypes
()
test_util
.
SetAllFields
(
message
)
self
.
assertEqual
s
(
message
,
parsed_message
)
self
.
assertEqual
(
message
,
parsed_message
)
def
testMergeLinesGolden
(
self
):
opened
=
self
.
ReadGolden
(
'text_format_unittest_data.txt'
)
...
...
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