text_format_test.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:googleURLParser 作者: randomaccess3 项目源码 文件源码
def testMapOrderSemantics(self):
    golden_lines = self.ReadGolden('map_test_data.txt')
    # The C++ implementation emits defaulted-value fields, while the Python
    # implementation does not.  Adjusting for this is awkward, but it is
    # valuable to test against a common golden file.
    line_blacklist = ('  key: 0\n',
                      '  value: 0\n',
                      '  key: false\n',
                      '  value: false\n')
    golden_lines = [line for line in golden_lines if line not in line_blacklist]

    message = map_unittest_pb2.TestMap()
    text_format.ParseLines(golden_lines, message)
    candidate = text_format.MessageToString(message)
    # The Python implementation emits "1.0" for the double value that the C++
    # implementation emits as "1".
    candidate = candidate.replace('1.0', '1', 2)
    self.assertMultiLineEqual(candidate, ''.join(golden_lines))


# Tests of proto2-only features (MessageSet, extensions, etc.).
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号