Python google.protobuf.text_format.MessageToString() Examples
The following are 30
code examples of google.protobuf.text_format.MessageToString().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.protobuf.text_format
, or try the search function
.
Example #1
Source File: build.py From recipes-py with Apache License 2.0 | 8 votes |
def RunSteps(api): text = text_format.MessageToString(api.buildbucket.build) api.step('build', ['echo'] + text.splitlines()) api.step('hostname', ['echo', api.buildbucket.host]) api.step('is_critical', ['echo', api.buildbucket.is_critical()]) child_build_tags = [ '%s:%s' % t for t in api.buildbucket.tags_for_child_build.iteritems() ] api.step('tags_for_child_build', ['echo'] + child_build_tags) api.assertions.assertEqual( api.buildbucket.bucket_v1, api.properties.get('expected_bucket_v1')) api.assertions.assertEqual( api.buildbucket.builder_name, api.buildbucket.build.builder.builder) api.assertions.assertEqual( api.buildbucket.gitiles_commit, api.buildbucket.build.input.gitiles_commit)
Example #2
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 7 votes |
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.).
Example #3
Source File: __init__.py From lambda-packs with MIT License | 6 votes |
def visualize_embeddings(summary_writer, config): """Stores a config file used by the embedding projector. Args: summary_writer: The summary writer used for writting events. config: `tf.contrib.tensorboard.plugins.projector.ProjectorConfig` proto that holds the configuration for the projector such as paths to checkpoint files and metadata files for the embeddings. If `config.model_checkpoint_path` is none, it defaults to the `logdir` used by the summary_writer. Raises: ValueError: If the summary writer does not have a `logdir`. """ logdir = summary_writer.get_logdir() # Sanity checks. if logdir is None: raise ValueError('Summary writer must have a logdir') # Saving the config file in the logdir. config_pbtxt = text_format.MessageToString(config) file_io.write_string_to_file( os.path.join(logdir, projector_plugin.PROJECTOR_FILENAME), config_pbtxt)
Example #4
Source File: text_format_test.py From lambda-packs with MIT License | 6 votes |
def testPrintExotic(self, message_module): message = message_module.TestAllTypes() message.repeated_int64.append(-9223372036854775808) message.repeated_uint64.append(18446744073709551615) message.repeated_double.append(123.456) 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\\\'"') message.repeated_string.append('\u00fc\ua71f') self.CompareToGoldenText( self.RemoveRedundantZeros(text_format.MessageToString(message)), 'repeated_int64: -9223372036854775808\n' 'repeated_uint64: 18446744073709551615\n' 'repeated_double: 123.456\n' 'repeated_double: 1.23e+22\n' 'repeated_double: 1.23e-18\n' 'repeated_string:' ' "\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""\n' 'repeated_string: "\\303\\274\\352\\234\\237"\n')
Example #5
Source File: config_util.py From vehicle_counting_tensorflow with MIT License | 6 votes |
def save_pipeline_config(pipeline_config, directory): """Saves a pipeline config text file to disk. Args: pipeline_config: A pipeline_pb2.TrainEvalPipelineConfig. directory: The model directory into which the pipeline config file will be saved. """ if not file_io.file_exists(directory): file_io.recursive_create_dir(directory) pipeline_config_path = os.path.join(directory, "pipeline.config") config_text = text_format.MessageToString(pipeline_config) with tf.gfile.Open(pipeline_config_path, "wb") as f: tf.logging.info("Writing pipeline config file to %s", pipeline_config_path) f.write(config_text)
Example #6
Source File: gftools-add-font.py From gftools with Apache License 2.0 | 6 votes |
def main(argv): if len(argv) != 2: sys.exit('One argument, a directory containing a font family') fontdir = argv[1] is_new = True old_metadata_file = os.path.join(fontdir, 'METADATA.pb') if os.path.isfile(old_metadata_file): is_new = False metadata = _MakeMetadata(fontdir, is_new) text_proto = text_format.MessageToString(metadata, as_utf8=True) desc = os.path.join(fontdir, 'DESCRIPTION.en_us.html') if os.path.isfile(desc): print('DESCRIPTION.en_us.html exists') else: _WriteTextFile(desc, 'N/A') _WriteTextFile(os.path.join(fontdir, 'METADATA.pb'), text_proto)
Example #7
Source File: __init__.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def visualize_embeddings(summary_writer, config): """Stores a config file used by the embedding projector. Args: summary_writer: The summary writer used for writting events. config: `tf.contrib.tensorboard.plugins.projector.ProjectorConfig` proto that holds the configuration for the projector such as paths to checkpoint files and metadata files for the embeddings. If `config.model_checkpoint_path` is none, it defaults to the `logdir` used by the summary_writer. Raises: ValueError: If the summary writer does not have a `logdir`. """ logdir = summary_writer.get_logdir() # Sanity checks. if logdir is None: raise ValueError('Summary writer must have a logdir') # Saving the config file in the logdir. config_pbtxt = text_format.MessageToString(config) file_io.write_string_to_file( os.path.join(logdir, PROJECTOR_FILENAME), config_pbtxt)
Example #8
Source File: text_format_test.py From lambda-packs with MIT License | 6 votes |
def testPrintExoticAsOneLine(self, message_module): message = message_module.TestAllTypes() message.repeated_int64.append(-9223372036854775808) message.repeated_uint64.append(18446744073709551615) message.repeated_double.append(123.456) 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\\\'"') message.repeated_string.append('\u00fc\ua71f') self.CompareToGoldenText( self.RemoveRedundantZeros(text_format.MessageToString( message, as_one_line=True)), 'repeated_int64: -9223372036854775808' ' repeated_uint64: 18446744073709551615' ' repeated_double: 123.456' ' repeated_double: 1.23e+22' ' repeated_double: 1.23e-18' ' repeated_string: ' '"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""' ' repeated_string: "\\303\\274\\352\\234\\237"')
Example #9
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testPrintMessageExpandAnyRepeated(self): packed_message = unittest_pb2.OneString() message = any_test_pb2.TestAny() packed_message.data = 'string0' message.repeated_any_value.add().Pack(packed_message) packed_message.data = 'string1' message.repeated_any_value.add().Pack(packed_message) self.assertEqual( text_format.MessageToString(message, descriptor_pool=descriptor_pool.Default()), 'repeated_any_value {\n' ' [type.googleapis.com/protobuf_unittest.OneString] {\n' ' data: "string0"\n' ' }\n' '}\n' 'repeated_any_value {\n' ' [type.googleapis.com/protobuf_unittest.OneString] {\n' ' data: "string1"\n' ' }\n' '}\n')
Example #10
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testPrintMessageSetAsOneLine(self): message = unittest_mset_pb2.TestMessageSetContainer() ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension message.message_set.Extensions[ext1].i = 23 message.message_set.Extensions[ext2].str = 'foo' self.CompareToGoldenText( text_format.MessageToString(message, as_one_line=True), 'message_set {' ' [protobuf_unittest.TestMessageSetExtension1] {' ' i: 23' ' }' ' [protobuf_unittest.TestMessageSetExtension2] {' ' str: \"foo\"' ' }' ' }')
Example #11
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testPrintMessageSet(self): message = unittest_mset_pb2.TestMessageSetContainer() ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension message.message_set.Extensions[ext1].i = 23 message.message_set.Extensions[ext2].str = 'foo' self.CompareToGoldenText( text_format.MessageToString(message), 'message_set {\n' ' [protobuf_unittest.TestMessageSetExtension1] {\n' ' i: 23\n' ' }\n' ' [protobuf_unittest.TestMessageSetExtension2] {\n' ' str: \"foo\"\n' ' }\n' '}\n') message = message_set_extensions_pb2.TestMessageSet() ext = message_set_extensions_pb2.message_set_extension3 message.Extensions[ext].text = 'bar' self.CompareToGoldenText( text_format.MessageToString(message), '[google.protobuf.internal.TestMessageSetExtension3] {\n' ' text: \"bar\"\n' '}\n')
Example #12
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testPrintInIndexOrder(self): message = unittest_pb2.TestFieldOrderings() message.my_string = '115' message.my_int = 101 message.my_float = 111 message.optional_nested_message.oo = 0 message.optional_nested_message.bb = 1 self.CompareToGoldenText( self.RemoveRedundantZeros(text_format.MessageToString( message, use_index_order=True)), 'my_string: \"115\"\nmy_int: 101\nmy_float: 111\n' 'optional_nested_message {\n oo: 0\n bb: 1\n}\n') self.CompareToGoldenText( self.RemoveRedundantZeros(text_format.MessageToString(message)), 'my_int: 101\nmy_string: \"115\"\nmy_float: 111\n' 'optional_nested_message {\n bb: 1\n oo: 0\n}\n')
Example #13
Source File: text_format_test.py From lambda-packs with MIT License | 6 votes |
def testPrintMessageSet(self): message = unittest_mset_pb2.TestMessageSetContainer() ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension message.message_set.Extensions[ext1].i = 23 message.message_set.Extensions[ext2].str = 'foo' self.CompareToGoldenText( text_format.MessageToString(message), 'message_set {\n' ' [protobuf_unittest.TestMessageSetExtension1] {\n' ' i: 23\n' ' }\n' ' [protobuf_unittest.TestMessageSetExtension2] {\n' ' str: \"foo\"\n' ' }\n' '}\n') message = message_set_extensions_pb2.TestMessageSet() ext = message_set_extensions_pb2.message_set_extension3 message.Extensions[ext].text = 'bar' self.CompareToGoldenText( text_format.MessageToString(message), '[google.protobuf.internal.TestMessageSetExtension3] {\n' ' text: \"bar\"\n' '}\n')
Example #14
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testPrintExotic(self, message_module): message = message_module.TestAllTypes() message.repeated_int64.append(-9223372036854775808) message.repeated_uint64.append(18446744073709551615) message.repeated_double.append(123.456) 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\\\'"') message.repeated_string.append(u'\u00fc\ua71f') self.CompareToGoldenText( self.RemoveRedundantZeros(text_format.MessageToString(message)), 'repeated_int64: -9223372036854775808\n' 'repeated_uint64: 18446744073709551615\n' 'repeated_double: 123.456\n' 'repeated_double: 1.23e+22\n' 'repeated_double: 1.23e-18\n' 'repeated_string:' ' "\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""\n' 'repeated_string: "\\303\\274\\352\\234\\237"\n')
Example #15
Source File: text_format_test.py From lambda-packs with MIT License | 6 votes |
def testPrettyPrintMultipleParts(self, message_module): def printer(m, indent, as_one_line): del indent, as_one_line if m.DESCRIPTOR == message_module.TestAllTypes.NestedMessage.DESCRIPTOR: return 'My lucky number is %s' % m.bb return None message = message_module.TestAllTypes() message.optional_int32 = 61 msg = message.repeated_nested_message.add() msg.bb = 42 msg = message.repeated_nested_message.add() msg.bb = 99 msg = message.optional_nested_message msg.bb = 1 self.CompareToGoldenText( text_format.MessageToString( message, as_one_line=True, message_formatter=printer), ('optional_int32: 61 ' 'optional_nested_message { My lucky number is 1 } ' 'repeated_nested_message { My lucky number is 42 } ' 'repeated_nested_message { My lucky number is 99 }'))
Example #16
Source File: text_format_test.py From lambda-packs with MIT License | 6 votes |
def testPrettyPrintMultiLine(self, message_module): def printer(m, indent, as_one_line): if m.DESCRIPTOR == message_module.TestAllTypes.NestedMessage.DESCRIPTOR: line_deliminator = (' ' if as_one_line else '\n') + ' ' * indent return 'My lucky number is:%s%s' % (line_deliminator, m.bb) return None message = message_module.TestAllTypes() msg = message.repeated_nested_message.add() msg.bb = 42 self.CompareToGoldenText( text_format.MessageToString( message, as_one_line=True, message_formatter=printer), 'repeated_nested_message { My lucky number is: 42 }') self.CompareToGoldenText( text_format.MessageToString( message, as_one_line=False, message_formatter=printer), 'repeated_nested_message {\n My lucky number is:\n 42\n}\n')
Example #17
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testPrintExoticAsOneLine(self, message_module): message = message_module.TestAllTypes() message.repeated_int64.append(-9223372036854775808) message.repeated_uint64.append(18446744073709551615) message.repeated_double.append(123.456) 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\\\'"') message.repeated_string.append(u'\u00fc\ua71f') self.CompareToGoldenText( self.RemoveRedundantZeros(text_format.MessageToString( message, as_one_line=True)), 'repeated_int64: -9223372036854775808' ' repeated_uint64: 18446744073709551615' ' repeated_double: 123.456' ' repeated_double: 1.23e+22' ' repeated_double: 1.23e-18' ' repeated_string: ' '"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""' ' repeated_string: "\\303\\274\\352\\234\\237"')
Example #18
Source File: text_format_test.py From lambda-packs with MIT License | 6 votes |
def testPrintMessageExpandAnyRepeated(self): packed_message = unittest_pb2.OneString() message = any_test_pb2.TestAny() packed_message.data = 'string0' message.repeated_any_value.add().Pack(packed_message) packed_message.data = 'string1' message.repeated_any_value.add().Pack(packed_message) self.assertEqual( text_format.MessageToString(message), 'repeated_any_value {\n' ' [type.googleapis.com/protobuf_unittest.OneString] {\n' ' data: "string0"\n' ' }\n' '}\n' 'repeated_any_value {\n' ' [type.googleapis.com/protobuf_unittest.OneString] {\n' ' data: "string1"\n' ' }\n' '}\n')
Example #19
Source File: text_format_test.py From lambda-packs with MIT License | 6 votes |
def testPrintMessageSetAsOneLine(self): message = unittest_mset_pb2.TestMessageSetContainer() ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension message.message_set.Extensions[ext1].i = 23 message.message_set.Extensions[ext2].str = 'foo' self.CompareToGoldenText( text_format.MessageToString(message, as_one_line=True), 'message_set {' ' [protobuf_unittest.TestMessageSetExtension1] {' ' i: 23' ' }' ' [protobuf_unittest.TestMessageSetExtension2] {' ' str: \"foo\"' ' }' ' }')
Example #20
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testPrintFloatFormat(self, message_module): # Check that float_format argument is passed to sub-message formatting. message = message_module.NestedTestAllTypes() # We use 1.25 as it is a round number in binary. The proto 32-bit float # will not gain additional imprecise digits as a 64-bit Python float and # show up in its str. 32-bit 1.2 is noisy when extended to 64-bit: # >>> struct.unpack('f', struct.pack('f', 1.2))[0] # 1.2000000476837158 # >>> struct.unpack('f', struct.pack('f', 1.25))[0] # 1.25 message.payload.optional_float = 1.25 # Check rounding at 15 significant digits message.payload.optional_double = -.000003456789012345678 # Check no decimal point. message.payload.repeated_float.append(-5642) # Check no trailing zeros. message.payload.repeated_double.append(.000078900) formatted_fields = ['optional_float: 1.25', 'optional_double: -3.45678901234568e-6', 'repeated_float: -5642', 'repeated_double: 7.89e-5'] text_message = text_format.MessageToString(message, float_format='.15g') self.CompareToGoldenText( self.RemoveRedundantZeros(text_message), 'payload {{\n {0}\n {1}\n {2}\n {3}\n}}\n'.format( *formatted_fields)) # as_one_line=True is a separate code branch where float_format is passed. text_message = text_format.MessageToString(message, as_one_line=True, float_format='.15g') self.CompareToGoldenText( self.RemoveRedundantZeros(text_message), 'payload {{ {0} {1} {2} {3} }}'.format(*formatted_fields))
Example #21
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testPrintRawUtf8String(self, message_module): message = message_module.TestAllTypes() message.repeated_string.append(u'\u00fc\ua71f') text = text_format.MessageToString(message, as_utf8=True) self.CompareToGoldenText(text, 'repeated_string: "\303\274\352\234\237"\n') parsed_message = message_module.TestAllTypes() text_format.Parse(text, parsed_message) self.assertEqual(message, parsed_message, '\n%s != %s' % (message, parsed_message))
Example #22
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testRoundTripExoticAsOneLine(self, message_module): message = message_module.TestAllTypes() message.repeated_int64.append(-9223372036854775808) message.repeated_uint64.append(18446744073709551615) message.repeated_double.append(123.456) 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\\\'"') message.repeated_string.append(u'\u00fc\ua71f') # Test as_utf8 = False. wire_text = text_format.MessageToString(message, as_one_line=True, as_utf8=False) parsed_message = message_module.TestAllTypes() r = text_format.Parse(wire_text, parsed_message) self.assertIs(r, parsed_message) self.assertEqual(message, parsed_message) # Test as_utf8 = True. wire_text = text_format.MessageToString(message, as_one_line=True, as_utf8=True) parsed_message = message_module.TestAllTypes() r = text_format.Parse(wire_text, parsed_message) self.assertIs(r, parsed_message) self.assertEqual(message, parsed_message, '\n%s != %s' % (message, parsed_message))
Example #23
Source File: compare.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def assertProtoEqual(self, a, b, check_initialized=True, normalize_numbers=False, msg=None): """Fails with a useful error if a and b aren't equal. Comparison of repeated fields matches the semantics of unittest.TestCase.assertEqual(), ie order and extra duplicates fields matter. Args: self: googletest.TestCase a: proto2 PB instance, or text string representing one b: proto2 PB instance -- message.Message or subclass thereof check_initialized: boolean, whether to fail if either a or b isn't initialized normalize_numbers: boolean, whether to normalize types and precision of numbers before comparison. msg: if specified, is used as the error message on failure """ if isinstance(a, six.string_types): a = text_format.Merge(a, b.__class__()) for pb in a, b: if check_initialized: errors = pb.FindInitializationErrors() if errors: self.fail('Initialization errors: %s\n%s' % (errors, pb)) if normalize_numbers: NormalizeNumberFields(pb) self.assertMultiLineEqual(text_format.MessageToString(a), text_format.MessageToString(b), msg=msg)
Example #24
Source File: strip_unused_lib.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def strip_unused_from_files(input_graph, input_binary, output_graph, output_binary, input_node_names, output_node_names, placeholder_type_enum): """Removes unused nodes from a graph file.""" if not gfile.Exists(input_graph): print("Input graph file '" + input_graph + "' does not exist!") return -1 if not output_node_names: print("You need to supply the name of a node to --output_node_names.") return -1 input_graph_def = graph_pb2.GraphDef() mode = "rb" if input_binary else "r" with gfile.FastGFile(input_graph, mode) as f: if input_binary: input_graph_def.ParseFromString(f.read()) else: text_format.Merge(f.read().decode("utf-8"), input_graph_def) output_graph_def = strip_unused(input_graph_def, input_node_names.split(","), output_node_names.split(","), placeholder_type_enum) if output_binary: with gfile.GFile(output_graph, "wb") as f: f.write(output_graph_def.SerializeToString()) else: with gfile.GFile(output_graph, "w") as f: f.write(text_format.MessageToString(output_graph_def)) print("%d ops in the final graph." % len(output_graph_def.node))
Example #25
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testPrintNestedNewLineInStringAsOneLine(self, message_module): message = message_module.TestAllTypes() message.optional_string = 'a\nnew\nline' self.CompareToGoldenText( text_format.MessageToString(message, as_one_line=True), 'optional_string: "a\\nnew\\nline"')
Example #26
Source File: proto_builder_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testOrderedFields(self): """Test that the field order is maintained when given an OrderedDict.""" proto_cls = proto_builder.MakeSimpleProtoClass( self.ordered_fields, full_name='net.proto2.python.public.proto_builder_test.OrderedTest') proto = proto_cls() proto.foo = 12345 proto.bar = 'asdf' self.assertMultiLineEqual( 'foo: 12345\nbar: "asdf"\n', text_format.MessageToString(proto))
Example #27
Source File: exporter.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 5 votes |
def export_inference_graph(input_type, pipeline_config, trained_checkpoint_prefix, output_directory, input_shape=None, output_collection_name='inference_op', additional_output_tensor_names=None): """Exports inference graph for the model specified in the pipeline config. Args: input_type: Type of input for the graph. Can be one of [`image_tensor`, `tf_example`]. pipeline_config: pipeline_pb2.TrainAndEvalPipelineConfig proto. trained_checkpoint_prefix: Path to the trained checkpoint file. output_directory: Path to write outputs. input_shape: Sets a fixed shape for an `image_tensor` input. If not specified, will default to [None, None, None, 3]. output_collection_name: Name of collection to add output tensors to. If None, does not add output tensors to a collection. additional_output_tensor_names: list of additional output tensors to include in the frozen graph. """ detection_model = model_builder.build(pipeline_config.model, is_training=False) _export_inference_graph(input_type, detection_model, pipeline_config.eval_config.use_moving_averages, trained_checkpoint_prefix, output_directory, additional_output_tensor_names, input_shape, output_collection_name, graph_hook_fn=None) pipeline_config.eval_config.use_moving_averages = False config_text = text_format.MessageToString(pipeline_config) with tf.gfile.Open( os.path.join(output_directory, 'pipeline.config'), 'wb') as f: f.write(config_text)
Example #28
Source File: proto_builder_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testMakeSimpleProtoClass(self): """Test that we can create a proto class.""" proto_cls = proto_builder.MakeSimpleProtoClass( self._fields, full_name='net.proto2.python.public.proto_builder_test.Test') proto = proto_cls() proto.foo = 12345 proto.bar = 'asdf' self.assertMultiLineEqual( 'bar: "asdf"\nfoo: 12345\n', text_format.MessageToString(proto))
Example #29
Source File: python_message.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _AddUnicodeMethod(unused_message_descriptor, cls): """Helper for _AddMessageMethods().""" def __unicode__(self): return text_format.MessageToString(self, as_utf8=True).decode('utf-8') cls.__unicode__ = __unicode__
Example #30
Source File: text_format_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testPrintExoticUnicodeSubclass(self, message_module): class UnicodeSub(six.text_type): pass message = message_module.TestAllTypes() message.repeated_string.append(UnicodeSub(u'\u00fc\ua71f')) self.CompareToGoldenText( text_format.MessageToString(message), 'repeated_string: "\\303\\274\\352\\234\\237"\n')