Spaces:
Build error
Build error
rmm commited on
Commit ·
c09e385
1
Parent(s): b008f47
test: updated to test behaviour according to debug flag state
Browse files
src/input/input_handling.py
CHANGED
|
@@ -28,9 +28,15 @@ def _is_str_true(v:str) -> bool:
|
|
| 28 |
''' convert a string to boolean: if contains True or 1 (or yes), return True '''
|
| 29 |
# https://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python
|
| 30 |
return v.lower() in ("yes", "true", "t", "1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# an arbitrary set of defaults so testing is less painful...
|
| 32 |
# ideally we add in some randomization to the defaults
|
| 33 |
-
dbg_populate_metadata =
|
|
|
|
| 34 |
# the other main option would be argparse, where we can run `streamlit run src/main.py -- --debug` or similar
|
| 35 |
# - I think env vars are simple and clean enough, it isn't really a CLI that we want to offer debug options, it is for dev.
|
| 36 |
if dbg_populate_metadata:
|
|
|
|
| 28 |
''' convert a string to boolean: if contains True or 1 (or yes), return True '''
|
| 29 |
# https://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python
|
| 30 |
return v.lower() in ("yes", "true", "t", "1")
|
| 31 |
+
|
| 32 |
+
def load_debug_autopopulate() -> bool:
|
| 33 |
+
return _is_str_true( os.getenv("DEBUG_AUTOPOPULATE_METADATA", "False"))
|
| 34 |
+
|
| 35 |
+
|
| 36 |
# an arbitrary set of defaults so testing is less painful...
|
| 37 |
# ideally we add in some randomization to the defaults
|
| 38 |
+
dbg_populate_metadata = load_debug_autopopulate()
|
| 39 |
+
|
| 40 |
# the other main option would be argparse, where we can run `streamlit run src/main.py -- --debug` or similar
|
| 41 |
# - I think env vars are simple and clean enough, it isn't really a CLI that we want to offer debug options, it is for dev.
|
| 42 |
if dbg_populate_metadata:
|
tests/test_demo_input_sidebar.py
CHANGED
|
@@ -3,6 +3,7 @@ from pathlib import Path
|
|
| 3 |
from io import BytesIO
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
|
| 7 |
import pytest
|
| 8 |
from unittest.mock import MagicMock, patch
|
|
@@ -12,7 +13,7 @@ import time
|
|
| 12 |
|
| 13 |
from input.input_handling import spoof_metadata
|
| 14 |
from input.input_observation import InputObservation
|
| 15 |
-
from input.input_handling import buffer_uploaded_files
|
| 16 |
|
| 17 |
from streamlit.runtime.uploaded_file_manager import UploadedFile
|
| 18 |
|
|
@@ -184,7 +185,13 @@ def test_no_input_no_interaction():
|
|
| 184 |
at = AppTest.from_file(SCRIPT_UNDER_TEST, default_timeout=10).run()
|
| 185 |
verify_initial_session_state(at)
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
# print (f"[I] whole tree: {at._tree}")
|
| 190 |
# for elem in at.sidebar.markdown:
|
|
|
|
| 3 |
from io import BytesIO
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
import pytest
|
| 9 |
from unittest.mock import MagicMock, patch
|
|
|
|
| 13 |
|
| 14 |
from input.input_handling import spoof_metadata
|
| 15 |
from input.input_observation import InputObservation
|
| 16 |
+
from input.input_handling import buffer_uploaded_files, load_debug_autopopulate
|
| 17 |
|
| 18 |
from streamlit.runtime.uploaded_file_manager import UploadedFile
|
| 19 |
|
|
|
|
| 185 |
at = AppTest.from_file(SCRIPT_UNDER_TEST, default_timeout=10).run()
|
| 186 |
verify_initial_session_state(at)
|
| 187 |
|
| 188 |
+
dbg = load_debug_autopopulate()
|
| 189 |
+
#var = at.session_state.input_author_email
|
| 190 |
+
#_cprint(f"[I] input email is '{var}' type: {type(var)} | is None? {var is None} | {dbg}", PURPLE)
|
| 191 |
+
if dbg: # autopopulated
|
| 192 |
+
assert at.session_state.input_author_email == spoof_metadata.get("author_email")
|
| 193 |
+
else: # should be empty, the user has to fill it in
|
| 194 |
+
assert at.session_state.input_author_email == ""
|
| 195 |
|
| 196 |
# print (f"[I] whole tree: {at._tree}")
|
| 197 |
# for elem in at.sidebar.markdown:
|
tests/test_demo_multifile_upload.py
CHANGED
|
@@ -26,7 +26,7 @@ from streamlit.testing.v1 import AppTest
|
|
| 26 |
|
| 27 |
|
| 28 |
# for expectations
|
| 29 |
-
from input.input_handling import spoof_metadata
|
| 30 |
from input.input_validator import get_image_datetime, get_image_latlon
|
| 31 |
|
| 32 |
|
|
@@ -137,7 +137,11 @@ def test_no_input_no_interaction():
|
|
| 137 |
|
| 138 |
at = AppTest.from_file("src/apptest/demo_multifile_upload.py").run()
|
| 139 |
assert at.session_state.observations == {}
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
def test_bad_email():
|
| 143 |
with patch.dict(spoof_metadata, {"author_email": "notanemail"}):
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
# for expectations
|
| 29 |
+
from input.input_handling import spoof_metadata, load_debug_autopopulate
|
| 30 |
from input.input_validator import get_image_datetime, get_image_latlon
|
| 31 |
|
| 32 |
|
|
|
|
| 137 |
|
| 138 |
at = AppTest.from_file("src/apptest/demo_multifile_upload.py").run()
|
| 139 |
assert at.session_state.observations == {}
|
| 140 |
+
dbg = load_debug_autopopulate()
|
| 141 |
+
if dbg: # autopopulated
|
| 142 |
+
assert at.session_state.input_author_email == spoof_metadata.get("author_email")
|
| 143 |
+
else: # should be empty, the user has to fill it in
|
| 144 |
+
assert at.session_state.input_author_email == ""
|
| 145 |
|
| 146 |
def test_bad_email():
|
| 147 |
with patch.dict(spoof_metadata, {"author_email": "notanemail"}):
|