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/testing.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'bs4/testing.py') diff --git a/bs4/testing.py b/bs4/testing.py index dc20812..b2ca180 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -358,6 +358,20 @@ class HTMLTreeBuilderSmokeTest(object): # For the rest of the story, see TestSubstitutions in # test_tree.py. +class XMLTreeBuilderSmokeTest(object): + + def test_namespaces_are_preserved(self): + markup = 'This tag is in the a namespaceThis tag is in the b namespace' + soup = self.soup(markup) + root = soup.root + import pdb; pdb.set_trace() + self.assertEquals("http://www.example.com/", root['xmlns:a']) + self.assertEquals("http://www.example.net/", root['xmlns:b']) + + + pass + + def skipIf(condition, reason): def nothing(test, *args, **kwargs): -- 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/testing.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'bs4/testing.py') diff --git a/bs4/testing.py b/bs4/testing.py index b2ca180..1945c02 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -360,16 +360,28 @@ class HTMLTreeBuilderSmokeTest(object): class XMLTreeBuilderSmokeTest(object): + def test_docstring_generated(self): + soup = self.soup("") + self.assertEqual( + soup.encode(), b'\n') + + def test_docstring_includes_correct_encoding(self): + soup = self.soup("") + self.assertEqual( + soup.encode("latin1"), + b'\n') + + + def test_tags_are_empty_element_if_and_only_if_they_are_empty(self): + self.assertSoupEquals("

", "

") + self.assertSoupEquals("

foo

") + def test_namespaces_are_preserved(self): - markup = 'This tag is in the a namespaceThis tag is in the b namespace' + markup = 'This tag is in the a namespaceThis tag is in the b namespace' soup = self.soup(markup) root = soup.root - import pdb; pdb.set_trace() - self.assertEquals("http://www.example.com/", root['xmlns:a']) - self.assertEquals("http://www.example.net/", root['xmlns:b']) - - - pass + self.assertEquals("http://example.com/", root['xmlns:a']) + self.assertEquals("http://example.net/", root['xmlns:b']) -- 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/testing.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bs4/testing.py') diff --git a/bs4/testing.py b/bs4/testing.py index 1945c02..6f9d857 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -371,6 +371,17 @@ class XMLTreeBuilderSmokeTest(object): soup.encode("latin1"), b'\n') + def test_real_xhtml_document(self): + """A real XHTML document should come out the same as it went in.""" + markup = b""" + + +Hello. +Goodbye. +""" + soup = self.soup(markup) + self.assertEqual(soup.encode("utf-8"), markup) + def test_tags_are_empty_element_if_and_only_if_they_are_empty(self): self.assertSoupEquals("

", "

") -- cgit v1.2.3 From 951d355581d27c2f3b61fa582fbe6ae57b46afb4 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 23 Feb 2012 13:35:53 -0500 Subject: Test that HTML5 parsers add the appropriate namespace to the tags they parse. --- bs4/testing.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'bs4/testing.py') diff --git a/bs4/testing.py b/bs4/testing.py index 6f9d857..55b953f 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -391,10 +391,29 @@ class XMLTreeBuilderSmokeTest(object): markup = 'This tag is in the a namespaceThis tag is in the b namespace' soup = self.soup(markup) root = soup.root - self.assertEquals("http://example.com/", root['xmlns:a']) - self.assertEquals("http://example.net/", root['xmlns:b']) + self.assertEqual("http://example.com/", root['xmlns:a']) + self.assertEqual("http://example.net/", root['xmlns:b']) +class HTML5TreeBuilderSmokeTest(HTMLTreeBuilderSmokeTest): + """Smoke test for a tree builder that supports HTML5.""" + + def test_html_tags_have_namespace(self): + markup = "" + soup = self.soup(markup) + self.assertEqual("http://www.w3.org/1999/xhtml", soup.a.namespace) + + def test_svg_tags_have_namespace(self): + markup = '' + soup = self.soup(markup) + self.assertEqual("http://www.w3.org/2000/svg", soup.svg.namespace) + + def test_mathml_tags_have_namespace(self): + markup = '' + soup = self.soup(markup) + self.assertEqual( + 'http://www.w3.org/1998/Math/MathML', soup.math.namespace) + def skipIf(condition, reason): def nothing(test, *args, **kwargs): -- cgit v1.2.3 From 6f15d9569be0f247a00a9d900246124bdeecec87 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 23 Feb 2012 13:38:46 -0500 Subject: A bit more testing. --- bs4/testing.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'bs4/testing.py') diff --git a/bs4/testing.py b/bs4/testing.py index 55b953f..e6f7f75 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -404,16 +404,19 @@ class HTML5TreeBuilderSmokeTest(HTMLTreeBuilderSmokeTest): self.assertEqual("http://www.w3.org/1999/xhtml", soup.a.namespace) def test_svg_tags_have_namespace(self): - markup = '' + markup = '' soup = self.soup(markup) - self.assertEqual("http://www.w3.org/2000/svg", soup.svg.namespace) + namespace = "http://www.w3.org/2000/svg" + self.assertEqual(namespace, soup.svg.namespace) + self.assertEqual(namespace, soup.circle.namespace) + def test_mathml_tags_have_namespace(self): - markup = '' + markup = '5' soup = self.soup(markup) - self.assertEqual( - 'http://www.w3.org/1998/Math/MathML', soup.math.namespace) - + namespace = 'http://www.w3.org/1998/Math/MathML' + self.assertEqual(namespace, soup.math.namespace) + self.assertEqual(namespace, soup.sqrt.namespace) def skipIf(condition, reason): def nothing(test, *args, **kwargs): -- cgit v1.2.3 From deaeb40977719ea821a62f41d75e2c9f48559094 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 23 Feb 2012 13:42:18 -0500 Subject: Inserted extra space. --- bs4/testing.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bs4/testing.py') diff --git a/bs4/testing.py b/bs4/testing.py index e6f7f75..c77b3b6 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -418,6 +418,7 @@ class HTML5TreeBuilderSmokeTest(HTMLTreeBuilderSmokeTest): self.assertEqual(namespace, soup.math.namespace) self.assertEqual(namespace, soup.sqrt.namespace) + def skipIf(condition, reason): def nothing(test, *args, **kwargs): return None -- cgit v1.2.3