Skip to content

Commit

Permalink
[PYTHON] Drop dependency on 'google.apputils'.
Browse files Browse the repository at this point in the history
Use stdlib's 'unittest' instead.
  • Loading branch information
tamird committed Apr 10, 2015
1 parent dab96f1 commit 9f42f5f
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ script:
- ./autogen.sh && ./configure && make -j2
- cd java && mvn test && cd ..
- cd javanano && mvn test && cd ..
- cd python && python setup.py build && python setup.py google_test && cd ..
- cd python && python setup.py build && python setup.py test && cd ..
- export LD_LIBRARY_PATH=../src/.libs
- cd python && python setup.py build --cpp_implementation && python setup.py google_test --cpp_implementation && cd ..
- cd python && python setup.py build --cpp_implementation && python setup.py test --cpp_implementation && cd ..
- make distcheck -j2
notifications:
email: false
4 changes: 2 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Installation
4) Build and run the tests:

$ python setup.py build
$ python setup.py google_test
$ python setup.py test

To build, test, and use the C++ implementation, you must first compile
libprotobuf.so:
Expand Down Expand Up @@ -82,7 +82,7 @@ Installation
$ python setup.py build --cpp_implementation

Then run the tests like so:
$ python setup.py google_test --cpp_implementation
$ python setup.py test --cpp_implementation

If some tests fail, this library may not work correctly on your
system. Continue at your own risk.
Expand Down
4 changes: 1 addition & 3 deletions python/google/protobuf/internal/_parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ def testIsNegative(self, arg):
import unittest
import uuid

from google.apputils import basetest

ADDR_RE = re.compile(r'\<([a-zA-Z0-9_\-\.]+) object at 0x[a-fA-F0-9]+\>')
_SEPARATOR = uuid.uuid1().hex
_FIRST_ARG = object()
Expand Down Expand Up @@ -380,7 +378,7 @@ def _UpdateClassDictForParamTestCase(dct, id_suffix, name, iterator):
id_suffix[new_name] = getattr(func, '__x_extra_id__', '')


class ParameterizedTestCase(basetest.TestCase):
class ParameterizedTestCase(unittest.TestCase):
"""Base class for test cases using the Parameters decorator."""
__metaclass__ = TestGeneratorMetaclass

Expand Down
7 changes: 4 additions & 3 deletions python/google/protobuf/internal/descriptor_database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@

__author__ = '[email protected] (Matt Toia)'

from google.apputils import basetest
import unittest

from google.protobuf import descriptor_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf import descriptor_database


class DescriptorDatabaseTest(basetest.TestCase):
class DescriptorDatabaseTest(unittest.TestCase):

def testAdd(self):
db = descriptor_database.DescriptorDatabase()
Expand All @@ -62,4 +63,4 @@ def testAdd(self):
'google.protobuf.python.internal.MessageWithNestedEnumOnly.NestedEnum'))

if __name__ == '__main__':
basetest.main()
unittest.main()
7 changes: 3 additions & 4 deletions python/google/protobuf/internal/descriptor_pool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import os
import unittest

from google.apputils import basetest
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pb2
from google.protobuf.internal import api_implementation
Expand All @@ -51,7 +50,7 @@
from google.protobuf import symbol_database


class DescriptorPoolTest(basetest.TestCase):
class DescriptorPoolTest(unittest.TestCase):

def setUp(self):
self.pool = descriptor_pool.DescriptorPool()
Expand Down Expand Up @@ -426,7 +425,7 @@ def CheckField(self, test, msg_desc, name, index):
test.assertEqual(self.extended_type, field_desc.containing_type.name)


class AddDescriptorTest(basetest.TestCase):
class AddDescriptorTest(unittest.TestCase):

def _TestMessage(self, prefix):
pool = descriptor_pool.DescriptorPool()
Expand Down Expand Up @@ -588,4 +587,4 @@ def testFile(self):


if __name__ == '__main__':
basetest.main()
unittest.main()
14 changes: 7 additions & 7 deletions python/google/protobuf/internal/descriptor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
__author__ = '[email protected] (Will Robinson)'

import sys
import unittest

