Fixed #34657 -- Made assert(Not)Contains/assertInHTML display haystacks in error messages.

This commit is contained in:
Chinmoy Chakraborty 2023-10-02 23:16:21 +05:30 committed by Mariusz Felisiak
parent 54d9d26ebf
commit 1dae65dc63
5 changed files with 157 additions and 31 deletions

View file

@ -985,12 +985,18 @@ class HTMLEqualTests(SimpleTestCase):
class InHTMLTests(SimpleTestCase):
def test_needle_msg(self):
msg = "False is not true : Couldn't find '<b>Hello</b>' in response"
msg = (
"False is not true : Couldn't find '<b>Hello</b>' in the following "
"response\n'<p>Test</p>'"
)
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML("<b>Hello</b>", "<p>Test</p>")
def test_msg_prefix(self):
msg = "False is not true : Prefix: Couldn't find '<b>Hello</b>' in response"
msg = (
"False is not true : Prefix: Couldn't find '<b>Hello</b>' in the following "
'response\n\'<input type="text" name="Hello" />\''
)
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML(
"<b>Hello</b>",
@ -1000,8 +1006,9 @@ class InHTMLTests(SimpleTestCase):
def test_count_msg_prefix(self):
msg = (
"2 != 1 : Prefix: Found 2 instances of '<b>Hello</b>' in response "
"(expected 1)"
"2 != 1 : Prefix: Found 2 instances of '<b>Hello</b>' (expected 1) in the "
"following response\n'<b>Hello</b><b>Hello</b>'"
""
)
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML(
@ -1011,6 +1018,38 @@ class InHTMLTests(SimpleTestCase):
msg_prefix="Prefix",
)
def test_base(self):
haystack = "<p><b>Hello</b> <span>there</span>! Hi <span>there</span>!</p>"
self.assertInHTML("<b>Hello</b>", haystack=haystack)
msg = f"Couldn't find '<p>Howdy</p>' in the following response\n{haystack!r}"
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML("<p>Howdy</p>", haystack)
self.assertInHTML("<span>there</span>", haystack=haystack, count=2)
msg = (
"Found 1 instances of '<b>Hello</b>' (expected 2) in the following response"
f"\n{haystack!r}"
)
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML("<b>Hello</b>", haystack=haystack, count=2)
def test_long_haystack(self):
haystack = (
"<p>This is a very very very very very very very very long message which "
"exceedes the max limit of truncation.</p>"
)
msg = f"Couldn't find '<b>Hello</b>' in the following response\n{haystack!r}"
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML("<b>Hello</b>", haystack)
msg = (
"Found 0 instances of '<b>This</b>' (expected 3) in the following response"
f"\n{haystack!r}"
)
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML("<b>This</b>", haystack, 3)
class JSONEqualTests(SimpleTestCase):
def test_simple_equal(self):