From 2f72913160bedb509a8042693328d139e7c6b945 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 23 Feb 2012 11:16:45 -0500 Subject: Namespaced attributes are equal if they correspond to the same string. --- bs4/tests/test_soup.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'bs4/tests/test_soup.py') diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 2b7c003..e9aaa78 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -3,7 +3,10 @@ import unittest from bs4 import BeautifulSoup -from bs4.element import SoupStrainer +from bs4.element import ( + SoupStrainer, + NamespacedAttribute, + ) from bs4.dammit import EntitySubstitution, UnicodeDammit from bs4.testing import SoupTest import warnings @@ -233,3 +236,17 @@ class TestUnicodeDammit(unittest.TestCase): msg = w[0].message self.assertTrue(isinstance(msg, UnicodeWarning)) self.assertTrue("Some characters could not be decoded" in str(msg)) + + +class TestNamedspacedAttribute(SoupTest): + + def test_attribute_is_equivalent_to_colon_separated_string(self): + a = NamespacedAttribute("a", "b") + self.assertEqual("a:b", a) + + def test_attributes_are_equivalent_if_all_members_identical(self): + a = NamespacedAttribute("a", "b", "c") + b = NamespacedAttribute("a", "b", "c") + self.assertEqual(a, b) + b.namespace = "d" + self.assertNotEqual(a, b) -- cgit v1.2.3 From b7749c50a2c96ccf6982cfa1ca02d883e31e0af9 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 23 Feb 2012 11:56:40 -0500 Subject: Bumped version number. --- bs4/tests/test_soup.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'bs4/tests/test_soup.py') diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index e9aaa78..8333ad4 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -19,7 +19,7 @@ class TestDeprecatedConstructorArguments(SoupTest): msg = str(w[0].message) self.assertTrue("parseOnlyThese" in msg) self.assertTrue("parse_only" in msg) - self.assertEquals(b"", soup.encode()) + self.assertEqual(b"", soup.encode()) def test_fromEncoding_renamed_to_from_encoding(self): with warnings.catch_warnings(record=True) as w: @@ -28,7 +28,7 @@ class TestDeprecatedConstructorArguments(SoupTest): msg = str(w[0].message) self.assertTrue("fromEncoding" in msg) self.assertTrue("from_encoding" in msg) - self.assertEquals("utf8", soup.original_encoding) + self.assertEqual("utf8", soup.original_encoding) def test_unrecognized_keyword_argument(self): self.assertRaises( @@ -209,7 +209,7 @@ class TestUnicodeDammit(unittest.TestCase): b"", b""): dammit = UnicodeDammit(data, is_html=True) - self.assertEquals( + self.assertEqual( "euc-jp", dammit.original_encoding) def test_last_ditch_entity_replacement(self): @@ -244,9 +244,18 @@ class TestNamedspacedAttribute(SoupTest): a = NamespacedAttribute("a", "b") self.assertEqual("a:b", a) - def test_attributes_are_equivalent_if_all_members_identical(self): + def test_attributes_are_equivalent_if_prefix_and_name_identical(self): a = NamespacedAttribute("a", "b", "c") b = NamespacedAttribute("a", "b", "c") self.assertEqual(a, b) - b.namespace = "d" - self.assertNotEqual(a, b) + + # The actual namespace is not considered. + c = NamespacedAttribute("a", "b", None) + self.assertEqual(a, c) + + # But name and prefix are important. + d = NamespacedAttribute("a", "z", "c") + self.assertNotEqual(a, d) + + e = NamespacedAttribute("z", "b", "c") + self.assertNotEqual(a, e) -- cgit v1.2.3 From fcefebe15290b9ff44934efa73fb07c70ebf5171 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 23 Feb 2012 12:23:12 -0500 Subject: Fixed handling of the closing of namespaced tags. --- bs4/tests/test_soup.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bs4/tests/test_soup.py') diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 8333ad4..33ab0fa 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -240,6 +240,10 @@ class TestUnicodeDammit(unittest.TestCase): class TestNamedspacedAttribute(SoupTest): + def test_name_may_be_none(self): + a = NamespacedAttribute("xmlns", None) + self.assertEqual(a, "xmlns") + def test_attribute_is_equivalent_to_colon_separated_string(self): a = NamespacedAttribute("a", "b") self.assertEqual("a:b", a) -- cgit v1.2.3