Skip to content

Commit faf225f

Browse files
arcivanovandy-maier
authored andcommitted
feat(deps): add support for coverage v6.x (TheKevJames#330)
No major issues in adding support, the bulpk of the work here is providing a smoke test for verification. Also updated tox and classifiers with new compatible ranges. Fixes TheKevJames#326
1 parent 2d7c638 commit faf225f

File tree

7 files changed

+141
-4
lines changed

7 files changed

+141
-4
lines changed

coveralls/reporter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
import os
33

44
from coverage import __version__
5-
from coverage.misc import NoSource
6-
from coverage.misc import NotPython
75

6+
try:
7+
from coverage.exceptions import NoSource
8+
from coverage.exceptions import NotPython
9+
except ImportError:
10+
from coverage.misc import NoSource
11+
from coverage.misc import NotPython
812

913
log = logging.getLogger('coveralls.reporter')
1014

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
python_requires='>= 3.5',
3636
install_requires=[
37-
'coverage>=4.1,<6.0',
37+
'coverage>=4.1,<7.0',
3838
'docopt>=0.6.1',
3939
'requests>=1.0.0',
4040
],
@@ -53,6 +53,8 @@
5353
'Programming Language :: Python :: 3.6',
5454
'Programming Language :: Python :: 3.7',
5555
'Programming Language :: Python :: 3.8',
56+
'Programming Language :: Python :: 3.9',
57+
'Programming Language :: Python :: 3.10',
5658
'Programming Language :: Python :: Implementation :: CPython',
5759
'Programming Language :: Python :: Implementation :: PyPy',
5860
],

tests/coverage_templates/bar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def test_func(max_val):
2+
for idx in range(0, max_val):
3+
if idx == -1:
4+
print("Miss 1", idx)
5+
elif idx == 4:
6+
print("Hit 1", idx)
7+
elif idx == 6:
8+
print("Hit 2", idx)
9+
elif idx == 12:
10+
print("Miss 2", idx)
11+
else:
12+
print("Other", idx)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def test_func(max_val):
2+
for idx in range(0, max_val):
3+
match idx:
4+
case -1:
5+
print("Miss 1", idx)
6+
case 4:
7+
print("Hit 1", idx)
8+
case 6:
9+
print("Hit 2", idx)
10+
case 12:
11+
print("Miss 2", idx)
12+
case _:
13+
print("Other", idx)

tests/coverage_templates/foo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sys
2+
3+
__all__ = ["test_func"]
4+
5+
if sys.version_info[:2] >= (3, 10):
6+
from bar_310 import test_func
7+
else:
8+
from bar import test_func

tests/integration_test.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import os
2+
import tempfile
3+
import unittest
4+
from os.path import join as jp, dirname
5+
from pprint import pprint
6+
from subprocess import check_call
7+
8+
from coveralls import Coveralls
9+
10+
COVERAGE_CONFIG = """
11+
[run]
12+
branch = True
13+
data_file = %s
14+
15+
[paths]
16+
source = %s
17+
%s
18+
"""
19+
20+
COVERAGE_CODE_STANZA = """
21+
import sys
22+
23+
sys.path.append(%r)
24+
25+
exec('''
26+
import foo
27+
28+
foo.test_func(%r)
29+
''')
30+
"""
31+
32+
COVERAGE_TEMPLATE_PATH = jp(dirname(__file__), "coverage_templates")
33+
34+
35+
class IntegrationTest(unittest.TestCase):
36+
@classmethod
37+
def setUpClass(cls):
38+
try:
39+
cls.old_cwd = os.getcwd()
40+
except FileNotFoundError:
41+
cls.old_cwd = None
42+
43+
@classmethod
44+
def tearDownClass(cls):
45+
if cls.old_cwd:
46+
os.chdir(cls.old_cwd)
47+
48+
def setUp(self):
49+
self.temp_dir = tempfile.TemporaryDirectory()
50+
os.chdir(self.temp_dir.name)
51+
self.covrc = jp(self.temp_dir.name, ".coveragerc")
52+
self.cov = jp(self.temp_dir.name, ".coverage")
53+
self.test_file = jp(self.temp_dir.name, "test.py")
54+
55+
def tearDown(self):
56+
self.temp_dir.cleanup()
57+
58+
def _test_harness(self, code):
59+
with open(self.covrc, "wt") as f:
60+
f.write(COVERAGE_CONFIG % (self.cov, COVERAGE_TEMPLATE_PATH, self.temp_dir))
61+
with open(self.test_file, "wt") as f:
62+
f.write(code)
63+
64+
check_call(["coverage", "run", "test.py"])
65+
66+
os.unlink(self.test_file)
67+
68+
coverallz = Coveralls(repo_token="xxx",
69+
config_file=self.covrc)
70+
report = coverallz.create_data()
71+
coverallz.create_report() # This is purely for coverage
72+
73+
source_files = set(f["name"] for f in report["source_files"])
74+
self.assertNotIn(self.test_file, source_files)
75+
self.assertIn(jp(COVERAGE_TEMPLATE_PATH, "foo.py"), source_files)
76+
self.assertTrue(jp(COVERAGE_TEMPLATE_PATH, "bar.py") in source_files or
77+
jp(COVERAGE_TEMPLATE_PATH, "bar_310.py") in source_files)
78+
self.assertFalse(jp(COVERAGE_TEMPLATE_PATH, "bar.py") in source_files and
79+
jp(COVERAGE_TEMPLATE_PATH, "bar_310.py") in source_files)
80+
81+
def _test_number(self, num):
82+
self._test_harness(COVERAGE_CODE_STANZA % (COVERAGE_TEMPLATE_PATH, num))
83+
84+
def test_5(self):
85+
self._test_number(5)
86+
87+
def test_7(self):
88+
self._test_number(7)
89+
90+
def test_11(self):
91+
self._test_number(11)

tox.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py35-cov41-{default,pyyaml},py{36,37,38,39,310,py3}-cov{41,5}-{default,pyyaml}
2+
envlist = py35-cov41-{default,pyyaml},py{36,37,38,39,310,py3}-cov{41,5,6}-{default,pyyaml}
33

44
[gh-actions]
55
python =
@@ -20,6 +20,7 @@ deps =
2020
pyyaml: PyYAML>=3.10,<5.3
2121
cov41: coverage>=4.1,<5.0
2222
cov5: coverage>=5.0,<6.0
23+
cov6: coverage>=6.0,<7.0
2324
commands =
2425
coverage run --branch --source=coveralls -m pytest tests/
2526
coverage report -m
@@ -35,3 +36,9 @@ deps =
3536
coverage>=5.0,<6.0
3637
commands =
3738
coveralls --verbose
39+
40+
[testenv:coveralls6]
41+
deps =
42+
coverage>=6.0,<7.0
43+
commands =
44+
coveralls --verbose

0 commit comments

Comments
 (0)