diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-20 10:01:21 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-20 10:01:21 -0500 |
commit | 0909884d21621394c0e810c508ceb4a4743ab8b5 (patch) | |
tree | 91993561e21eb2c26bfd06f1a30192b79d88a676 /bs4/testing.py | |
parent | 6c25290f92453294397049661f5edc36af562082 (diff) |
Added code from 2.7's standard library so that the tests will run on Python 2.6.
Diffstat (limited to 'bs4/testing.py')
-rw-r--r-- | bs4/testing.py | 32 |
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 |