Skip to content

Commit df27300

Browse files
committed
Added tests
1 parent e44dc42 commit df27300

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ __pycache__
44
build/
55
dist/
66
*.egg-info/
7+
.cache/
8+
.coverage

pytest.ini

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[pytest]
2+
addopts = --pep8 --tb=short --cov
3+
python_files = test_*.py
4+
norecursedirs = *.egg tmp* build .tox
5+
pep8ignore =
6+
*.py E126 E127 E128
7+
setup.py ALL
8+
*/tests/* ALL
9+
*/docs/* ALL
10+
*/build/* ALL
11+
*/TOXENV/* ALL
12+
pep8maxlinelength = 99

requirements-dev.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest==2.8.2
2+
pytest-cache==1.0
3+
pytest-cov==2.2.0
4+
pytest-pep8==1.0.6

tests/conftest.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import print_function, division, absolute_import, unicode_literals
3+
4+
import sys
5+
import os
6+
7+
current_dir = os.path.dirname(os.path.abspath(__file__))
8+
parent_dir = os.path.normpath(os.path.join(current_dir, '..'))
9+
sys.path.insert(0, parent_dir)

tests/test_output.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import print_function, division, absolute_import, unicode_literals
3+
4+
import sys
5+
6+
import pytest
7+
8+
from coverage_badge import __main__
9+
10+
11+
@pytest.fixture
12+
def cb(monkeypatch):
13+
"""
14+
Return a monkey patched coverage_badge module that always returns a percentage of 79.
15+
"""
16+
def get_fake_total():
17+
return '79'
18+
monkeypatch.setattr(__main__, 'get_total', get_fake_total)
19+
return __main__
20+
21+
22+
def test_version(cb, capsys):
23+
"""
24+
Test the version output.
25+
"""
26+
with pytest.raises(SystemExit) as se:
27+
cb.main(['-v'])
28+
out, _ = capsys.readouterr()
29+
assert out == 'coverage-badge v%s\n' % __main__.__version__
30+
31+
32+
def test_svg_output(cb, capsys):
33+
"""
34+
Test the SVG output.
35+
"""
36+
cb.main([])
37+
out, _ = capsys.readouterr()
38+
assert out.startswith('<svg xmlns="http://www.w3.org/2000/svg" width="99" height="20">')
39+
assert '<text x="80" y="14">79%</text>' in out
40+
assert out.endswith('</svg>\n')

0 commit comments

Comments
 (0)