from google.apputils import basetest
from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_pb2
Expand All @@ -52,7 +52,7 @@
"""


class DescriptorTest(basetest.TestCase):
class DescriptorTest(unittest.TestCase):

def setUp(self):
file_proto = descriptor_pb2.FileDescriptorProto(
Expand Down Expand Up @@ -390,7 +390,7 @@ def testFileDescriptor(self):
self.assertEqual(self.my_file.name, 'some/filename/some.proto')
self.assertEqual(self.my_file.package, 'protobuf_unittest')

@basetest.unittest.skipIf(
@unittest.skipIf(
api_implementation.Type() != 'cpp' or api_implementation.Version() != 2,
'Immutability of descriptors is only enforced in v2 implementation')
def testImmutableCppDescriptor(self):
Expand All @@ -403,7 +403,7 @@ def testImmutableCppDescriptor(self):
message_descriptor.fields.append(None)


class GeneratedDescriptorTest(basetest.TestCase):
class GeneratedDescriptorTest(unittest.TestCase):
"""Tests for the properties of descriptors in generated code."""

def CheckMessageDescriptor(self, message_descriptor):
Expand Down Expand Up @@ -493,7 +493,7 @@ def testCppDescriptorContainer_Iterator(self):
self.assertEqual('FOO', next(values_iter).name)


class DescriptorCopyToProtoTest(basetest.TestCase):
class DescriptorCopyToProtoTest(unittest.TestCase):
"""Tests for CopyTo functions of Descriptor."""

def _AssertProtoEqual(self, actual_proto, expected_class, expected_ascii):
Expand Down Expand Up @@ -694,7 +694,7 @@ def testCopyToProto_ServiceDescriptor(self):
# TEST_SERVICE_ASCII)


class MakeDescriptorTest(basetest.TestCase):
class MakeDescriptorTest(unittest.TestCase):

def testMakeDescriptorWithNestedFields(self):
file_descriptor_proto = descriptor_pb2.FileDescriptorProto()
Expand Down Expand Up @@ -776,4 +776,4 @@ def testMakeDescriptorWithOptions(self):
options.Extensions[unittest_custom_options_pb2.msgopt].i)

if __name__ == '__main__':
basetest.main()
unittest.main()
11 changes: 6 additions & 5 deletions python/google/protobuf/internal/generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

__author__ = '[email protected] (Will Robinson)'

from google.apputils import basetest
import unittest

from google.protobuf.internal import test_bad_identifiers_pb2
from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
Expand All @@ -55,7 +56,7 @@
MAX_EXTENSION = 536870912


class GeneratorTest(basetest.TestCase):
class GeneratorTest(unittest.TestCase):

def testNestedMessageDescriptor(self):
field_name = 'optional_nested_message'
Expand Down Expand Up @@ -291,7 +292,7 @@ def testOneof(self):
self.assertIs(desc.oneofs[0], desc.oneofs_by_name['oneof_field'])
nested_names = set(['oneof_uint32', 'oneof_nested_message',
'oneof_string', 'oneof_bytes'])
self.assertSameElements(
self.assertItemsEqual(
nested_names,
[field.name for field in desc.oneofs[0].fields])
for field_name, field_desc in desc.fields_by_name.iteritems():
Expand All @@ -301,7 +302,7 @@ def testOneof(self):
self.assertIsNone(field_desc.containing_oneof)


class SymbolDatabaseRegistrationTest(basetest.TestCase):
class SymbolDatabaseRegistrationTest(unittest.TestCase):
"""Checks that messages, enums and files are correctly registered."""

def testGetSymbol(self):
Expand Down Expand Up @@ -340,4 +341,4 @@ def testFindFileByName(self):
'google/protobuf/unittest.proto').name)

if __name__ == '__main__':
basetest.main()
unittest.main()
26 changes: 14 additions & 12 deletions python/google/protobuf/internal/message_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

__author__ = '[email protected] (Matt Toia)'

from google.apputils import basetest
import unittest

from google.protobuf import descriptor_pb2
from google.protobuf.internal import factory_test1_pb2
from google.protobuf.internal import factory_test2_pb2
Expand All @@ -43,7 +44,7 @@
from google.protobuf import message_factory


class MessageFactoryTest(basetest.TestCase):
class MessageFactoryTest(unittest.TestCase):

def setUp(self):
self.factory_test1_fd = descriptor_pb2.FileDescriptorProto.FromString(
Expand Down Expand Up @@ -104,17 +105,18 @@ def testGetMessages(self):
for _ in range(2):
messages = message_factory.GetMessages([self.factory_test2_fd,
self.factory_test1_fd])
self.assertContainsSubset(
['google.protobuf.python.internal.Factory2Message',
'google.protobuf.python.internal.Factory1Message'],
messages.keys())
self.assertTrue(
set(['google.protobuf.python.internal.Factory2Message',
'google.protobuf.python.internal.Factory1Message'],
).issubset(set(messages.keys())))
self._ExerciseDynamicClass(
messages['google.protobuf.python.internal.Factory2Message'])
self.assertContainsSubset(
['google.protobuf.python.internal.Factory2Message.one_more_field',
'google.protobuf.python.internal.another_field'],
(messages['google.protobuf.python.internal.Factory1Message']
._extensions_by_name.keys()))
self.assertTrue(
set(['google.protobuf.python.internal.Factory2Message.one_more_field',
'google.protobuf.python.internal.another_field'],
).issubset(
set(messages['google.protobuf.python.internal.Factory1Message']
._extensions_by_name.keys())))
factory_msg1 = messages['google.protobuf.python.internal.Factory1Message']
msg1 = messages['google.protobuf.python.internal.Factory1Message']()
ext1 = factory_msg1._extensions_by_name[
Expand All @@ -128,4 +130,4 @@ def testGetMessages(self):


if __name__ == '__main__':
basetest.main()
unittest.main()
11 changes: 5 additions & 6 deletions python/google/protobuf/internal/message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import sys
import unittest

from google.apputils import basetest
from google.protobuf.internal import _parameterized
from google.protobuf import unittest_pb2
from google.protobuf import unittest_proto3_arena_pb2
Expand All @@ -75,7 +74,7 @@ def IsNegInf(val):
@_parameterized.Parameters(
(unittest_pb2),
(unittest_proto3_arena_pb2))
class MessageTest(basetest.TestCase):
class MessageTest(unittest.TestCase):

def testBadUtf8String(self, message_module):
if api_implementation.Type() != 'python':
Expand Down Expand Up @@ -887,7 +886,7 @@ def testRepeatedCompositeFieldPop(self, message_module):


# Class to test proto2-only features (required, extensions, etc.)
class Proto2Test(basetest.TestCase):
class Proto2Test(unittest.TestCase):

def testFieldPresence(self):
message = unittest_pb2.TestAllTypes()
Expand Down Expand Up @@ -1037,7 +1036,7 @@ def testParsingMerge(self):


# Class to test proto3-only features/behavior (updated field presence & enums)
class Proto3Test(basetest.TestCase):
class Proto3Test(unittest.TestCase):

def testFieldPresence(self):
message = unittest_proto3_arena_pb2.TestAllTypes()
Expand Down Expand Up @@ -1115,7 +1114,7 @@ def testAssignUnknownEnum(self):
self.assertEqual(7654321, m2.repeated_nested_enum[0])


class ValidTypeNamesTest(basetest.TestCase):
class ValidTypeNamesTest(unittest.TestCase):

def assertImportFromName(self, msg, base_name):
# Parse <type 'module.class_name'> to extra 'some.name' as a string.
Expand All @@ -1138,4 +1137,4 @@ def testTypeNamesCanBeImported(self):


if __name__ == '__main__':
basetest.main()
unittest.main()
6 changes: 3 additions & 3 deletions python/google/protobuf/internal/proto_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

"""Tests for google.protobuf.proto_builder."""

from google.apputils import basetest
import unittest

from google.protobuf import descriptor_pb2
from google.protobuf import descriptor_pool
from google.protobuf import proto_builder
from google.protobuf import text_format


class ProtoBuilderTest(basetest.TestCase):
class ProtoBuilderTest(unittest.TestCase):

def setUp(self):
self._fields = {
Expand Down Expand Up @@ -74,4 +74,4 @@ def testMakeSameProtoClassTwice(self):


if __name__ == '__main__':
basetest.main()
unittest.main()
Loading

0 comments on commit 9f42f5f

Please sign in to comment.