Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
4bcfb6c
1
Parent(s):
c4d6745
test: implementing basic tests and validating the workflow
Browse files- pytest.ini +3 -0
- tests/requirements.txt +6 -0
- tests/test_input_handling.py +57 -0
pytest.ini
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[pytest]
|
2 |
+
pythonpath = "src"
|
3 |
+
|
tests/requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# tests
|
2 |
+
pytest~=8.3.4
|
3 |
+
pytest-cov~=6.0.0
|
4 |
+
# linting
|
5 |
+
#flake8
|
6 |
+
|
tests/test_input_handling.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytest
|
2 |
+
|
3 |
+
from input_handling import is_valid_email
|
4 |
+
|
5 |
+
# generate tests for is_valid_email
|
6 |
+
# - test with valid email
|
7 |
+
# - basic email with @ and .
|
8 |
+
# - test with email with multiple .
|
9 |
+
# - test with empty email
|
10 |
+
# - test with None email
|
11 |
+
# - test with non-string email
|
12 |
+
# - test with invalid email
|
13 |
+
# - test with email without @
|
14 |
+
# - test with email without .
|
15 |
+
# - test with email without domain
|
16 |
+
# - test with email without username
|
17 |
+
# - test with email without TLD
|
18 |
+
# - test with email with multiple @
|
19 |
+
# - test with email starting with the + sign
|
20 |
+
|
21 |
+
|
22 |
+
def test_is_valid_email_valid():
|
23 |
+
assert is_valid_email("[email protected]")
|
24 |
+
assert is_valid_email("[email protected]")
|
25 |
+
assert is_valid_email("[email protected]")
|
26 |
+
assert is_valid_email("[email protected]")
|
27 |
+
assert is_valid_email("[email protected]")
|
28 |
+
|
29 |
+
def test_is_valid_email_empty():
|
30 |
+
assert not is_valid_email("")
|
31 |
+
|
32 |
+
def test_is_valid_email_none():
|
33 |
+
with pytest.raises(TypeError):
|
34 |
+
is_valid_email(None)
|
35 |
+
|
36 |
+
def test_is_valid_email_non_string():
|
37 |
+
with pytest.raises(TypeError):
|
38 |
+
is_valid_email(123)
|
39 |
+
|
40 |
+
|
41 |
+
def test_is_valid_email_invalid():
|
42 |
+
assert not is_valid_email("a.bc")
|
43 |
+
assert not is_valid_email("a@bc")
|
44 |
+
assert not is_valid_email("a.b@cc")
|
45 |
+
assert not is_valid_email("@b.cc")
|
46 |
+
assert not is_valid_email("[email protected]")
|
47 |
+
assert not is_valid_email("a@b.")
|
48 |
+
assert not is_valid_email("a@bb.")
|
49 |
+
assert not is_valid_email("[email protected].")
|
50 |
+
assert not is_valid_email("a@[email protected]")
|
51 |
+
|
52 |
+
# not sure how xfails come through the CI pipeline yet.
|
53 |
+
# maybe better to just comment out this stuff until pipeline is setup, then can check /extend
|
54 |
+
#@pytest.mark.xfail(reason="Bug identified, but while setting up CI having failing tests causes more headache")
|
55 |
+
#def test_is_valid_email_invalid_plus():
|
56 |
+
# assert not is_valid_email("[email protected]")
|
57 |
+
# assert not is_valid_email("[email protected]")
|