summaryrefslogtreecommitdiff
path: root/bs4/testing.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/testing.py')
-rw-r--r--bs4/testing.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/bs4/testing.py b/bs4/testing.py
index c374a29..967261d 100644
--- a/bs4/testing.py
+++ b/bs4/testing.py
@@ -1,6 +1,7 @@
"""Helper classes for tests."""
import unittest
+from unittest import TestCase
from bs4 import BeautifulSoup
from bs4.element import Comment, SoupStrainer
from bs4.builder import LXMLTreeBuilder
@@ -31,3 +32,34 @@ class SoupTest(unittest.TestCase):
compare_parsed_to = to_parse
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
+
+ test_item.__unittest_skip__ = True
+ test_item.__unittest_skip_why__ = reason
+ return test_item
+ return decorator
+
+def skipIf(condition, reason):
+ """
+ Skip a test if the condition is true.
+ """
+ if condition:
+ return skip(reason)
+ return _id