From d7056f49c8bb3a448cec2f1a6f2de55e93c8e8d6 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 26 Feb 2011 21:26:15 -0500 Subject: First stab at HTML entity replacement. --- tests/test_tree.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/test_tree.py') diff --git a/tests/test_tree.py b/tests/test_tree.py index 0b3d72e..249e7ae 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -830,6 +830,19 @@ class TestPersistence(SoupTest): class TestSubstitutions(SoupTest): + def test_entity_substitution(self): + soup = self.soup( + u"Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!") + encoded = soup.encode("utf-8", replace_with_html_entities=True) + self.assertEquals(encoded, + self.document_for("Sacré bleu!")) + + def test_entity_substitution_off_by_default(self): + markup = u"Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!" + soup = self.soup(markup) + encoded = soup.b.encode("utf-8") + self.assertEquals(encoded, markup.encode('utf-8')) + def test_encoding_substitution(self): # Here's the tag saying that a document is # encoded in Shift-JIS. -- cgit v1.2.3 From 247785aa53358fa64e9bd5f799c4c9a1609489f0 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 26 Feb 2011 22:54:04 -0500 Subject: Renamed replace_with_html_entities to substitute_html_entities. --- tests/test_tree.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/test_tree.py') diff --git a/tests/test_tree.py b/tests/test_tree.py index 249e7ae..f9163f1 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -830,14 +830,14 @@ class TestPersistence(SoupTest): class TestSubstitutions(SoupTest): - def test_entity_substitution(self): + def test_html_entity_substitution(self): soup = self.soup( u"Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!") - encoded = soup.encode("utf-8", replace_with_html_entities=True) + encoded = soup.encode("utf-8", substitute_html_entities=True) self.assertEquals(encoded, self.document_for("Sacré bleu!")) - def test_entity_substitution_off_by_default(self): + def test_html_entity_substitution_off_by_default(self): markup = u"Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!" soup = self.soup(markup) encoded = soup.b.encode("utf-8") -- cgit v1.2.3 From 8a6e1b5e15368c9dd66b6b407b7328c2bd0360ad Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 26 Feb 2011 23:39:06 -0500 Subject: The attribute list comes in as a dictionary, so stop turning it into a list for no reason. Saves code and a little time. Sort outgoing attributes so that the tests will run consistently. --- tests/test_tree.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_tree.py') diff --git a/tests/test_tree.py b/tests/test_tree.py index f9163f1..ea10367 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -741,6 +741,14 @@ class TestElementObjects(SoupTest): self.assertTrue(soup.foo.has_key('attr')) self.assertFalse(soup.foo.has_key('attr2')) + def test_attributes_come_out_in_alphabetical_order(self): + markup = '' + self.assertSoupEquals(markup, '') + + def test_multiple_values_for_the_same_attribute_are_collapsed(self): + markup = '' + self.assertSoupEquals(markup, '') + def test_string(self): # A tag that contains only a text node makes that node # available as .string. -- cgit v1.2.3