diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-20 12:19:33 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-20 12:19:33 -0500 |
commit | 3cf25e3143a8765a0fd129a6ab368f617ee1653c (patch) | |
tree | 108123031ec71f9fe36bb957cb4f9c82b5743cbe | |
parent | 7283761096d81f87d313c08c2915d6ee19bc6a36 (diff) |
copied skipIf didn't work, so made a smaller one.
-rw-r--r-- | bs4/testing.py | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/bs4/testing.py b/bs4/testing.py index 0008821..e5e8c93 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -1,5 +1,6 @@ """Helper classes for tests.""" +import functools import unittest from unittest import TestCase from bs4 import BeautifulSoup @@ -37,33 +38,14 @@ class SoupTest(unittest.TestCase): self.assertEqual(obj.decode(), self.document_for(compare_parsed_to)) -# Code copied from Python 2.7 standard library, unittest.py, for use -# in Python 2.6. - -def _id(obj): - return obj - - -def skip(reason): - """ - Unconditionally skip a test. - """ - def decorator(test_item): - if not (isinstance(test_item, type) and issubclass(test_item, TestCase)): - @functools.wraps(test_item) - def skip_wrapper(*args, **kwargs): - raise SkipTest(reason) - test_item = skip_wrapper +def skipIf(condition, reason): + def nothing(test, *args, **kwargs): + return None - test_item.__unittest_skip__ = True - test_item.__unittest_skip_why__ = reason - return test_item - return decorator + def decorator(test_item): + if condition: + return nothing + else: + return test_item -def skipIf(condition, reason): - """ - Skip a test if the condition is true. - """ - if condition: - return skip(reason) - return _id + return decorator |