field_tag = encoder.TagBytes(field_descriptor.number, wire_type) result_dict = {} for tag_bytes, value in self.unknown_fields: if tag_bytes == field_tag: decoder = missing_enum_values_pb2.TestEnumValues._decoders_by_tag[ tag_bytes][0] decoder(value, 0, len(value), self.message, result_dict) return result_dict[field_descriptor] def testUnknownEnumValue(self): self.assertFalse(self.missing_message.HasField('optional_nested_enum')) value = self.GetField('optional_nested_enum') self.assertEqual(self.message.optional_nested_enum, value) def testUnknownRepeatedEnumValue(self): value = self.GetField('repeated_nested_enum') self.assertEqual(self.message.repeated_nested_enum, value) def testUnknownPackedEnumValue(self): value = self.GetField('packed_nested_enum') self.assertEqual(self.message.packed_nested_enum, value) def testRoundTrip(self): new_message = missing_enum_values_pb2.TestEnumValues() new_message.ParseFromString(self.missing_message.SerializeToString()) self.assertEqual(self.message, new_message) if __name__ == '__main__': basetest.main()
def main(_): googletest.main()
def main(unused_argv): basetest.main()
def main(_): googletest.main()
def main(_): basetest.main()
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Unittest for descriptor.py for the pure Python implementation.""" import os os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python' # We must set the implementation version above before the google3 imports. # pylint: disable=g-import-not-at-top from google.apputils import basetest from google.protobuf.internal import api_implementation # Run all tests from the original module by putting them in our namespace. # pylint: disable=wildcard-import from google.protobuf.internal.descriptor_test import * class ConfirmPurePythonTest(basetest.TestCase): def testImplementationSetting(self): self.assertEqual('python', api_implementation.Type()) if __name__ == '__main__': basetest.main()
def main(_): basetest.main()
def main(unused_argv): basetest.main()
self.assertEqual(1, len(result.additional_properties)) self.assertEqual(0, result.additional_properties[0].value.index) def testNestedFieldMapping(self): nested_msg = AdditionalPropertiesMessage() nested_msg.additional_properties = [ AdditionalPropertiesMessage.AdditionalProperty( key='key_one', value='value_one'), AdditionalPropertiesMessage.AdditionalProperty( key='key_two', value='value_two'), ] msg = HasNestedMessage(nested=nested_msg) encoded_msg = encoding.MessageToJson(msg) self.assertEqual( {'nested': {'key_one': 'value_one', 'key_two': 'value_two'}}, json.loads(encoded_msg)) new_msg = encoding.JsonToMessage(type(msg), encoded_msg) self.assertEqual( set(('key_one', 'key_two')), set([x.key for x in new_msg.nested.additional_properties])) new_msg.nested.additional_properties.pop() self.assertEqual(1, len(new_msg.nested.additional_properties)) self.assertEqual(2, len(msg.nested.additional_properties)) if __name__ == '__main__': googletest.main()
self.assertEquals(output.getvalue(), self._test_proto.SerializeToString()) def testInfo_text(self): with tempfile.NamedTemporaryFile() as proto_file: proto_file.write(self._test_proto.SerializeToString()) proto_file.flush() output = StringIO.StringIO() unified_launcher._PrintInfo(proto_file.name, 'text', out=output) self.assertTrue('skin: "800x900"' in output.getvalue(), output.getvalue()) def _CreateFile(path, payload=''): """Creates a file at path. Arguments: path: the path to create the file at. payload: [optional] the contents to store in the file. Returns: The path that was created. """ with open(path, 'wb') as f: f.write(payload) return path if __name__ == '__main__': googletest.main()