From 87747b712cfe63d173332f06ee1ba2bf9adf9ce5 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Wed, 15 Feb 2012 17:03:37 -0500 Subject: Added a kind of hacky way to interpret the restriction class='foo bar'. Stop generating a space before the slash that closes an empty-element tag. --- bs4/tests/test_tree.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 3684777..9e57d54 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -220,6 +220,17 @@ class TestFindAllByAttribute(TreeTest): self.assertSelects( soup.find_all("a", small_attribute_value), ["Found it"]) + def test_find_all_with_string_for_attrs_finds_multiple_classes(self): + soup = self.soup('') + a, a2 = soup.find_all("a") + self.assertEqual([a, a2], soup.find_all("a", "foo")) + self.assertEqual([a], soup.find_all("a", "bar")) + + # If you specify the attribute as a string that contains a + # space, only that specific value will be found. + self.assertEqual([a], soup.find_all("a", "foo bar")) + self.assertEqual([], soup.find_all("a", "bar foo")) + def test_find_all_by_attribute_soupstrainer(self): tree = self.soup(""" Match. @@ -595,8 +606,8 @@ class TestTagCreation(SoupTest): # Both the
and

tag are empty-element, just because # they have no contents. - self.assertEqual(b"
", xml_br.encode()) - self.assertEqual(b"

", xml_p.encode()) + self.assertEqual(b"
", xml_br.encode()) + self.assertEqual(b"

", xml_p.encode()) html_soup = BeautifulSoup("", "html") html_br = html_soup.new_tag("br") @@ -604,7 +615,7 @@ class TestTagCreation(SoupTest): # The HTML builder users HTML's rules about which tags are # empty-element tags, and the new tags reflect these rules. - self.assertEqual(b"
", html_br.encode()) + self.assertEqual(b"
", html_br.encode()) self.assertEqual(b"

", html_p.encode()) def test_new_string_creates_navigablestring(self): @@ -775,7 +786,7 @@ class TestTreeModification(SoupTest): # markup like this to come through. But in general, we don't # know what the parser would or wouldn't have allowed, so # I'm letting this succeed for now. - soup = self.soup("
") + soup = self.soup("
") soup.br.insert(1, "Contents") self.assertEqual(str(soup.br), "
Contents
") @@ -1071,7 +1082,7 @@ class TestCDAtaListAttributes(SoupTest): # We saw in another test that accept-charset is a cdata-list # attribute for the
tag. But it's not a cdata-list # attribute for any other tag. - self.assertEquals('ISO-8859-1 UTF-8', soup.a['accept-charset']) + self.assertEqual('ISO-8859-1 UTF-8', soup.a['accept-charset']) class TestPersistence(SoupTest): @@ -1183,7 +1194,7 @@ class TestSubstitutions(SoupTest): # Here's the tag saying that a document is # encoded in Shift-JIS. meta_tag = ('') + 'http-equiv="Content-type"/>') soup = self.soup(meta_tag) # Parse the document, and the charset is replaced with a @@ -1207,7 +1218,7 @@ class TestSubstitutions(SoupTest): def test_encoding_substitution_doesnt_happen_if_tag_is_strained(self): markup = ('
foo
') + 'http-equiv="Content-type"/>
foo
') # Beautiful Soup used to try to rewrite the meta tag even if the # meta tag got filtered out by the strainer. This test makes -- cgit v1.2.3