Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elements within "expandables" containers are not visible in ElementTree #8089

Closed
3 of 4 tasks
Asaurus1 opened this issue Feb 6, 2024 · 5 comments
Closed
3 of 4 tasks

Comments

@Asaurus1
Copy link
Contributor

Asaurus1 commented Feb 6, 2024

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

AppTest does not seem to capture elements created inside of expandables like st.status or st.expander. As mentioned in #7719, there's currently no public API for expander or status elements in AppTest but, even when accessed via AppTest.get('expandables')[0] there are no elements captured inside of the expandable element.

Reproducible Code Example

def test_status():
    from streamlit.testing.v1 import AppTest

    at = AppTest.from_string("import streamlit as st\nst.status().error('foo')")
    at.run()

    assert at.error[0].value == "foo"

also

def test_status():
    from streamlit.testing.v1 import AppTest

    at = AppTest.from_string("import streamlit as st\nst.expander().error('foo')")
    at.run()

    assert at.get('expandables')[0].error[0].value == "foo"

Steps To Reproduce

Run the function in streamlit 1.30.0+

Expected Behavior

Should behave like the following and raise no exception.

def test_status():
    from streamlit.testing.v1 import AppTest

    at = AppTest.from_string("import streamlit as st\nst.empty().error('foo')")
    at.run()

    assert at.error[0].value == "foo"

Current Behavior

IndexError on at.error[0]

Even if you change the final line to at.get('expandables')[0].error[0] you still get an IndexError on .error[0]. There doesn't seem to be any work-around for getting elements drawn inside expanders at the AppTest interface.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.30.0
  • Python version: 3.11.4
  • Operating System: Independent
  • Browser: N/A

Additional Information

No response

@Asaurus1 Asaurus1 added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Feb 6, 2024
Copy link

github-actions bot commented Feb 6, 2024

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@kajarenc
Copy link
Collaborator

kajarenc commented Feb 6, 2024

thanks, @Asaurus1 for opening this issue!

@AnOctopus I think for the current version elements inside expendables are not reachable, and it is an expected behavior, is that correct?

@kajarenc kajarenc added priority:P3 and removed status:needs-triage Has not been triaged by the Streamlit team labels Feb 6, 2024
@Asaurus1
Copy link
Contributor Author

Asaurus1 commented Feb 6, 2024

I'm going to close this as fixed --- it seems to work just fine if I actually write my tests properly, e.g.

def test_status():
    from streamlit.testing.v1 import AppTest

    at = AppTest.from_string("import streamlit as st\nst.status(label='WITH PROPER ARGUMENTS FOR THE FUNCTION CALLS').error('foo')")
    at.run()

    assert at.error[0].value == "foo"

@Asaurus1 Asaurus1 closed this as completed Feb 6, 2024
@Asaurus1
Copy link
Contributor Author

Asaurus1 commented Feb 6, 2024

@AnOctopus Re-opening since I have determined a more specific bug. It seems that calling ".update()" on a status element clears it's contents. Parse_tree_from_messages probably just needs a a special case to handle these update messages without replacing the element entirely.

I'll update the first post when I'm back on a keyboard. I'm also not sure if #7923 fixes this or not, I will have to do some testing

To reproduce:

def test_status():
    from streamlit.testing.v1 import AppTest

    at = AppTest.from_string("import streamlit as st\nsts=st.status('bar')\nsts.error('foo')\nsts.update(state='complete')")
    at.run()

    assert at.error[0].value == "foo"

@Asaurus1 Asaurus1 reopened this Feb 6, 2024
@Asaurus1
Copy link
Contributor Author

Asaurus1 commented Feb 6, 2024

It seems like #7923 does fix this.

@Asaurus1 Asaurus1 closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants