MCPcopy
hub / github.com/django/django / assertHTMLEqual

Method assertHTMLEqual

django/test/testcases.py:955–977  ·  view source on GitHub ↗

Assert that two HTML snippets are semantically the same. Whitespace in most cases is ignored, and attribute ordering is not significant. The arguments must be valid HTML.

(self, html1, html2, msg=None)

Source from the content-addressed store, hash-verified

953 self.assertIsInstance(fieldclass(*field_args, **field_kwargs), fieldclass)
954
955 def assertHTMLEqual(self, html1, html2, msg=None):
956 """
957 Assert that two HTML snippets are semantically the same.
958 Whitespace in most cases is ignored, and attribute ordering is not
959 significant. The arguments must be valid HTML.
960 """
961 dom1 = assert_and_parse_html(
962 self, html1, msg, "First argument is not valid HTML:"
963 )
964 dom2 = assert_and_parse_html(
965 self, html2, msg, "Second argument is not valid HTML:"
966 )
967
968 if dom1 != dom2:
969 standardMsg = "%s != %s" % (safe_repr(dom1, True), safe_repr(dom2, True))
970 diff = "\n" + "\n".join(
971 difflib.ndiff(
972 str(dom1).splitlines(),
973 str(dom2).splitlines(),
974 )
975 )
976 standardMsg = self._truncateMessage(standardMsg, diff)
977 self.fail(self._formatMessage(msg, standardMsg))
978
979 def assertHTMLNotEqual(self, html1, html2, msg=None):
980 """Assert that two HTML snippets are not semantically equivalent."""

Calls 2

assert_and_parse_htmlFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected