summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.txt2
-rw-r--r--bs4/element.py2
-rw-r--r--bs4/testing.py32
-rw-r--r--bs4/tests/test_html5lib.py7
4 files changed, 39 insertions, 4 deletions
diff --git a/NEWS.txt b/NEWS.txt
index 8f16cd5..61c04ce 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -7,6 +7,8 @@
* Issue a warning if characters were replaced with REPLACEMENT
CHARACTER during Unicode conversion.
+* Restored compatibility with Python 2.6.
+
= 4.0.0b6 (20110216) =
* Multi-valued attributes like "class" always have a list of values,
diff --git a/bs4/element.py b/bs4/element.py
index 513407c..997378a 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -750,7 +750,7 @@ class Tag(PageElement):
# Turn the data structure into Unicode, then encode the
# Unicode.
u = self.decode(indent_level, encoding, formatter)
- return u.encode(encoding, errors=errors)
+ return u.encode(encoding, errors)
def decode(self, indent_level=None,
eventual_encoding=DEFAULT_OUTPUT_ENCODING,
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
diff --git a/bs4/tests/test_html5lib.py b/bs4/tests/test_html5lib.py
index d972b2d..f1f3727 100644
--- a/bs4/tests/test_html5lib.py
+++ b/bs4/tests/test_html5lib.py
@@ -10,8 +10,9 @@ from test_lxml import (
TestLXMLBuilderEncodingConversion,
)
import unittest
+from bs4.testing import skipIf
-@unittest.skipIf(
+@skipIf(
not HTML5LIB_PRESENT,
"html5lib seems not to be present, not testing its tree builder.")
class TestHTML5Builder(TestLXMLBuilder):
@@ -81,7 +82,7 @@ class TestHTML5Builder(TestLXMLBuilder):
# get a CData object.
self.assertSoupEquals(markup, "<svg><!--[CDATA[foobar]]--></svg>")
-@unittest.skipIf(
+@skipIf(
not HTML5LIB_PRESENT,
"html5lib seems not to be present, not testing it on invalid markup.")
class TestHTML5BuilderInvalidMarkup(TestLXMLBuilderInvalidMarkup):
@@ -246,7 +247,7 @@ class TestHTML5BuilderInvalidMarkup(TestLXMLBuilderInvalidMarkup):
self.assertEqual(soup.p.string, u"\N{REPLACEMENT CHARACTER}")
-@unittest.skipIf(
+@skipIf(
not HTML5LIB_PRESENT,
"html5lib seems not to be present, not testing encoding conversion.")
class TestHTML5LibEncodingConversion(TestLXMLBuilderEncodingConversion):