Skip to content

Commit deab7fb

Browse files
committed
fixes coverage
1 parent 64ada0b commit deab7fb

File tree

6 files changed

+66
-20
lines changed

6 files changed

+66
-20
lines changed

.coveragerc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[run]
2+
branch = True
3+
source = pytest_echo
4+
5+
omit =
6+
7+
[report]
8+
# Regexes for lines to exclude from consideration
9+
exclude_lines =
10+
pragma: no cover
11+
12+
ignore_errors = False
13+
14+
[html]
15+
directory = ~build/coverage

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
.cache
33
.tox
44
dist
5-
*.egg-info
5+
pytest_echo.egg-info
66
*.pyc
77
__pycache__
88
docs/_build
9+
.coverage
10+
~build

pytest_echo.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
from pprint import pformat
55

66
import pip
7+
from pkg_resources import DistributionNotFound
78

89
__version__ = '1.5'
910

1011

11-
class RetrieveException(Exception):
12-
pass
13-
14-
1512
def get_attr(obj, attr, default='NOT FOUND'):
1613
"""Recursive get object's attribute. May use dot notation.
1714
18-
>>> class C(object): pass
15+
>>> class C(object):
16+
... pass
1917
>>> a = C()
2018
>>> a.b = C()
2119
>>> a.b.c = 4
@@ -46,7 +44,7 @@ def get_attr(obj, attr, default='NOT FOUND'):
4644
return obj[attr]
4745
else:
4846
return default
49-
except Exception as e:
47+
except Exception as e: # pragma: no cover
5048
return str(e)
5149
else:
5250
L = attr.split('.')
@@ -69,6 +67,8 @@ def get_module_attribute(path):
6967
<type 'dict'>
7068
>>> print get_module_attribute('os.path.curdir')
7169
'.'
70+
>>> print get_module_attribute('wrong')
71+
('Unable to load %s', 'wrong')
7272
"""
7373
parts = path.split('.')
7474
parent = ""
@@ -117,7 +117,7 @@ def _get_version(package_name):
117117
import pkg_resources
118118

119119
return pkg_resources.require(package_name)[0].version
120-
except:
120+
except (ImportError, AttributeError, TypeError, DistributionNotFound):
121121
pass
122122

123123
try:
@@ -141,17 +141,15 @@ def pytest_report_header(config):
141141
for k in config.option.echo_envs:
142142
data.extend(get_env(k))
143143
ret.append("\n".join([" %s: %s" % (k, v)
144-
for k,v in sorted(data)]))
144+
for k, v in sorted(data)]))
145145

146-
# ret.append("\n".join([" %s: %s" % (k, os.environ.get(k, "<not set>"))
147-
# for k in config.option.echo_envs]))
148146
if config.option.echo_versions:
149147
ret.append("Package version:")
150148
data = []
151149
for k in config.option.echo_versions:
152150
data.extend(get_version(k))
153151
ret.append("\n".join([" %s: %s" % (k, v)
154-
for k,v in sorted(data)]))
152+
for k, v in sorted(data)]))
155153

156154
if config.option.echo_attribues:
157155
ret.append("Inspections:")

setup.cfg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ universal=1
1212
[devpi:upload]
1313
formats = bdist_wheel,sdist.tgz
1414

15+
[flake8]
16+
max-line-length = 91
17+
18+
[isort]
19+
line_length=90
20+
combine_as_imports = true
21+
multi_line_output = 5
22+
default_section = FIRSTPARTY
23+
indent=' '
24+
25+
known_future_library=
26+
known_standard_library=
27+
known_third_party=
28+
known_first_party=
29+
30+
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,CONCURRENCY,LOCALFOLDER
31+
32+

test_echo.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
from contextlib import contextmanager
44

5+
import django
56
import pytest
67

78
import pytest_echo
@@ -46,7 +47,6 @@ def env(**kwargs):
4647

4748

4849
def test_echo_env(testdir):
49-
# os.environ['PYTESTECHO'] = '123'
5050
with env(PYTESTECHO='123'):
5151
result = testdir.runpytest('--echo-env=PYTESTECHO')
5252
result.stdout.fnmatch_lines([
@@ -55,8 +55,6 @@ def test_echo_env(testdir):
5555

5656

5757
def test_echo_env_glob(testdir):
58-
# os.environ['PYTESTECHO-a'] = '1'
59-
# os.environ['PYTESTECHO-b'] = '2'
6058
with env(**{'PYTESTECHO-a': '1', 'PYTESTECHO-b': '2'}):
6159
result = testdir.runpytest('--echo-env=PYTESTECHO*')
6260
result.stdout.fnmatch_lines([
@@ -70,13 +68,23 @@ def test_echo_version(testdir):
7068
result.stdout.fnmatch_lines([" pytest-echo: %s" % pytest_echo.__version__])
7169

7270

71+
def test_echo_version_missing(testdir):
72+
result = testdir.runpytest('--echo-version=missing-package')
73+
result.stdout.fnmatch_lines([" missing-package: <unable to load package>"])
74+
75+
76+
def test_echo_version_no_setuptools(testdir, monkeypatch):
77+
monkeypatch.setattr("pkg_resources.require", None)
78+
result = testdir.runpytest('--echo-version=pytest', '--echo-version=django')
79+
result.stdout.fnmatch_lines([" pytest: %s" % pytest.__version__])
80+
result.stdout.fnmatch_lines([" django: %s" % django.get_version()])
81+
82+
7383
def test_echo_version_glob(testdir):
7484
result = testdir.runpytest('--echo-version=pytest*')
7585
result.stdout.fnmatch_lines([" pytest: %s" % pytest.__version__,
7686
" pytest-echo: %s" % pytest_echo.__version__,
7787
])
78-
# result.stdout.fnmatch_lines([" pytest-echo: %s" % pytest_echo.__version__])
79-
# result.stdout.fnmatch_lines([" pytest: %s" % pytest.__version__])
8088

8189

8290
def test_echo_all(testdir):

tox.ini

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ deps =
77
py{34,35,36}: django
88
py{33,34}: pytest<3
99
py{33,34}: py<1.5
10+
coverage
1011

1112
commands =
12-
pip install {toxinidir}
13-
py.test {posargs}
13+
; py.test --pyargs test_echo.py
14+
pip install -e .
15+
coverage run -m py.test
16+
coverage report
17+
coverage html
1418

1519
[pytest]
1620
pep8ignore = E128 E302
1721
doc/conf.py ALL
18-
python_files=test_echo.py
22+
;python_files=test_echo.py
1923

2024
addopts =
2125
--tb=short
26+
--doctest-modules
2227
--capture=sys
2328

2429
[flake8]

0 commit comments

Comments
 (0)