async def test_role_completions( client: Client, text: str, setup: Tuple[str, Optional[Set[str]], Optional[Set[str]]], ): """Ensure that we can offer correct role suggestions. This test case is focused on the list of completion items we return for a given completion request. This ensures we correctly handle differing sphinx configurations and extensions while discovering the available roles. Cases are parameterized and the inputs are expected to have the following format:: ("more info :", ({'expected'}, {'unexpected'})) where: - ``{'expected'}`` is the set of completion item labels you expect to see returned from the completion request. Can be ``None`` which will assert that no completions are returned. - ``{'unexpected'}`` is the set of completion item labels you **do not** expect to see returned from the completion request. A common pattern where a number of different values for ``text`` should produce the same set of results within a given setup, is to make use of :func:`python:itertools.product` to generate all combinations of setups. Parameters ---------- client: The client fixture used to drive the test. text: The text providing the context of the completion request. setup: The tuple providing the rest of the setup for the test. """ expected, unexpected = setup test_uri = client.root_uri + "/test.rst" results = await completion_request(client, test_uri, text) items = {item.label for item in results.items} expected = expected or set() unexpected = unexpected or set() assert expected == items & expected assert set() == items & unexpected check.completion_items(client, results.items)
async def test_include_argument_completions(client: Client, text, setup): """Ensure that we can offer the correct filepath suggestions.""" filepath, expected, unexpected = setup test_uri = client.root_uri + f"/{filepath}" results = await completion_request(client, test_uri, text) items = {item.label for item in results.items} expected = expected or set() unexpected = unexpected or set() assert expected == items & expected assert set() == items & unexpected check.completion_items(client, results.items)
async def test_codeblock_completions(client: Client, text: str, setup): """Ensure that we can offer correct ``.. code-block::`` suggestions.""" expected, unexpected = setup test_uri = client.root_uri + "/test.rst" results = await completion_request(client, test_uri, text) items = {item.label for item in results.items} expected = expected or set() unexpected = unexpected or set() assert expected == items & expected assert set() == items & unexpected check.completion_items(client, results.items)
async def test_directive_completions( client: Client, text: str, expected: Optional[Set[str]], unexpected: Optional[Set[str]], ): test_uri = client.root_uri + "/test.rst" results = await completion_request(client, test_uri, text) items = {item.label for item in results.items} expected = expected or set() unexpected = unexpected or set() assert expected == items & expected assert set() == items & unexpected check.completion_items(client, results.items)