Skip to content

Commit

Permalink
remove dependency on unittest2
Browse files Browse the repository at this point in the history
This allows support for both python 2.6 and 3.3
  • Loading branch information
graingert committed Apr 5, 2013
1 parent bca1120 commit de34807
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
59 changes: 59 additions & 0 deletions django_browserid/tests/__init__.py
Expand Up @@ -87,3 +87,62 @@ def inner(*args, **kwargs):
with self:
return func(*args, **kwargs)
return inner


def skipped(func):
""" Decorator that marks a function as skipped. Uses nose's SkipTest exception
if installed. Without nose, this will count skipped tests as passing tests."""
try:
from nose.plugins.skip import SkipTest
def skipme(*a, **k):
raise SkipTest()
skipme.__name__ = func.__name__
return skipme
except ImportError:
# no nose, we'll just skip the test ourselves
def skipme(*a, **k):
print "Skipping", func.__name__
skipme.__name__ = func.__name__
return skipme


def skip_if(condition):
""" Decorator that skips a test if the *condition* evaluates True.
*condition* can be a boolean or a callable that accepts one argument.
The callable will be called with the function to be decorated, and
should return True to skip the test.
"""
def skipped_wrapper(func):
def wrapped(*a, **kw):
if isinstance(condition, bool):
result = condition
else:
result = condition(func)
if result:
return skipped(func)(*a, **kw)
else:
return func(*a, **kw)
wrapped.__name__ = func.__name__
return wrapped
return skipped_wrapper


def skip_unless(condition):
""" Decorator that skips a test if the *condition* does not return True.
*condition* can be a boolean or a callable that accepts one argument.
The callable will be called with the function to be decorated, and
should return True if the condition is satisfied.
"""
def skipped_wrapper(func):
def wrapped(*a, **kw):
if isinstance(condition, bool):
result = condition
else:
result = condition(func)
if not result:
return skipped(func)(*a, **kw)
else:
return func(*a, **kw)
wrapped.__name__ = func.__name__
return wrapped
return skipped_wrapper
10 changes: 2 additions & 8 deletions django_browserid/tests/test_auth.py
Expand Up @@ -8,13 +8,7 @@
from mock import ANY, patch

from django_browserid.auth import BrowserIDBackend, default_username_algo, verify
from django_browserid.tests import mock_browserid

# Support Python 2.6 by using unittest2
try:
from unittest import skipIf
except ImportError:
from unittest2 import skipIf
from django_browserid.tests import mock_browserid, skip_if

try:
from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -107,8 +101,8 @@ def test_verify_called_with_browserid_extra(self, user_verify):

# Only run custom user model tests if we're using a version of Django that
# supports it.
@skip_if(not get_user_model) # 'Not supported in Django < 1.5'
@patch.object(settings, 'AUTH_USER_MODEL', 'tests.CustomUser')
@skipIf(not get_user_model, 'Not supported in Django < 1.5')
class CustomUserModelTests(TestCase):
def _auth(self, backend=None, verified_email=None):
if backend is None:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Expand Up @@ -5,7 +5,6 @@ fancy_tag==0.2.0
mock>=0.8.0
Django>=1.3
django-nose
unittest2==0.5.1
pyquery==1.2.4

# Documentation
Expand Down

0 comments on commit de34807

Please sign in to comment.