diff options
-rw-r--r-- | bs4/testing.py | 15 | ||||
-rw-r--r-- | bs4/tests/test_htmlparser.py | 1 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 9 |
3 files changed, 24 insertions, 1 deletions
diff --git a/bs4/testing.py b/bs4/testing.py index cc30e17..dc20812 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -198,6 +198,21 @@ class HTMLTreeBuilderSmokeTest(object): self.assertSoupEquals("�", expect) self.assertSoupEquals("�", expect) + def test_basic_namespaces(self): + """Parsers don't need to *understand* namespaces, but at the + very least they should not choke on namespaces or lose + data.""" + + markup = b'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:mathml="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg"><head></head><body><mathml:msqrt>4</mathml:msqrt><b svg:fill="red"></b></body></html>' + soup = self.soup(markup) + self.assertEquals(markup, soup.encode()) + html = soup.html + self.assertEquals('http://www.w3.org/1999/xhtml', soup.html['xmlns']) + self.assertEquals( + 'http://www.w3.org/1998/Math/MathML', soup.html['xmlns:mathml']) + self.assertEquals( + 'http://www.w3.org/2000/svg', soup.html['xmlns:svg']) + # # Generally speaking, tests below this point are more tests of # Beautiful Soup than tests of the tree builders. But parsers are diff --git a/bs4/tests/test_htmlparser.py b/bs4/tests/test_htmlparser.py index bcb5ed2..6215185 100644 --- a/bs4/tests/test_htmlparser.py +++ b/bs4/tests/test_htmlparser.py @@ -17,3 +17,4 @@ class HTMLParserTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest): def test_namespaced_public_doctype(self): # html.parser can't handle namespaced doctypes, so skip this one. pass + diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index f39826a..6aa02cb 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -63,7 +63,6 @@ class TestFind(TreeTest): soup = self.soup(u'<h1>Räksmörgås</h1>') self.assertEqual(soup.find(text=u'Räksmörgås'), u'Räksmörgås') - class TestFindAll(TreeTest): """Basic tests of the find_all() method.""" @@ -94,6 +93,14 @@ class TestFindAll(TreeTest): self.assertSelects( soup.find_all('a', limit=0), ["1", "2", "3", "4", "5"]) +class TestFindAllBasicNamespaces(TreeTest): + + def test_find_by_namespaced_name(self): + soup = self.soup('<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">') + self.assertEquals("4", soup.find("mathml:msqrt").string) + self.assertEquals("a", soup.find(attrs= { "svg:fill" : "red" }).name) + + class TestFindAllByName(TreeTest): """Test ways of finding tags by tag name.""" |