Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
6af1379
1
Parent(s):
bd65a2f
test: added tests for number validator, and one xfail for email
Browse files- with the xfail I want to see how GH-actions reports it. (marking this
way declares that "it's a known bug", basically; so ideally we retain
the green tick. In this case, it's an easy fix.)
.github/workflows/python-pytest.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
2 |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
3 |
|
4 |
-
name:
|
5 |
|
6 |
on:
|
7 |
push:
|
|
|
1 |
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
2 |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
3 |
|
4 |
+
name: Execute tests with pytest
|
5 |
|
6 |
on:
|
7 |
push:
|
tests/test_input_handling.py
CHANGED
@@ -1,6 +1,7 @@
|
|
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
|
@@ -51,7 +52,57 @@ def test_is_valid_email_invalid():
|
|
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 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pytest
|
2 |
|
3 |
from input_handling import is_valid_email
|
4 |
+
from input_handling import is_valid_number
|
5 |
|
6 |
# generate tests for is_valid_email
|
7 |
# - test with valid email
|
|
|
52 |
|
53 |
# not sure how xfails come through the CI pipeline yet.
|
54 |
# maybe better to just comment out this stuff until pipeline is setup, then can check /extend
|
55 |
+
@pytest.mark.xfail(reason="Bug identified, but while setting up CI having failing tests causes more headache")
|
56 |
+
def test_is_valid_email_invalid_plus():
|
57 |
+
assert not is_valid_email("[email protected]")
|
58 |
+
assert not is_valid_email("[email protected]")
|
59 |
+
|
60 |
+
|
61 |
+
def test_is_valid_number_valid():
|
62 |
+
# with a sign or without, fractional or integer are all valid
|
63 |
+
assert is_valid_number("123")
|
64 |
+
assert is_valid_number("123.456")
|
65 |
+
assert is_valid_number("-123")
|
66 |
+
assert is_valid_number("-123.456")
|
67 |
+
assert is_valid_number("+123")
|
68 |
+
assert is_valid_number("+123.456")
|
69 |
+
|
70 |
+
def test_is_valid_number_empty():
|
71 |
+
assert not is_valid_number("")
|
72 |
+
|
73 |
+
def test_is_valid_number_none():
|
74 |
+
with pytest.raises(TypeError):
|
75 |
+
is_valid_number(None)
|
76 |
+
|
77 |
+
def test_is_valid_number_invalid():
|
78 |
+
# func should return False for strings that are not numbers
|
79 |
+
assert not is_valid_number("abc")
|
80 |
+
assert not is_valid_number("123abc")
|
81 |
+
assert not is_valid_number("abc123")
|
82 |
+
assert not is_valid_number("123.456.789")
|
83 |
+
assert not is_valid_number("123,456")
|
84 |
+
assert not is_valid_number("123-456")
|
85 |
+
assert not is_valid_number("123+456")
|
86 |
+
def test_is_valid_number_valid():
|
87 |
+
assert is_valid_number("123")
|
88 |
+
assert is_valid_number("123.456")
|
89 |
+
assert is_valid_number("-123")
|
90 |
+
assert is_valid_number("-123.456")
|
91 |
+
assert is_valid_number("+123")
|
92 |
+
assert is_valid_number("+123.456")
|
93 |
+
|
94 |
+
def test_is_valid_number_empty():
|
95 |
+
assert not is_valid_number("")
|
96 |
+
|
97 |
+
def test_is_valid_number_none():
|
98 |
+
with pytest.raises(TypeError):
|
99 |
+
is_valid_number(None)
|
100 |
+
|
101 |
+
def test_is_valid_number_invalid():
|
102 |
+
assert not is_valid_number("abc")
|
103 |
+
assert not is_valid_number("123abc")
|
104 |
+
assert not is_valid_number("abc123")
|
105 |
+
assert not is_valid_number("123.456.789")
|
106 |
+
assert not is_valid_number("123,456")
|
107 |
+
assert not is_valid_number("123-456")
|
108 |
+
assert not is_valid_number("123+456")
|