Skip to content

Commit

Permalink
Merge pull request #276 from tamird/drop-apputils-dependency
Browse files Browse the repository at this point in the history
Migrate Python tests to stdlib unittest, drop apputils dependency.
  • Loading branch information
haberman committed Apr 11, 2015
2 parents 6003aa1 + 9f42f5f commit be89e62
Show file tree
Hide file tree
Showing 24 changed files with 132 additions and 278 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
3 changes: 0 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,14 @@ python_EXTRA_DIST= \
python/google/protobuf/internal/descriptor_pool_test.py \
python/google/protobuf/internal/descriptor_pool_test1.proto \
python/google/protobuf/internal/descriptor_pool_test2.proto \
python/google/protobuf/internal/descriptor_python_test.py \
python/google/protobuf/internal/descriptor_test.py \
python/google/protobuf/internal/encoder.py \
python/google/protobuf/internal/enum_type_wrapper.py \
python/google/protobuf/internal/factory_test1.proto \
python/google/protobuf/internal/factory_test2.proto \
python/google/protobuf/internal/generator_test.py \
python/google/protobuf/internal/message_factory_python_test.py \
python/google/protobuf/internal/message_factory_test.py \
python/google/protobuf/internal/message_listener.py \
python/google/protobuf/internal/message_python_test.py \
python/google/protobuf/internal/message_test.py \
python/google/protobuf/internal/missing_enum_values.proto \
python/google/protobuf/internal/more_extensions.proto \
Expand Down
38 changes: 28 additions & 10 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,39 @@ Installation
4) Build and run the tests:

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

To build the C++ implementation run:
$ python setup.py build --cpp_implementation
To build, test, and use the C++ implementation, you must first compile
libprotobuf.so:

$ (cd .. && make)

On OS X:

If you are running a homebrew-provided python, you must make sure another
version of protobuf is not already installed, as homebrew's python will
search /usr/local/lib for libprotobuf.so before it searches ../src/.libs
You can either unlink homebrew's protobuf or install the libprotobuf you
built earlier:

To test and use the C++ implementation, you must make libprotobuf.so
from the C++ build accessible. You can either install the C++ code
you built, or set LD_LIBRARY_PATH:
$ brew unlink protobuf
or
$ (cd .. && make install)

$ (cd .. && make install)
or
$ export LD_LIBRARY_PATH=../src/.libs
On other *nix:

You must make libprotobuf.so dynamically available. You can either
install libprotobuf you built earlier, or set LD_LIBRARY_PATH:

$ export LD_LIBRARY_PATH=../src/.libs
or
$ (cd .. && make install)

To build the C++ implementation run:
$ 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
4 changes: 2 additions & 2 deletions python/google/protobuf/internal/api_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@

# This environment variable can be used to switch between the two
# 'cpp' implementations, overriding the compile-time constants in the
# _api_implementation module. Right now only 1 and 2 are valid values. Any other
# value will be ignored.
# _api_implementation module. Right now only '2' is supported. Any other
# value will cause an error to be raised.
_implementation_version_str = os.getenv(
'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION', '2')

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()
54 changes: 0 additions & 54 deletions python/google/protobuf/internal/descriptor_python_test.py

This file was deleted.

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()
54 changes: 0 additions & 54 deletions python/google/protobuf/internal/message_factory_python_test.py

This file was deleted.

Loading

0 comments on commit be89e62

Please sign in to comment.