Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
2d694a6
1
Parent(s):
821ac40
fix: env variable defines whether fields autopopulated
Browse files- for the CI tests, the env variable is set too, so the tests pass
- next step requires tests updated to cope (visual tests can fill the
fields to simulate the user)
.github/workflows/python-pycov-onPR.yml
CHANGED
@@ -27,7 +27,7 @@ jobs:
|
|
27 |
# note this will run all non-visual tests, including the slow end2end ones
|
28 |
# - this action is only on PR; the slow ones are skipped on push.
|
29 |
run: |
|
30 |
-
pytest -s -m "not visual" --ignore=tests/visual_selenium --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests/ | tee pytest-coverage.txt
|
31 |
echo "working dir:" && pwd
|
32 |
echo "files in cwd:" && ls -ltr
|
33 |
|
|
|
27 |
# note this will run all non-visual tests, including the slow end2end ones
|
28 |
# - this action is only on PR; the slow ones are skipped on push.
|
29 |
run: |
|
30 |
+
DEBUG_AUTOPOPULATE_METADATA=True pytest -s -m "not visual" --ignore=tests/visual_selenium --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests/ | tee pytest-coverage.txt
|
31 |
echo "working dir:" && pwd
|
32 |
echo "files in cwd:" && ls -ltr
|
33 |
|
.github/workflows/python-pytest.yml
CHANGED
@@ -33,4 +33,7 @@ jobs:
|
|
33 |
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
34 |
- name: Run quick tests with pytest
|
35 |
run: |
|
36 |
-
pytest -m "not slow and not visual" --strict-markers --ignore=tests/visual_selenium
|
|
|
|
|
|
|
|
33 |
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
34 |
- name: Run quick tests with pytest
|
35 |
run: |
|
36 |
+
DEBUG_AUTOPOPULATE_METADATA=True pytest -m "not slow and not visual" --strict-markers --ignore=tests/visual_selenium
|
37 |
+
|
38 |
+
# first pass: the visual tests that are looking for metadata to be populated already pass with this debug flag.
|
39 |
+
# todo: expand tests to enter the metadata, which will allow progress through the phases.
|
.github/workflows/python-visualtests.yml
CHANGED
@@ -50,4 +50,6 @@ jobs:
|
|
50 |
# we use --demo to make it slow enough (selenium doesn't wait long enough
|
51 |
# otherwise, not one step it consistently fails at.)
|
52 |
run: |
|
53 |
-
pytest -m "visual" --strict-markers tests/visual_selenium/ -s --demo
|
|
|
|
|
|
50 |
# we use --demo to make it slow enough (selenium doesn't wait long enough
|
51 |
# otherwise, not one step it consistently fails at.)
|
52 |
run: |
|
53 |
+
DEBUG_AUTOPOPULATE_METADATA=True pytest -m "visual" --strict-markers tests/visual_selenium/ -s --demo
|
54 |
+
|
55 |
+
# DEBUG_AUTOPOPULATE_METADATA=True streamlit run src/main.py
|
src/input/input_handling.py
CHANGED
@@ -2,6 +2,7 @@ from typing import List, Tuple
|
|
2 |
import datetime
|
3 |
import logging
|
4 |
import hashlib
|
|
|
5 |
|
6 |
import streamlit as st
|
7 |
from streamlit.delta_generator import DeltaGenerator
|
@@ -23,15 +24,25 @@ both the UI elements (setup_input_UI) and the validation functions.
|
|
23 |
'''
|
24 |
allowed_image_types = ['jpg', 'jpeg', 'png', 'webp']
|
25 |
|
|
|
|
|
|
|
|
|
26 |
# an arbitrary set of defaults so testing is less painful...
|
27 |
# ideally we add in some randomization to the defaults
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def check_inputs_are_set(empty_ok:bool=False, debug:bool=False) -> bool:
|
37 |
"""
|
@@ -190,10 +201,11 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
190 |
msg = f"[D] {filename}: lat, lon from image metadata: {latitude0}, {longitude0}"
|
191 |
m_logger.debug(msg)
|
192 |
|
193 |
-
if
|
194 |
-
latitude0:
|
195 |
-
|
196 |
-
longitude0
|
|
|
197 |
|
198 |
image = st.session_state.images.get(image_hash, None)
|
199 |
# add the UI elements
|
|
|
2 |
import datetime
|
3 |
import logging
|
4 |
import hashlib
|
5 |
+
import os
|
6 |
|
7 |
import streamlit as st
|
8 |
from streamlit.delta_generator import DeltaGenerator
|
|
|
24 |
'''
|
25 |
allowed_image_types = ['jpg', 'jpeg', 'png', 'webp']
|
26 |
|
27 |
+
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 = _is_str_true( os.getenv("DEBUG_AUTOPOPULATE_METADATA", "False"))
|
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:
|
37 |
+
spoof_metadata = {
|
38 |
+
"latitude": 0.5,
|
39 |
+
"longitude": 44,
|
40 |
+
"author_email": "[email protected]",
|
41 |
+
"date": None,
|
42 |
+
"time": None,
|
43 |
+
}
|
44 |
+
else:
|
45 |
+
spoof_metadata = {}
|
46 |
|
47 |
def check_inputs_are_set(empty_ok:bool=False, debug:bool=False) -> bool:
|
48 |
"""
|
|
|
201 |
msg = f"[D] {filename}: lat, lon from image metadata: {latitude0}, {longitude0}"
|
202 |
m_logger.debug(msg)
|
203 |
|
204 |
+
if spoof_metadata:
|
205 |
+
if latitude0 is None: # get some default values if not found in exifdata
|
206 |
+
latitude0:float = spoof_metadata.get('latitude', 0) + dbg_ix
|
207 |
+
if longitude0 is None:
|
208 |
+
longitude0:float = spoof_metadata.get('longitude', 0) - dbg_ix
|
209 |
|
210 |
image = st.session_state.images.get(image_hash, None)
|
211 |
# add the UI elements
|