aboutsummaryrefslogtreecommitdiffhomepage
path: root/python/google/protobuf/internal/text_format_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/google/protobuf/internal/text_format_test.py')
-rwxr-xr-xpython/google/protobuf/internal/text_format_test.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py
index c2074db5..c8fc79dc 100755
--- a/python/google/protobuf/internal/text_format_test.py
+++ b/python/google/protobuf/internal/text_format_test.py
@@ -45,14 +45,16 @@ class TextFormatTest(unittest.TestCase):
def testPrintAllFields(self):
message = unittest_pb2.TestAllTypes()
test_util.SetAllFields(message)
- self.CompareToGoldenFile(text_format.MessageToString(message),
- 'text_format_unittest_data.txt')
+ self.CompareToGoldenFile(
+ self.RemoveRedundantZeros(text_format.MessageToString(message)),
+ 'text_format_unittest_data.txt')
def testPrintAllExtensions(self):
message = unittest_pb2.TestAllExtensions()
test_util.SetAllExtensions(message)
- self.CompareToGoldenFile(text_format.MessageToString(message),
- 'text_format_unittest_extensions_data.txt')
+ self.CompareToGoldenFile(
+ self.RemoveRedundantZeros(text_format.MessageToString(message)),
+ 'text_format_unittest_extensions_data.txt')
def testPrintMessageSet(self):
message = unittest_mset_pb2.TestMessageSetContainer()
@@ -78,7 +80,8 @@ class TextFormatTest(unittest.TestCase):
message.repeated_double.append(1.23e22);
message.repeated_double.append(1.23e-18);
message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'\"');
- self.CompareToGoldenText(text_format.MessageToString(message),
+ self.CompareToGoldenText(
+ self.RemoveRedundantZeros(text_format.MessageToString(message)),
'repeated_int64: -9223372036854775808\n'
'repeated_uint64: 18446744073709551615\n'
'repeated_double: 123.456\n'
@@ -92,6 +95,12 @@ class TextFormatTest(unittest.TestCase):
message.c = 123
self.assertEqual('c: 123\n', str(message))
+ def RemoveRedundantZeros(self, text):
+ # Some platforms print 1e+5 as 1e+005. This is fine, but we need to remove
+ # these zeros in order to match the golden file.
+ return text.replace('e+0','e+').replace('e+0','e+') \
+ .replace('e-0','e-').replace('e-0','e-')
+
if __name__ == '__main__':
unittest.main()