Skip to content

Commit dbd730b

Browse files
authored
Merge pull request #34 from samuelcolvin/tests
adding tests
2 parents cf1e6b7 + 7c7d968 commit dbd730b

File tree

9 files changed

+310
-83
lines changed

9 files changed

+310
-83
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ docs/_build/
1616
.env
1717
.venv
1818
env/
19+
env27/
1920
.idea/
21+
.coverage
22+
htmlcov/

.travis.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ language: python
44
cache: pip
55

66
python:
7-
- '2.7'
8-
- '3.4'
7+
#- '2.7'
8+
#- '3.4'
99
- '3.5'
1010
- '3.6'
1111
- '3.7'
1212
- '3.8'
1313

1414
install:
15-
- pip install -r test_requirements.txt
15+
- make install
1616

1717
script:
18-
- flake8 email_validator
18+
- make lint
19+
- make test
1920

21+
after_success:
22+
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.DEFAULT_GOAL := all
2+
3+
.PHONY: install
4+
install:
5+
pip install -U setuptools pip
6+
pip install -U -r test_requirements.txt
7+
pip install -e .
8+
9+
.PHONY: lint
10+
lint:
11+
python setup.py check -rms
12+
flake8 email_validator tests
13+
14+
.PHONY: test
15+
test:
16+
pytest --cov=email_validator
17+
18+
.PHONY: testcov
19+
testcov: test
20+
@echo "building coverage html"
21+
@coverage html
22+
23+
.PHONY: all
24+
all: testcov lint
25+
26+
.PHONY: clean
27+
clean:
28+
rm -rf `find . -name __pycache__`
29+
rm -f `find . -type f -name '*.py[co]' `
30+
rm -f `find . -type f -name '*~' `
31+
rm -f `find . -type f -name '.*~' `
32+
rm -rf .cache
33+
rm -rf .pytest_cache
34+
rm -rf htmlcov
35+
rm -rf *.egg-info
36+
rm -f .coverage
37+
rm -f .coverage.*
38+
rm -rf build
39+
rm -rf dist
40+
python setup.py clean

README.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ information without telling them.)
191191
UCS-4 support required for Python 2.7
192192
'''''''''''''''''''''''''''''''''''''
193193

194-
Note that when using Python 2.7, it is required that it was built with
195-
UCS-4 support (see `here <https://stackoverflow.com/questions/29109944/python-returns-length-of-2-for-single-unicode-character-string>`__); otherwise emails with unicode characters outside
194+
Note that when using Python 2.7, it is required that it was built with
195+
UCS-4 support (see `here <https://stackoverflow.com/questions/29109944/python-returns-length-of-2-for-single-unicode-character-string>`__); otherwise emails with unicode characters outside
196196
of the BMP (Basic Multilingual Plane) will not validate correctly.
197197

198198
Normalization
@@ -387,12 +387,11 @@ or likely to cause trouble:
387387
Testing
388388
-------
389389

390-
A handful of valid email addresses are pasted in ``test_pass.txt``. Run
391-
them through the validator (without deliverability checks) like so:
390+
Tests can be run using
392391

393392
::
394393

395-
python3 email_validator/__init__.py --tests < test_pass.txt
394+
make test
396395

397396
For Project Maintainers
398397
-----------------------

email_validator/__init__.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -315,45 +315,7 @@ def main():
315315
import sys
316316
import json
317317

318-
if sys.argv[-1] == "--tests":
319-
# Pass a file of valid/invalid email addresses.
320-
correct_answer = None
321-
failed = 0
322-
for line in sys.stdin:
323-
# Strip newlines and skip blank lines and comments.
324-
line = line.strip()
325-
if line == "" or line[0] == "#":
326-
continue
327-
if sys.version_info < (3,):
328-
line = line.decode("utf8") # assume utf8 in input
329-
330-
# Pick up "[valid]"/"[invalid]" lines.
331-
if line == "[valid]":
332-
correct_answer = True
333-
continue
334-
elif line == "[invalid]":
335-
correct_answer = False
336-
continue
337-
elif correct_answer is None:
338-
raise Exception("Missing [valid]/[invalid] line.")
339-
340-
# Run.
341-
try:
342-
email = line
343-
validate_email(email, check_deliverability=False)
344-
if correct_answer is False:
345-
# Should have failed.
346-
print(email, "was recognized as valid.")
347-
failed += 1
348-
except EmailNotValidError as e:
349-
if correct_answer is True:
350-
# Should have passed.
351-
print(email, e)
352-
failed += 1
353-
print("%d tests failed" % failed)
354-
sys.exit(0 if not failed else 1)
355-
356-
elif len(sys.argv) == 1:
318+
if len(sys.argv) == 1:
357319
# Read lines for STDIN and validate the email address on each line.
358320
allow_smtputf8 = True
359321
for line in sys.stdin:

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ license_file = LICENSE
66

77
[flake8]
88
max-line-length = 120
9+
10+
[tool:pytest]
11+
testpaths = tests
12+
filterwarnings =
13+
error

test_pass.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.

test_requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
coverage==4.5.4
2+
docutils==0.15.2
13
flake8==3.7.9
4+
pytest==5.2.2
5+
pytest-cov==2.8.1

0 commit comments

Comments
 (0)