Fixed #24112 -- Fixed assertInHTML()'s counting if needle has no root element.
This commit is contained in:
parent
ff1e7b4eb4
commit
ca2ccf54ff
|
@ -94,6 +94,9 @@ class Element(object):
|
||||||
if not isinstance(element, six.string_types):
|
if not isinstance(element, six.string_types):
|
||||||
if self == element:
|
if self == element:
|
||||||
return 1
|
return 1
|
||||||
|
if isinstance(element, RootElement):
|
||||||
|
if self.children == element.children:
|
||||||
|
return 1
|
||||||
i = 0
|
i = 0
|
||||||
for child in self.children:
|
for child in self.children:
|
||||||
# child is text content and element is also text content, then
|
# child is text content and element is also text content, then
|
||||||
|
|
|
@ -591,6 +591,8 @@ class HTMLEqualTests(SimpleTestCase):
|
||||||
self.assertIn(dom1, dom2)
|
self.assertIn(dom1, dom2)
|
||||||
dom1 = parse_html('<p>bar</p>')
|
dom1 = parse_html('<p>bar</p>')
|
||||||
self.assertIn(dom1, dom2)
|
self.assertIn(dom1, dom2)
|
||||||
|
dom1 = parse_html('<div><p>foo</p><p>bar</p></div>')
|
||||||
|
self.assertIn(dom2, dom1)
|
||||||
|
|
||||||
def test_count(self):
|
def test_count(self):
|
||||||
# equal html contains each other one time
|
# equal html contains each other one time
|
||||||
|
@ -626,6 +628,11 @@ class HTMLEqualTests(SimpleTestCase):
|
||||||
dom2 = parse_html('<p>foo<p>bar</p></p>')
|
dom2 = parse_html('<p>foo<p>bar</p></p>')
|
||||||
self.assertEqual(dom2.count(dom1), 0)
|
self.assertEqual(dom2.count(dom1), 0)
|
||||||
|
|
||||||
|
# html with a root element contains the same html with no root element
|
||||||
|
dom1 = parse_html('<p>foo</p><p>bar</p>')
|
||||||
|
dom2 = parse_html('<div><p>foo</p><p>bar</p></div>')
|
||||||
|
self.assertEqual(dom2.count(dom1), 1)
|
||||||
|
|
||||||
def test_parsing_errors(self):
|
def test_parsing_errors(self):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
self.assertHTMLEqual('<p>', '')
|
self.assertHTMLEqual('<p>', '')
|
||||||
|
|
Loading…
Reference in New Issue