Skip to content

Commit

Permalink
test: using src/apptest subdir for the test harnesses
Browse files Browse the repository at this point in the history
- streamlit executes ok like this
- pytest executes ok like this
- couldn't get the same results from the tests directory unfortunately.
  • Loading branch information
rmm-ch committed Jan 17, 2025
1 parent 00921cc commit eaa1c71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Empty file added src/__init__.py
Empty file.
12 changes: 11 additions & 1 deletion src/demo_wv.py → src/apptest/demo_wv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@
# - TODO: find a cleaner solution for organisation (maybe just config to pytest?)

import streamlit as st
import whale_viewer as sw_wv

# to run streamlit from this subdir, we need the the src dir on the path
# NOTE: pytest doesn't need this to run the tests, but to develop the test
# harness is hard without running streamlit
import sys
from os import path
# src (parent from here)
src_dir = path.dirname( path.dirname( path.abspath(__file__) ) )
sys.path.append(src_dir)


import whale_viewer as sw_wv

# a menu to pick one of the images
title = st.title("Whale Viewer testing")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_demo_wv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_selectbox_ok():
- finally, we check there are the right number of options (26)
'''
at = AppTest.from_file("src/demo_wv.py").run()
at = AppTest.from_file("src/apptest/demo_wv.py").run()
assert len(at.selectbox) == 1
assert at.selectbox[0].value == "beluga"
assert at.selectbox[0].index == 0
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_img_props():
- then changing the image, we do the same checks again
'''
at = AppTest.from_file("src/demo_wv.py").run()
at = AppTest.from_file("src/apptest/demo_wv.py").run()
ix = 0 # we didn't interact with the dropdown, so it should be the first one
# could fetch the property - maybe better in case code example changes
ix = at.selectbox[0].index
Expand Down

0 comments on commit eaa1c71

Please sign in to comment.