Skip to content

Conversation

@adamtheturtle
Copy link
Contributor

No description provided.

toctree[0][0],
[compact_paragraph, reference, 'Welcome to Sphinx Testss documentation!'],
toctree_0_0,
[compact_paragraph, reference, "Welcome to Sphinx Tests's documentation!"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

assert_node(toctree_0_0[0], reference, anchorname='')

toctree_0_1 = toctree_0[1]
assert isinstance(toctree_0_1, Element)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth extracting this to a helper. something like-

def extract_element(node: Node, *indices: int) -> Node:
    """
    Walk down a docutils node tree by repeatedly indexing children.

    Example:
        extract_element(doc, 0, 2, 1) == doc[0][2][1]
    """
    current: Node = node

    for depth, i in enumerate(indices):
        assert isinstance(current, Element), (
            f"Expected Element at depth {depth} before indexing with [{i}], "
            f"got {type(current).__name__!r}"
        )
        try:
            current = current[i]
        except IndexError as e:
            raise AssertionError(
                f"Index {i} out of range at depth {depth} for "
                f"{type(current).__name__!r}"
            ) from e

    return current

there's a lot of tests that could use something like this to resolve type issues

Copy link
Member

@AA-Turner AA-Turner Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danieleades Maybe move to tests/utils.py? Either this PR or a new one would be fine.

Edit: lost context here, thought this was one of your PRs. Would you mind making a PR to add the function?

A

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the first PR that would use this method, so makes as much sense to add it here as anywhere?

sticking in tests/utils makes sense.

failing that, i'm happy to spin up a separate PR to add this utility. I'll see what @adamtheturtle wants to do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's lots of use of the doctree_* pattern already from recent PRs.

A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants