Skip to content

Commit 965f8ab

Browse files
committed
Tests and packaging
1 parent c849425 commit 965f8ab

7 files changed

Lines changed: 209 additions & 3 deletions

File tree

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
dist: xenial
2+
language: python
3+
4+
env:
5+
global:
6+
# reload 0.2.0 is broken by 4.4.1
7+
- TOX_SKIP_ENV='.*-coverage(44[^0]|4[56789].|[56789]..)-reload020'
8+
9+
cache: pip
10+
python:
11+
- '2.7'
12+
- '3.4'
13+
- '3.5'
14+
- '3.6'
15+
- '3.7'
16+
- 'pypy2.7-6.0'
17+
- 'pypy3.5-6.0'
18+
19+
install:
20+
- pip install tox-travis
21+
script:
22+
- tox

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* v0.2.0
2+
- Tests for all coverage patch versions 4.0 - 5.0a,
3+
CPython 2.7 and 3.4 - 3.7 and PyPy 6.0
4+
- Add LICENSE to distributions
5+
6+
* v0.1.0
7+
- Initial version

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include LICENSE
2+
include tox.ini
3+
include tests/*.py

setup.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
Programming Language :: Python :: 3.4
1212
Programming Language :: Python :: 3.5
1313
Programming Language :: Python :: 3.6
14+
Programming Language :: Python :: 3.7
1415
Programming Language :: Python :: Implementation :: CPython
1516
Programming Language :: Python :: Implementation :: PyPy
1617
Topic :: Software Development :: Quality Assurance
1718
Topic :: Software Development :: Testing
18-
Development Status :: 3 - Alpha
19+
Development Status :: 4 - Beta
1920
"""
2021

2122
setup(
22-
name='coverage_env_plugin',
23-
version='0.1',
23+
name='coverage-env-plugin',
24+
version='0.2.0',
2425
description='coverage.py environment plugin',
2526
author='John Vandenberg',
2627
author_email='jayvdb@gmail.com',
@@ -30,6 +31,8 @@
3031
'coverage >= 4.0',
3132
'packaging',
3233
],
34+
tests_require=['unittest-mixins'],
35+
test_suite='tests',
3336
license='MIT License',
3437
classifiers=classifiers.splitlines(),
3538
)

tests/__init__.py

Whitespace-only changes.

tests/test_markers.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import os
2+
3+
from distutils.version import LooseVersion
4+
from unittest import TestCase
5+
6+
from unittest_mixins import TempDirMixin
7+
8+
import coverage_env_plugin
9+
try:
10+
from coverage_config_reload_plugin import __version__ as config_reload_version
11+
except ImportError:
12+
config_reload_version = '0.2.0'
13+
14+
from coverage import __version__ as coverage_version
15+
from coverage.backward import StringIO
16+
from coverage.control import Coverage
17+
18+
19+
class ConfigMarkersPluginTest(TempDirMixin, TestCase):
20+
"""Test plugin through the Coverage class."""
21+
22+
def _reset_env(self):
23+
if 'OS_NAME' in os.environ:
24+
del os.environ['OS_NAME']
25+
assert 'OS_NAME' not in os.environ
26+
coverage_env_plugin.DEFAULT_ENVIRONMENT = {}
27+
28+
def test_plugin_init(self):
29+
self._reset_env()
30+
31+
self.make_file('.coveragerc', """\
32+
[run]
33+
plugins = coverage_env_plugin
34+
35+
[coverage_env_plugin]
36+
markers = True
37+
38+
[report]
39+
exclude_lines =
40+
foobar: no cover
41+
""")
42+
43+
cov = Coverage()
44+
assert cov.config.get_option('report:exclude_lines') == ['foobar: no cover']
45+
46+
cov.start()
47+
cov.stop()
48+
49+
assert cov.config.plugins == ['coverage_env_plugin']
50+
assert cov.config.plugin_options =={'coverage_env_plugin': {'markers': 'True'}}
51+
52+
assert 'OS_NAME' in coverage_env_plugin.DEFAULT_ENVIRONMENT
53+
assert 'OS_NAME' in os.environ
54+
55+
def test_reload_plugin_init(self):
56+
self._reset_env()
57+
58+
self.make_file('.coveragerc', """\
59+
[run]
60+
plugins = coverage_env_plugin, coverage_config_reload_plugin
61+
[coverage_env_plugin]
62+
markers = True
63+
[report]
64+
exclude_lines =
65+
pragma ${OS_NAME}: no cover
66+
""")
67+
68+
debug_out = StringIO()
69+
cov = Coverage(config_file='.coveragerc', debug=['sys'])
70+
cov._debug_file = debug_out
71+
cov.set_option('run:plugins', ['coverage_env_plugin', 'coverage_config_reload_plugin'])
72+
cov.start()
73+
cov.stop()
74+
75+
assert cov.config.get_option('coverage_env_plugin:markers') == 'True'
76+
77+
out_lines = [line.strip() for line in debug_out.getvalue().splitlines()]
78+
self.assertIn('plugins.file_tracers: -none-', out_lines)
79+
80+
if LooseVersion(config_reload_version) >= LooseVersion('0.3.0'):
81+
expected_end = [
82+
'-- sys: coverage_config_reload_plugin.ConfigReloadPlugin -----',
83+
'configreload: True',
84+
'-- end -------------------------------------------------------',
85+
]
86+
self.assertEqual(expected_end, out_lines[-len(expected_end):])
87+
88+
if LooseVersion(coverage_version) >= LooseVersion('4.6'):
89+
self.assertIn('plugins.configurers: coverage_config_reload_plugin.ConfigReloadPlugin', out_lines)
90+
91+
def test_os_name(self):
92+
self._reset_env()
93+
94+
self.make_file('.coveragerc', """\
95+
[run]
96+
plugins = coverage_env_plugin, coverage_config_reload_plugin
97+
[coverage_env_plugin]
98+
markers = True
99+
[report]
100+
exclude_lines =
101+
pragma ${OS_NAME}: no cover
102+
""")
103+
104+
cov = Coverage(config_file='.coveragerc')
105+
106+
assert cov.config.get_option('report:exclude_lines') == ['pragma : no cover']
107+
assert cov.config.exclude_list == ['pragma : no cover']
108+
109+
assert cov.config.get_option('coverage_env_plugin:markers') == 'True'
110+
111+
cov.start()
112+
cov.stop()
113+
114+
assert 'OS_NAME' in coverage_env_plugin.DEFAULT_ENVIRONMENT
115+
116+
os_name = coverage_env_plugin.DEFAULT_ENVIRONMENT['OS_NAME']
117+
os_name_pragma = 'pragma {}: no cover'.format(os_name)
118+
119+
assert cov.config.get_option('report:exclude_lines') == [os_name_pragma]
120+
assert cov.config.exclude_list == [os_name_pragma]
121+
122+
def test_os_name_without_reload(self):
123+
self._reset_env()
124+
125+
self.make_file('.coveragerc', """\
126+
[run]
127+
plugins = coverage_env_plugin
128+
[coverage_env_plugin]
129+
markers = True
130+
[report]
131+
exclude_lines =
132+
pragma ${OS_NAME}: no cover
133+
""")
134+
135+
cov = Coverage(config_file='.coveragerc')
136+
137+
assert cov.config.get_option('report:exclude_lines') == ['pragma : no cover']
138+
assert cov.config.exclude_list == ['pragma : no cover']
139+
140+
assert cov.config.get_option('coverage_env_plugin:markers') == 'True'
141+
142+
cov.start()
143+
cov.stop()
144+
145+
assert 'OS_NAME' in coverage_env_plugin.DEFAULT_ENVIRONMENT
146+
147+
# It doesnt work; result is the same as the original config
148+
assert cov.config.get_option('report:exclude_lines') == ['pragma : no cover']
149+
assert cov.config.exclude_list == ['pragma : no cover']

tox.ini

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[tox]
2+
envlist = py{27,34,35,36,37,38,py,py2,py3}-coverage{400,410,420,430,440,441,442,450,453,500}-reload{020,030}
3+
4+
[testenv]
5+
deps =
6+
pytest
7+
unittest-mixins
8+
coverage400: coverage==4.0.0
9+
coverage410: coverage==4.1.0
10+
coverage420: coverage==4.2.0
11+
coverage430: coverage==4.3.0
12+
coverage440: coverage==4.4.0
13+
coverage443: coverage==4.4.1
14+
coverage444: coverage==4.4.2
15+
coverage450: coverage==4.5.0
16+
coverage453: coverage==4.5.3
17+
coverage500: coverage>=5.0a4
18+
reload020: coverage-config-reload-plugin==0.2.0
19+
reload030: coverage-config-reload-plugin==0.3.0
20+
21+
commands =
22+
pytest

0 commit comments

Comments
 (0)