(self, needle, haystack, count=None, msg_prefix="")
| 990 | self.fail(self._formatMessage(msg, standardMsg)) |
| 991 | |
| 992 | def assertInHTML(self, needle, haystack, count=None, msg_prefix=""): |
| 993 | parsed_needle = assert_and_parse_html( |
| 994 | self, needle, None, "First argument is not valid HTML:" |
| 995 | ) |
| 996 | parsed_haystack = assert_and_parse_html( |
| 997 | self, haystack, None, "Second argument is not valid HTML:" |
| 998 | ) |
| 999 | real_count = parsed_haystack.count(parsed_needle) |
| 1000 | |
| 1001 | if (count is None and real_count > 0) or count == real_count: |
| 1002 | return |
| 1003 | |
| 1004 | if msg_prefix: |
| 1005 | msg_prefix += ": " |
| 1006 | haystack_repr = safe_repr(haystack) |
| 1007 | if count is not None: |
| 1008 | if count == 0: |
| 1009 | msg = ( |
| 1010 | f"{needle!r} unexpectedly found in the following response\n" |
| 1011 | f"{haystack_repr}" |
| 1012 | ) |
| 1013 | else: |
| 1014 | msg = ( |
| 1015 | f"Found {real_count} instances of {needle!r} (expected {count}) in " |
| 1016 | f"the following response\n{haystack_repr}" |
| 1017 | ) |
| 1018 | msg = f"{real_count} != {count} : {msg_prefix}{msg}" |
| 1019 | else: |
| 1020 | msg = ( |
| 1021 | f"False is not true : {msg_prefix}Couldn't find {needle!r} in the " |
| 1022 | f"following response\n{haystack_repr}" |
| 1023 | ) |
| 1024 | self.fail(msg) |
| 1025 | |
| 1026 | def assertNotInHTML(self, needle, haystack, msg_prefix=""): |
| 1027 | self.assertInHTML(needle, haystack, count=0, msg_prefix=msg_prefix) |
no test coverage detected