summaryrefslogtreecommitdiff
path: root/src/beautifulsoup/builder/__init__.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2010-12-29 10:38:46 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2010-12-29 10:38:46 -0500
commit7ba9e49cada146978c1f02d9c28430fdcf56ab72 (patch)
tree77fd6a9d2ab9940569e21e0bcd6b29fed33b03ee /src/beautifulsoup/builder/__init__.py
parent017a21625f347665ad23da6dd109b9af29b4b443 (diff)
Refactored the code that turns HTML fragments into parser-specific documents for test purposes.
Diffstat (limited to 'src/beautifulsoup/builder/__init__.py')
-rw-r--r--src/beautifulsoup/builder/__init__.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/beautifulsoup/builder/__init__.py b/src/beautifulsoup/builder/__init__.py
index cf54c9c..b7db8db 100644
--- a/src/beautifulsoup/builder/__init__.py
+++ b/src/beautifulsoup/builder/__init__.py
@@ -26,6 +26,19 @@ class TreeBuilder(Entities):
def feed(self, markup):
raise NotImplementedError()
+ def test_fragment_to_document(self, fragment):
+ """Wrap an HTML fragment to make it look like a document.
+
+ Different parsers do this differently. For instance, lxml
+ introduces an empty <head> tag, and html5lib
+ doesn't. Abstracting this away lets us write simple tests
+ which run HTML fragments through the parser and compare the
+ results against other HTML fragments.
+
+ This method should not be used outside of tests.
+ """
+ return fragment
+
class SAXTreeBuilder(TreeBuilder):
"""A Beautiful Soup treebuilder that listens for SAX events."""