Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1963 from asmacdo/unittest-to-compat
Browse files Browse the repository at this point in the history
import unittest2 in compat module
  • Loading branch information
asmacdo committed Jul 7, 2015
2 parents 051799a + 5fbe335 commit 09f2ddd
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 50 deletions.
29 changes: 8 additions & 21 deletions common/pulp/common/compat.py
@@ -1,16 +1,4 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2012 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

"""
This module contains a few items that we have come to love from versions of Python that are newer
than 2.4. Because we love those things so much, we have brought them into this file so that our code
Expand All @@ -21,6 +9,7 @@

import backports.pkgutil


def check_builtin(module):
"""
This decorator tries to return a function of the same name as f from the given module, and falls
Expand All @@ -38,18 +27,14 @@ def wrap(f):
return wrap


################################################
# This provides json.
################################################
try:
import json
except ImportError:
import simplejson as json
import simplejson as json # noqa


################################################
# This provides the builtin, all.
################################################
@check_builtin(__builtin__)
def all(iterable):
"""
Expand All @@ -62,9 +47,7 @@ def all(iterable):
return True


################################################
# This provides the builtin, any.
################################################
@check_builtin(__builtin__)
def any(iterable):
"""
Expand All @@ -77,9 +60,13 @@ def any(iterable):
return False


################################################
# This provides pkgutil.iter_modules.
################################################
@check_builtin(pkgutil)
def iter_modules(*args, **kwargs):
return backports.pkgutil.iter_modules(*args, **kwargs)


try:
import unittest2 as unittest
except ImportError:
import unittest # noqa
5 changes: 1 addition & 4 deletions server/test/unit/base.py
@@ -1,11 +1,8 @@
from copy import deepcopy
try:
import unittest2 as unittest
except ImportError:
import unittest

import mock

from pulp.common.compat import unittest
from pulp.server.async import celery_instance
from pulp.server.db.model import TaskStatus, ReservedResource, Worker
from pulp.server.managers import factory as manager_factory
Expand Down
5 changes: 1 addition & 4 deletions server/test/unit/plugins/loader/test_manager.py
@@ -1,13 +1,10 @@
import pkg_resources
try:
import unittest2 as unittest
except ImportError:
import unittest

import mock
import mongoengine

from pulp.common import error_codes
from pulp.common.compat import unittest
from pulp.plugins.loader import manager
from pulp.server import exceptions
from pulp.server.db.model import ContentUnit
Expand Down
6 changes: 1 addition & 5 deletions server/test/unit/server/controllers/test_repository.py
@@ -1,12 +1,8 @@
try:
import unittest2 as unittest
except ImportError:
import unittest

from mock import MagicMock, patch
import mock
import mongoengine

from pulp.common.compat import unittest
from pulp.plugins.loader import exceptions as plugin_exceptions
from pulp.plugins.model import PublishReport
from pulp.server.controllers import repository as repo_controller
Expand Down
7 changes: 1 addition & 6 deletions server/test/unit/server/controllers/test_units.py
@@ -1,12 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest


from mock import MagicMock, patch
import mongoengine

from pulp.common.compat import unittest
from pulp.server.controllers import units as units_controller
from pulp.server.db import model

Expand Down
6 changes: 1 addition & 5 deletions server/test/unit/server/db/test_model.py
Expand Up @@ -9,15 +9,11 @@

from mock import patch

try:
import unittest2 as unittest
except ImportError:
import unittest

import mongoengine
from mongoengine import DateTimeField, DictField, Document, IntField, StringField

from pulp.common import error_codes, dateutils
from pulp.common.compat import unittest
from pulp.devel.unit.util import touch
from pulp.server.exceptions import PulpCodedException
from pulp.server.db import model
Expand Down
@@ -1,10 +1,6 @@
try:
import unittest2 as unittest
except ImportError:
import unittest

import mock

from pulp.common.compat import unittest
# The serializers module should not normally be an starting point for imports, so we need to import
# the criteria module before serializers to prevent a circular import. This is only an issue when
# running this test module by itself, and will be fixed when pulp.server.db.model becomes a true
Expand Down

0 comments on commit 09f2ddd

Please sign in to comment.