~verterok/ubuntu/lucid/protobuf/2.4.0a-backport

« back to all changes in this revision

Viewing changes to python/google/protobuf/internal/generator_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
__author__ = 'robinson@google.com (Will Robinson)'
43
43
 
44
44
import unittest
 
45
from google.protobuf import unittest_custom_options_pb2
45
46
from google.protobuf import unittest_import_pb2
46
47
from google.protobuf import unittest_mset_pb2
47
48
from google.protobuf import unittest_pb2
48
49
from google.protobuf import unittest_no_generic_services_pb2
49
 
 
 
50
from google.protobuf import service
50
51
 
51
52
MAX_EXTENSION = 536870912
52
53
 
99
100
    self.assertTrue(isinf(message.neg_inf_float))
100
101
    self.assertTrue(message.neg_inf_float < 0)
101
102
    self.assertTrue(isnan(message.nan_float))
 
103
    self.assertEqual("? ? ?? ?? ??? ??/ ??-", message.cpp_trigraph)
102
104
 
103
105
  def testHasDefaultValues(self):
104
106
    desc = unittest_pb2.TestAllTypes.DESCRIPTOR
140
142
    proto = unittest_mset_pb2.TestMessageSet()
141
143
    self.assertTrue(proto.DESCRIPTOR.GetOptions().message_set_wire_format)
142
144
 
 
145
  def testMessageWithCustomOptions(self):
 
146
    proto = unittest_custom_options_pb2.TestMessageWithCustomOptions()
 
147
    enum_options = proto.DESCRIPTOR.enum_types_by_name['AnEnum'].GetOptions()
 
148
    self.assertTrue(enum_options is not None)
 
149
    # TODO(gps): We really should test for the presense of the enum_opt1
 
150
    # extension and for its value to be set to -789.
 
151
 
143
152
  def testNestedTypes(self):
144
153
    self.assertEquals(
145
154
        set(unittest_pb2.TestAllTypes.DESCRIPTOR.nested_types),
208
217
    self.assertFalse(unittest_pb2.DESCRIPTOR.serialized_pb is None)
209
218
 
210
219
  def testNoGenericServices(self):
211
 
    # unittest_no_generic_services.proto should contain defs for everything
212
 
    # except services.
213
220
    self.assertTrue(hasattr(unittest_no_generic_services_pb2, "TestMessage"))
214
221
    self.assertTrue(hasattr(unittest_no_generic_services_pb2, "FOO"))
215
222
    self.assertTrue(hasattr(unittest_no_generic_services_pb2, "test_extension"))
216
 
    self.assertFalse(hasattr(unittest_no_generic_services_pb2, "TestService"))
 
223
 
 
224
    # Make sure unittest_no_generic_services_pb2 has no services subclassing
 
225
    # Proto2 Service class.
 
226
    if hasattr(unittest_no_generic_services_pb2, "TestService"):
 
227
      self.assertFalse(issubclass(unittest_no_generic_services_pb2.TestService,
 
228
                                  service.Service))
 
229
 
 
230
  def testMessageTypesByName(self):
 
231
    file_type = unittest_pb2.DESCRIPTOR
 
232
    self.assertEqual(
 
233
        unittest_pb2._TESTALLTYPES,
 
234
        file_type.message_types_by_name[unittest_pb2._TESTALLTYPES.name])
 
235
 
 
236
    # Nested messages shouldn't be included in the message_types_by_name
 
237
    # dictionary (like in the C++ API).
 
238
    self.assertFalse(
 
239
        unittest_pb2._TESTALLTYPES_NESTEDMESSAGE.name in
 
240
        file_type.message_types_by_name)
217
241
 
218
242
 
219
243
if __name__ == '__main__':