Skip to content

Commit

Permalink
feat(deps): add support for coverage v6.x (TheKevJames#330)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arcivanov authored and andy-maier committed Dec 23, 2022
1 parent 2d7c638 commit faf225f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 4 deletions.
8 changes: 6 additions & 2 deletions coveralls/reporter.py
Expand Up @@ -2,9 +2,13 @@
import os

from coverage import __version__
from coverage.misc import NoSource
from coverage.misc import NotPython

try:
from coverage.exceptions import NoSource
from coverage.exceptions import NotPython
except ImportError:
from coverage.misc import NoSource
from coverage.misc import NotPython

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

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Expand Up @@ -34,7 +34,7 @@
},
python_requires='>= 3.5',
install_requires=[
'coverage>=4.1,<6.0',
'coverage>=4.1,<7.0',
'docopt>=0.6.1',
'requests>=1.0.0',
],
Expand All @@ -53,6 +53,8 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
Expand Down
12 changes: 12 additions & 0 deletions tests/coverage_templates/bar.py
@@ -0,0 +1,12 @@
def test_func(max_val):
for idx in range(0, max_val):
if idx == -1:
print("Miss 1", idx)
elif idx == 4:
print("Hit 1", idx)
elif idx == 6:
print("Hit 2", idx)
elif idx == 12:
print("Miss 2", idx)
else:
print("Other", idx)
13 changes: 13 additions & 0 deletions tests/coverage_templates/bar_310.py
@@ -0,0 +1,13 @@
def test_func(max_val):
for idx in range(0, max_val):
match idx:
case -1:
print("Miss 1", idx)
case 4:
print("Hit 1", idx)
case 6:
print("Hit 2", idx)
case 12:
print("Miss 2", idx)
case _:
print("Other", idx)
8 changes: 8 additions & 0 deletions tests/coverage_templates/foo.py
@@ -0,0 +1,8 @@
import sys

__all__ = ["test_func"]

if sys.version_info[:2] >= (3, 10):
from bar_310 import test_func
else:
from bar import test_func
91 changes: 91 additions & 0 deletions tests/integration_test.py
@@ -0,0 +1,91 @@
import os
import tempfile
import unittest
from os.path import join as jp, dirname
from pprint import pprint
from subprocess import check_call

from coveralls import Coveralls

COVERAGE_CONFIG = """
[run]
branch = True
data_file = %s
[paths]
source = %s
%s
"""

COVERAGE_CODE_STANZA = """
import sys
sys.path.append(%r)
exec('''
import foo
foo.test_func(%r)
''')
"""

COVERAGE_TEMPLATE_PATH = jp(dirname(__file__), "coverage_templates")


class IntegrationTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
try:
cls.old_cwd = os.getcwd()
except FileNotFoundError:
cls.old_cwd = None

@classmethod
def tearDownClass(cls):
if cls.old_cwd:
os.chdir(cls.old_cwd)

def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
os.chdir(self.temp_dir.name)
self.covrc = jp(self.temp_dir.name, ".coveragerc")
self.cov = jp(self.temp_dir.name, ".coverage")
self.test_file = jp(self.temp_dir.name, "test.py")

def tearDown(self):
self.temp_dir.cleanup()

def _test_harness(self, code):
with open(self.covrc, "wt") as f:
f.write(COVERAGE_CONFIG % (self.cov, COVERAGE_TEMPLATE_PATH, self.temp_dir))
with open(self.test_file, "wt") as f:
f.write(code)

check_call(["coverage", "run", "test.py"])

os.unlink(self.test_file)

coverallz = Coveralls(repo_token="xxx",
config_file=self.covrc)
report = coverallz.create_data()
coverallz.create_report() # This is purely for coverage

source_files = set(f["name"] for f in report["source_files"])
self.assertNotIn(self.test_file, source_files)
self.assertIn(jp(COVERAGE_TEMPLATE_PATH, "foo.py"), source_files)
self.assertTrue(jp(COVERAGE_TEMPLATE_PATH, "bar.py") in source_files or
jp(COVERAGE_TEMPLATE_PATH, "bar_310.py") in source_files)
self.assertFalse(jp(COVERAGE_TEMPLATE_PATH, "bar.py") in source_files and
jp(COVERAGE_TEMPLATE_PATH, "bar_310.py") in source_files)

def _test_number(self, num):
self._test_harness(COVERAGE_CODE_STANZA % (COVERAGE_TEMPLATE_PATH, num))

def test_5(self):
self._test_number(5)

def test_7(self):
self._test_number(7)

def test_11(self):
self._test_number(11)
9 changes: 8 additions & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py35-cov41-{default,pyyaml},py{36,37,38,39,310,py3}-cov{41,5}-{default,pyyaml}
envlist = py35-cov41-{default,pyyaml},py{36,37,38,39,310,py3}-cov{41,5,6}-{default,pyyaml}

[gh-actions]
python =
Expand All @@ -20,6 +20,7 @@ deps =
pyyaml: PyYAML>=3.10,<5.3
cov41: coverage>=4.1,<5.0
cov5: coverage>=5.0,<6.0
cov6: coverage>=6.0,<7.0
commands =
coverage run --branch --source=coveralls -m pytest tests/
coverage report -m
Expand All @@ -35,3 +36,9 @@ deps =
coverage>=5.0,<6.0
commands =
coveralls --verbose

[testenv:coveralls6]
deps =
coverage>=6.0,<7.0
commands =
coveralls --verbose

0 comments on commit faf225f

Please sign in to comment.