Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
c860c9c
1
Parent(s):
d1d63ea
fix: all usage of session_state.files explicitly a list now
Browse files- init was to a dict, then overwritten by a list,
- all access was treating as a list
src/apptest/demo_elements.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
# a small library of elements used in testing, presenting some
|
2 |
# processed data in simple ways that are easily testable via AppTest
|
|
|
3 |
import streamlit as st
|
4 |
from input.input_handling import (
|
5 |
get_image_datetime, get_image_latlon
|
@@ -14,7 +15,7 @@ def show_uploaded_file_info():
|
|
14 |
|
15 |
st.write("the buffered files:")
|
16 |
|
17 |
-
uploaded_files = st.session_state.file_uploader_data
|
18 |
for ix, file in enumerate(uploaded_files):
|
19 |
image_datetime_raw = get_image_datetime(file)
|
20 |
latitude0, longitude0 = get_image_latlon(file)
|
|
|
1 |
# a small library of elements used in testing, presenting some
|
2 |
# processed data in simple ways that are easily testable via AppTest
|
3 |
+
from typing import List
|
4 |
import streamlit as st
|
5 |
from input.input_handling import (
|
6 |
get_image_datetime, get_image_latlon
|
|
|
15 |
|
16 |
st.write("the buffered files:")
|
17 |
|
18 |
+
uploaded_files:List = st.session_state.file_uploader_data
|
19 |
for ix, file in enumerate(uploaded_files):
|
20 |
image_datetime_raw = get_image_datetime(file)
|
21 |
latitude0, longitude0 = get_image_latlon(file)
|
src/apptest/demo_multifile_upload.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# a minimal snippet for validating the upload sequence, for testing purposes (with AppTest)
|
2 |
-
|
3 |
import streamlit as st
|
4 |
|
5 |
# to run streamlit from this subdir, we need the the src dir on the path
|
@@ -26,7 +26,7 @@ from input.input_handling import (
|
|
26 |
|
27 |
def buffer_uploaded_files():
|
28 |
st.write("buffering files! ")
|
29 |
-
uploaded_files = st.session_state.file_uploader_data
|
30 |
for ix, file in enumerate(uploaded_files):
|
31 |
image_datetime_raw = get_image_datetime(file)
|
32 |
latitude0, longitude0 = get_image_latlon(file)
|
|
|
1 |
# a minimal snippet for validating the upload sequence, for testing purposes (with AppTest)
|
2 |
+
from typing import List
|
3 |
import streamlit as st
|
4 |
|
5 |
# to run streamlit from this subdir, we need the the src dir on the path
|
|
|
26 |
|
27 |
def buffer_uploaded_files():
|
28 |
st.write("buffering files! ")
|
29 |
+
uploaded_files:List = st.session_state.file_uploader_data
|
30 |
for ix, file in enumerate(uploaded_files):
|
31 |
image_datetime_raw = get_image_datetime(file)
|
32 |
latitude0, longitude0 = get_image_latlon(file)
|
src/input/input_handling.py
CHANGED
@@ -116,7 +116,7 @@ def buffer_uploaded_files():
|
|
116 |
|
117 |
|
118 |
# get files from state
|
119 |
-
uploaded_files = st.session_state.file_uploader_data
|
120 |
|
121 |
filenames = []
|
122 |
images = {}
|
@@ -261,7 +261,7 @@ def _setup_dynamic_inputs() -> None:
|
|
261 |
# - and these go into session state
|
262 |
|
263 |
# load the files from the session state
|
264 |
-
uploaded_files = st.session_state.files
|
265 |
hashes = st.session_state.image_hashes
|
266 |
#images = st.session_state.images
|
267 |
observations = {}
|
@@ -368,7 +368,7 @@ def init_input_data_session_states() -> None:
|
|
368 |
st.session_state.images = {}
|
369 |
|
370 |
if "files" not in st.session_state:
|
371 |
-
st.session_state.files =
|
372 |
|
373 |
if "public_observations" not in st.session_state:
|
374 |
st.session_state.public_observations = {}
|
|
|
116 |
|
117 |
|
118 |
# get files from state
|
119 |
+
uploaded_files:List = st.session_state.file_uploader_data
|
120 |
|
121 |
filenames = []
|
122 |
images = {}
|
|
|
261 |
# - and these go into session state
|
262 |
|
263 |
# load the files from the session state
|
264 |
+
uploaded_files:List = st.session_state.files
|
265 |
hashes = st.session_state.image_hashes
|
266 |
#images = st.session_state.images
|
267 |
observations = {}
|
|
|
368 |
st.session_state.images = {}
|
369 |
|
370 |
if "files" not in st.session_state:
|
371 |
+
st.session_state.files = []
|
372 |
|
373 |
if "public_observations" not in st.session_state:
|
374 |
st.session_state.public_observations = {}
|
tests/test_demo_input_sidebar.py
CHANGED
@@ -58,7 +58,6 @@ def _cprint(msg:str, color:str=OKCYAN):
|
|
58 |
|
59 |
TIMEOUT = 10
|
60 |
#SCRIPT_UNDER_TEST = "src/main.py"
|
61 |
-
#SCRIPT_UNDER_TEST = "src/apptest/demo_input_phase.py"
|
62 |
SCRIPT_UNDER_TEST = "src/apptest/demo_input_sidebar.py"
|
63 |
|
64 |
def verify_initial_session_state(at:AppTest):
|
@@ -68,12 +67,12 @@ def verify_initial_session_state(at:AppTest):
|
|
68 |
# - observations {}
|
69 |
# - image_hashes []
|
70 |
# - images {}
|
71 |
-
# - files
|
72 |
# - public_observations {}
|
73 |
assert at.session_state.observations == {}
|
74 |
assert at.session_state.image_hashes == []
|
75 |
assert at.session_state.images == {}
|
76 |
-
assert at.session_state.files ==
|
77 |
assert at.session_state.public_observations == {}
|
78 |
assert "container_file_uploader" in at.session_state
|
79 |
assert "container_metadata_inputs" in at.session_state
|
@@ -87,27 +86,8 @@ def test_no_input_no_interaction():
|
|
87 |
# -> not much on the main tab.
|
88 |
|
89 |
at = AppTest.from_file(SCRIPT_UNDER_TEST, default_timeout=10).run()
|
90 |
-
|
91 |
-
|
92 |
-
else:
|
93 |
-
# the initialised states we expect
|
94 |
-
# - container_file_uploader exists
|
95 |
-
# - container_metadata_inputs exists
|
96 |
-
# - observations {}
|
97 |
-
# - image_hashes []
|
98 |
-
# - image_filenames []
|
99 |
-
# - images {}
|
100 |
-
# - files {}
|
101 |
-
# - public_observations {}
|
102 |
-
assert at.session_state.observations == {}
|
103 |
-
assert at.session_state.image_filenames == []
|
104 |
-
assert at.session_state.image_hashes == []
|
105 |
-
assert at.session_state.images == {}
|
106 |
-
assert at.session_state.files == {}
|
107 |
-
assert at.session_state.public_observations == {}
|
108 |
-
assert "container_file_uploader" in at.session_state
|
109 |
-
assert "container_metadata_inputs" in at.session_state
|
110 |
-
|
111 |
assert at.session_state.input_author_email == spoof_metadata.get("author_email")
|
112 |
|
113 |
# print (f"[I] whole tree: {at._tree}")
|
@@ -120,6 +100,8 @@ def test_no_input_no_interaction():
|
|
120 |
# in the sidebar, we have the progress indicator, then the fileuploader and metadata inputs
|
121 |
# - annoyingly we can't use keys for markdown.
|
122 |
# - so we are sensitive to the order.
|
|
|
|
|
123 |
assert "Progress: 0/5" in at.sidebar.markdown[0].value
|
124 |
assert "st-key-container_file_uploader_id" in at.sidebar.markdown[1].value
|
125 |
assert "st-key-container_metadata_inputs_id" in at.sidebar.markdown[2].value
|
@@ -157,7 +139,6 @@ def test_two_input_files_realdata(mock_file_rv: MagicMock, mock_uploadedFile_Lis
|
|
157 |
|
158 |
# Set the return value of the mocked file_uploader to the list of mock files
|
159 |
mock_file_rv.return_value = mock_files
|
160 |
-
#mock_file_rv.side_effect = wrapped_buffer_uploaded_files # not yet!...
|
161 |
|
162 |
# Run the Streamlit app
|
163 |
at = AppTest.from_file(SCRIPT_UNDER_TEST, default_timeout=TIMEOUT).run()
|
@@ -180,7 +161,7 @@ def test_two_input_files_realdata(mock_file_rv: MagicMock, mock_uploadedFile_Lis
|
|
180 |
# - observations 2 elements, keys -> some hashes. values: InputObservation objects
|
181 |
# - image_hashes 2 elements, hashes (str) |
|
182 |
# - images {} 2 elements, keys -> hashes, values -> np.ndarray.
|
183 |
-
# - files
|
184 |
# x public_observations {}
|
185 |
# I think just verify the sizes and types, we could do a data integrity
|
186 |
# check on the hashes matching everywhere, but that is far from visual.
|
|
|
58 |
|
59 |
TIMEOUT = 10
|
60 |
#SCRIPT_UNDER_TEST = "src/main.py"
|
|
|
61 |
SCRIPT_UNDER_TEST = "src/apptest/demo_input_sidebar.py"
|
62 |
|
63 |
def verify_initial_session_state(at:AppTest):
|
|
|
67 |
# - observations {}
|
68 |
# - image_hashes []
|
69 |
# - images {}
|
70 |
+
# - files []
|
71 |
# - public_observations {}
|
72 |
assert at.session_state.observations == {}
|
73 |
assert at.session_state.image_hashes == []
|
74 |
assert at.session_state.images == {}
|
75 |
+
assert at.session_state.files == []
|
76 |
assert at.session_state.public_observations == {}
|
77 |
assert "container_file_uploader" in at.session_state
|
78 |
assert "container_metadata_inputs" in at.session_state
|
|
|
86 |
# -> not much on the main tab.
|
87 |
|
88 |
at = AppTest.from_file(SCRIPT_UNDER_TEST, default_timeout=10).run()
|
89 |
+
verify_initial_session_state(at)
|
90 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
assert at.session_state.input_author_email == spoof_metadata.get("author_email")
|
92 |
|
93 |
# print (f"[I] whole tree: {at._tree}")
|
|
|
100 |
# in the sidebar, we have the progress indicator, then the fileuploader and metadata inputs
|
101 |
# - annoyingly we can't use keys for markdown.
|
102 |
# - so we are sensitive to the order.
|
103 |
+
# - we could grab all the text, and just be content with presence of the target strings
|
104 |
+
# anywhere in the sidebar? that would be more robust at least.
|
105 |
assert "Progress: 0/5" in at.sidebar.markdown[0].value
|
106 |
assert "st-key-container_file_uploader_id" in at.sidebar.markdown[1].value
|
107 |
assert "st-key-container_metadata_inputs_id" in at.sidebar.markdown[2].value
|
|
|
139 |
|
140 |
# Set the return value of the mocked file_uploader to the list of mock files
|
141 |
mock_file_rv.return_value = mock_files
|
|
|
142 |
|
143 |
# Run the Streamlit app
|
144 |
at = AppTest.from_file(SCRIPT_UNDER_TEST, default_timeout=TIMEOUT).run()
|
|
|
161 |
# - observations 2 elements, keys -> some hashes. values: InputObservation objects
|
162 |
# - image_hashes 2 elements, hashes (str) |
|
163 |
# - images {} 2 elements, keys -> hashes, values -> np.ndarray.
|
164 |
+
# - files [] a list of 2 MockUploadedFile objects
|
165 |
# x public_observations {}
|
166 |
# I think just verify the sizes and types, we could do a data integrity
|
167 |
# check on the hashes matching everywhere, but that is far from visual.
|