Skip to content

AppTest coverage for a KwargsInput source of a MultiSourceInput (and _file_uploaders recursion into it) #32

Closed

Description

@thorwhalen

i2mint/front#45 (fixed by i2mint/front#49) made a KwargsInput usable as one of the sources of a MultiSourceInput: the section now feeds its input specs to that nested kwargs input. front has a unit test with minimal concrete elements, but streamlitfront has no AppTest for this shape, and the recursion of _file_uploaders into a kwargs input's _exec_section (when that kwargs input sits inside a multi-source input) is still untested.

Starter (verified to pass against front master once #49 is merged):

from streamlit.testing.v1 import AppTest

APP = '''
from i2 import Sig
from front import APP_KEY, RENDERING_KEY, ELEMENT_KEY
from streamlitfront import mk_app
from streamlitfront.elements import FileUploader, MultiSourceInput, TextOutput, KwargsInput

def g(a: int = 1, b: str = "x"): ...
def f(data): return repr(data)

mk_app([f], config={
    APP_KEY: {"title": "t"},
    RENDERING_KEY: {"f": {"execution": {
        "inputs": {"data": {
            ELEMENT_KEY: MultiSourceInput,
            "From files": {ELEMENT_KEY: FileUploader},
            "From params": {ELEMENT_KEY: KwargsInput, "func_sig": Sig(g)},
        }},
        "output": {ELEMENT_KEY: TextOutput},
    }}},
})()
'''

def test_kwargs_source_of_multi_source_input():
    at = AppTest.from_string(APP, default_timeout=30).run()
    at.selectbox[0].select("From params").run()
    at.number_input[0].set_value(5).run()
    at.text_input[0].set_value("hi").run()
    at.button[0].click().run()
    assert not at.exception
    assert "{'a': 5, 'b': 'hi'}" in [m.value for m in at.markdown]

Add it to tests/ (reusing the _isolate_default_convention fixture of tests/test_file_uploader_clear.py), plus a variant where the kwargs source has a parameter rendered as a FileUploader, to cover _file_uploaders clearing it after submit.

🤖 Generated with Claude Code

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions