diff options
author | Leonard Richardson <leonardr@segfault.org> | 2017-05-06 13:23:18 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2017-05-06 13:23:18 -0400 |
commit | 49cc750524fb436fa4880eefa6c8d0b3bbbd7175 (patch) | |
tree | 0d282e7eee39e43ed6cc7e1b5541bad4d585bed5 /bs4/testing.py | |
parent | 2874552990cf9668d721808d3dbd1cd80a98c614 (diff) |
It's now possible to use a tag's namespace prefix when searching,
e.g. soup.find('namespace:tag') [bug=1655332]
Diffstat (limited to 'bs4/testing.py')
-rw-r--r-- | bs4/testing.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bs4/testing.py b/bs4/testing.py index 3a6ed42..733cc29 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -669,6 +669,30 @@ class XMLTreeBuilderSmokeTest(object): soup = self.soup(markup) self.assertEqual(unicode(soup.foo), markup) + def test_find_by_prefixed_name(self): + doc = """<?xml version="1.0" encoding="utf-8"?> +<Document xmlns="http://example.com/ns0" + xmlns:ns1="http://example.com/ns1" + xmlns:ns2="http://example.com/ns2" + <ns1:tag>foo</ns1:tag> + <ns1:tag>bar</ns1:tag> + <ns2:tag key="value">baz</ns2:tag> +</Document> +""" + soup = self.soup(doc) + + # There are three <tag> tags. + self.assertEqual(3, len(soup.find_all('tag'))) + + # But two of them are ns1:tag and one of them is ns2:tag. + self.assertEqual(2, len(soup.find_all('ns1:tag'))) + self.assertEqual(1, len(soup.find_all('ns2:tag'))) + + self.assertEqual(1, len(soup.find_all('ns2:tag', key='value'))) + self.assertEqual(3, len(soup.find_all(['ns1:tag', 'ns2:tag']))) + + + class HTML5TreeBuilderSmokeTest(HTMLTreeBuilderSmokeTest): """Smoke test for a tree builder that supports HTML5.""" |