Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove dependency on unittest2

This allows support for both python 2.6 and 3.3
  • Loading branch information...
commit de34807a2720079d507aa16c2397f024b7c93907 1 parent bca1120
@graingert authored
View
59 django_browserid/tests/__init__.py
@@ -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
View
10 django_browserid/tests/test_auth.py
@@ -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
@@ -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:
View
1  requirements.txt
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.