MCPcopy
hub / github.com/streamlit/streamlit / expect_prefixed_markdown

Function expect_prefixed_markdown

e2e_playwright/shared/app_utils.py:712–757  ·  view source on GitHub ↗

Find the markdown with the prefix and then ensure that the `expected_markdown` is in the text as well. Splitting it into a `filter` and a `to_have_text` check has the advantage that we see the diff in case of a mismatch; this would not be the case if we just used the `filter`.

(
    locator: FrameLocator | Locator | Page,
    expected_prefix: str,
    expected_markdown: str | re.Pattern[str],
    exact_match: bool = False,
)

Source from the content-addressed store, hash-verified

710
711
712def expect_prefixed_markdown(
713 locator: FrameLocator | Locator | Page,
714 expected_prefix: str,
715 expected_markdown: str | re.Pattern[str],
716 exact_match: bool = False,
717) -> None:
718 """Find the markdown with the prefix and then ensure that the
719 `expected_markdown` is in the text as well.
720
721 Splitting it into a `filter` and a `to_have_text` check has the advantage
722 that we see the diff in case of a mismatch; this would not be the case if we
723 just used the `filter`.
724
725 Only one markdown-element must be returned, otherwise an error is thrown.
726
727 Parameters
728 ----------
729 locator : Locator
730 The locator to search for the markdown element.
731
732 expected_prefix : str
733 The prefix of the markdown element.
734
735 expected_markdown : str or Pattern[str]
736 The markdown content that should be found. If a pattern is provided,
737 the text will be matched against this pattern.
738
739 exact_match : bool, optional
740 Whether the markdown should exactly match the `expected_markdown`, by default True.
741 Otherwise, the `expected_markdown` must be contained in the markdown content.
742
743 """
744 selection_text = locator.get_by_test_id("stMarkdownContainer").filter(
745 has_text=expected_prefix
746 )
747 if exact_match:
748 text_to_match: str | re.Pattern[str]
749 if isinstance(expected_markdown, re.Pattern):
750 # Recompile the pattern with the prefix:
751 text_to_match = re.compile(f"{expected_prefix} {expected_markdown.pattern}")
752 else:
753 text_to_match = f"{expected_prefix} {expected_markdown}"
754
755 expect(selection_text).to_have_text(text_to_match)
756 else:
757 expect(selection_text).to_contain_text(expected_markdown)
758
759
760def expect_markdown(

Calls 1

get_by_test_idMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…