Skip to content

provide typing.Protocol for dash_duo #2170

Description

@janosh

Is your feature request related to a problem? Please describe.

The DX for using the pytest fixture dash.testing.plugin.dash_duo() could be improved by providing a typing.Protocol to type hint available methods and their signatures.

Describe the solution you'd like

from typing import Protocol

import dash
from dash.testing.application_runners import import_app
from dash.testing.wait import wait_for_element_by_css_selector, wait_for_text_to_equal


class DashDuo(Protocol):
    "The dash_duo pytest fixture lives in dash.testing.plugin.dash_duo."

    def start_server(self, start_server) -> None:
        ...

    def find_element(self, selector: str) -> dash.development.base_component.Component:
        ...


def test_example_app(dash_duo: DashDuo):  # type hint for dash_duo enables auto-complete
    app = import_app("example")
    dash_duo.start_server(app)

    my_component = dash_duo.find_element("#hello-world")

    assert "my-value" == my_component.get_attribute("value")

    ....

Screenshot from VS Code showing auto-complete in action

Screen Shot 2022-07-27 at 11 11 43

Describe alternatives you've considered

None

Activity

  1. alexcjohnson commented on Aug 1, 2022

    @alexcjohnson
    Collaborator

    Seems reasonable, @T4rk1n you've worked on typing for dash.testing a bit, any thoughts? Will it be possible to have this picked up automatically by VSCode when dash_duo is used as a pytest fixture, or will you still need to import a DashDuo and annotate every dash_duo?

  2. janosh commented on Aug 1, 2022

    @janosh
    Author

    You would have to annotate every single use of dash_duo unless you had some extension like pytest-fixtures installed.

  3. T4rk1n commented on Aug 1, 2022

    @T4rk1n
    Contributor

    Pycharm pick it up by default, not a vscode user so I don't know about it, but seems like the plugin would work?

  4. janosh commented on Aug 1, 2022

    @janosh
    Author

    I made a rough start over here if you want to pick up from that. Or maybe DashDuo can be auto-generated?

  5. kostyafarber commented on Oct 10, 2022

    @kostyafarber

    Hi this sounds interesting. Happy to pick it up with some guidance. Thanks.

  6. self-assigned this
    on Jul 24, 2024
  7. removed their assignment
    on Aug 2, 2024
  8. changed the title [-][Feature Request] `typing.Protocol` for `dash_duo`[/-] [+]provide `typing.Protocol` for `dash_duo`[/+] on Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogfeaturesomething new

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions