summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2010-12-29 20:59:40 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2010-12-29 20:59:40 -0500
commitb689fd9c53a9b43ea37e473df6d2f56e0e7e1bcf (patch)
tree3b53c9b26acad852419dcfec5c190da58abf91ff
parentd9c95565a7db3272f1e7337eca5234ab0d64dfd2 (diff)
A few more simple tests.
-rw-r--r--src/beautifulsoup/tests/test_soup.py11
-rw-r--r--src/beautifulsoup/tests/test_tree.py16
2 files changed, 23 insertions, 4 deletions
diff --git a/src/beautifulsoup/tests/test_soup.py b/src/beautifulsoup/tests/test_soup.py
index 66f05ae..558d482 100644
--- a/src/beautifulsoup/tests/test_soup.py
+++ b/src/beautifulsoup/tests/test_soup.py
@@ -72,3 +72,14 @@ class TestUnicodeDammit(unittest.TestCase):
dammit = UnicodeDammit(utf_8)
self.assertEquals(dammit.originalEncoding, 'utf-8')
self.assertEquals(dammit.unicode.encode("utf-8"), utf_8)
+
+ def test_ignore_inappropriate_codecs(self):
+ utf8_data = u"Räksmörgås".encode("utf-8")
+ dammit = UnicodeDammit(utf8_data, ["utf-16"])
+ self.assertEquals(dammit.originalEncoding, 'utf-8')
+
+ def test_ignore_invalid_codecs(self):
+ utf8_data = u"Räksmörgås".encode("utf-8")
+ for bad_encoding in ['.utf8', '...', 'utF---16.!']:
+ dammit = UnicodeDammit(utf8_data, [bad_encoding])
+ self.assertEquals(dammit.originalEncoding, 'utf-8')
diff --git a/src/beautifulsoup/tests/test_tree.py b/src/beautifulsoup/tests/test_tree.py
index 191ec59..9e0dbc5 100644
--- a/src/beautifulsoup/tests/test_tree.py
+++ b/src/beautifulsoup/tests/test_tree.py
@@ -35,7 +35,15 @@ class TreeTest(SoupTest):
class TestFind(TreeTest):
- """Basic tests of the find() method."""
+ """Basic tests of the find() method.
+
+ find() just calls findAll() with limit=1, so it's not tested all
+ that thouroughly here.
+ """
+
+ def test_find_tag(self):
+ soup = self.soup("<a>1</a><b>2</b><a>3</a><b>4</b>")
+ self.assertEqual(soup.find("b").string, "2")
def test_unicode_text_find(self):
soup = self.soup(u'<h1>Räksmörgås</h1>')
@@ -296,9 +304,9 @@ class TestNextOperations(TreeTest):
last = self.tree.find(text="Three")
self.assertEquals(last.next, None)
- # XXX This doesn't actually work.
- #def test_next_of_root_is_first_item(self):
- # self.assertEquals(self.tree.next['id'], 'start')
+ def test_next_of_root_is_none(self):
+ # The document root is outside the next/previous chain.
+ self.assertEquals(self.tree.next, None)
def test_find_all_next(self):
self.assertSelects(self.start.findAllNext('b'), ["Two", "Three"])