diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-23 13:55:51 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-23 13:55:51 -0500 |
commit | 97b54c4bdbee0f109c444b50d8102ae8d7abb7c4 (patch) | |
tree | 8feb3c4387fa5dc67c810f76c9a831ebf523898d /bs4/tests/test_soup.py | |
parent | 328204928bd22ca9e8aeac0a3208645d9f82f264 (diff) | |
parent | deaeb40977719ea821a62f41d75e2c9f48559094 (diff) |
The namespace stuff seems to work, and it's definitely an improvement on the status quo, so in it goes.
Diffstat (limited to 'bs4/tests/test_soup.py')
-rw-r--r-- | bs4/tests/test_soup.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 2b7c003..33ab0fa 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 @@ -16,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"<b></b>", soup.encode()) + self.assertEqual(b"<b></b>", soup.encode()) def test_fromEncoding_renamed_to_from_encoding(self): with warnings.catch_warnings(record=True) as w: @@ -25,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( @@ -206,7 +209,7 @@ class TestUnicodeDammit(unittest.TestCase): b"<html><meta charset=euc-jp /></html>", b"<html><meta charset=euc-jp/></html>"): dammit = UnicodeDammit(data, is_html=True) - self.assertEquals( + self.assertEqual( "euc-jp", dammit.original_encoding) def test_last_ditch_entity_replacement(self): @@ -233,3 +236,30 @@ 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_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) + + 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) + + # 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) |