Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
7dee860
1
Parent(s):
71dfd99
test: updated test to match interface; solved other xfail tests
Browse files- src/input/input_validator.py +4 -2
- src/whale_viewer.py +3 -0
- tests/test_input_handling.py +2 -5
- tests/test_whale_viewer.py +1 -3
src/input/input_validator.py
CHANGED
|
@@ -41,7 +41,9 @@ def is_valid_email(email:str) -> bool:
|
|
| 41 |
Returns:
|
| 42 |
bool: True if the email address is valid, False otherwise.
|
| 43 |
"""
|
| 44 |
-
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
|
|
|
|
|
|
| 45 |
return re.match(pattern, email) is not None
|
| 46 |
|
| 47 |
# Function to extract date and time from image metadata
|
|
@@ -125,4 +127,4 @@ def get_image_latlon(image_file: UploadedFile) :
|
|
| 125 |
except Exception as e: # FIXME: what types of exception?
|
| 126 |
st.warning(f"Could not extract latitude and longitude from image metadata. (file: {str(image_file)}")
|
| 127 |
|
| 128 |
-
return None, None
|
|
|
|
| 41 |
Returns:
|
| 42 |
bool: True if the email address is valid, False otherwise.
|
| 43 |
"""
|
| 44 |
+
#pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
| 45 |
+
# do not allow starting with a +
|
| 46 |
+
pattern = r'^[a-zA-Z0-9_]+[a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
| 47 |
return re.match(pattern, email) is not None
|
| 48 |
|
| 49 |
# Function to extract date and time from image metadata
|
|
|
|
| 127 |
except Exception as e: # FIXME: what types of exception?
|
| 128 |
st.warning(f"Could not extract latitude and longitude from image metadata. (file: {str(image_file)}")
|
| 129 |
|
| 130 |
+
return None, None
|
src/whale_viewer.py
CHANGED
|
@@ -115,6 +115,9 @@ def format_whale_name(whale_class:str) -> str:
|
|
| 115 |
Returns:
|
| 116 |
str: The formatted whale name with spaces instead of underscores and each word capitalized.
|
| 117 |
"""
|
|
|
|
|
|
|
|
|
|
| 118 |
whale_name = whale_class.replace("_", " ").title()
|
| 119 |
return whale_name
|
| 120 |
|
|
|
|
| 115 |
Returns:
|
| 116 |
str: The formatted whale name with spaces instead of underscores and each word capitalized.
|
| 117 |
"""
|
| 118 |
+
if not isinstance(whale_class, str):
|
| 119 |
+
raise TypeError("whale_class should be a string.")
|
| 120 |
+
|
| 121 |
whale_name = whale_class.replace("_", " ").title()
|
| 122 |
return whale_name
|
| 123 |
|
tests/test_input_handling.py
CHANGED
|
@@ -51,9 +51,6 @@ def test_is_valid_email_invalid():
|
|
| 51 |
assert not is_valid_email("a@b.cc.")
|
| 52 |
assert not is_valid_email("a@b@c.d")
|
| 53 |
|
| 54 |
-
# not sure how xfails come through the CI pipeline yet.
|
| 55 |
-
# maybe better to just comment out this stuff until pipeline is setup, then can check /extend
|
| 56 |
-
@pytest.mark.xfail(reason="Bug identified, but while setting up CI having failing tests causes more headache")
|
| 57 |
def test_is_valid_email_invalid_plus():
|
| 58 |
assert not is_valid_email("+@test.com")
|
| 59 |
assert not is_valid_email("+oneuse@test.com")
|
|
@@ -143,7 +140,7 @@ def test_get_image_latlon():
|
|
| 143 |
|
| 144 |
# missing GPS loc
|
| 145 |
f2 = test_data_pth / 'cakes_no_exif_gps.jpg'
|
| 146 |
-
assert get_image_latlon(f2) == None
|
| 147 |
|
| 148 |
# missng datetime -> expect gps not affected
|
| 149 |
f3 = test_data_pth / 'cakes_no_exif_datetime.jpg'
|
|
@@ -151,7 +148,7 @@ def test_get_image_latlon():
|
|
| 151 |
|
| 152 |
# tests for get_image_latlon with empty file
|
| 153 |
def test_get_image_latlon_empty():
|
| 154 |
-
assert get_image_latlon("") == None
|
| 155 |
|
| 156 |
# tests for decimal_coords
|
| 157 |
# - without input, py raises TypeError
|
|
|
|
| 51 |
assert not is_valid_email("a@b.cc.")
|
| 52 |
assert not is_valid_email("a@b@c.d")
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
def test_is_valid_email_invalid_plus():
|
| 55 |
assert not is_valid_email("+@test.com")
|
| 56 |
assert not is_valid_email("+oneuse@test.com")
|
|
|
|
| 140 |
|
| 141 |
# missing GPS loc
|
| 142 |
f2 = test_data_pth / 'cakes_no_exif_gps.jpg'
|
| 143 |
+
assert get_image_latlon(f2) == (None, None)
|
| 144 |
|
| 145 |
# missng datetime -> expect gps not affected
|
| 146 |
f3 = test_data_pth / 'cakes_no_exif_datetime.jpg'
|
|
|
|
| 148 |
|
| 149 |
# tests for get_image_latlon with empty file
|
| 150 |
def test_get_image_latlon_empty():
|
| 151 |
+
assert get_image_latlon("") == (None, None)
|
| 152 |
|
| 153 |
# tests for decimal_coords
|
| 154 |
# - without input, py raises TypeError
|
tests/test_whale_viewer.py
CHANGED
|
@@ -40,11 +40,9 @@ def test_format_whale_name_empty():
|
|
| 40 |
assert format_whale_name("") == ""
|
| 41 |
|
| 42 |
# testing with the wrong datatype
|
| 43 |
-
# we should get a TypeError - currently it fails with a AttributeError
|
| 44 |
-
@pytest.mark.xfail
|
| 45 |
def test_format_whale_name_none():
|
| 46 |
with pytest.raises(TypeError):
|
| 47 |
format_whale_name(None)
|
| 48 |
|
| 49 |
|
| 50 |
-
# display_whale requires UI to test it.
|
|
|
|
| 40 |
assert format_whale_name("") == ""
|
| 41 |
|
| 42 |
# testing with the wrong datatype
|
|
|
|
|
|
|
| 43 |
def test_format_whale_name_none():
|
| 44 |
with pytest.raises(TypeError):
|
| 45 |
format_whale_name(None)
|
| 46 |
|
| 47 |
|
| 48 |
+
# display_whale requires UI to test it.
|