From 1784f100c8f2aa64d5c8bf1a9f2502f51065f936 Mon Sep 17 00:00:00 2001 From: Arcadiy Ivanov Date: Sun, 24 Oct 2021 18:48:15 -0400 Subject: [PATCH] Add support for coverage 6.x There aren't really any issues with the current version. Verified by providing a smoke integration test Updated tox and classifiers fixes #326 --- coveralls/reporter.py | 8 ++- setup.py | 4 +- tests/coverage_templates/bar.py | 12 ++++ tests/coverage_templates/bar_310.py | 13 +++++ tests/coverage_templates/foo.py | 8 +++ tests/integration_test.py | 91 +++++++++++++++++++++++++++++ tox.ini | 9 ++- 7 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 tests/coverage_templates/bar.py create mode 100644 tests/coverage_templates/bar_310.py create mode 100644 tests/coverage_templates/foo.py create mode 100644 tests/integration_test.py diff --git a/coveralls/reporter.py b/coveralls/reporter.py index 09d21ca2..06f0b141 100644 --- a/coveralls/reporter.py +++ b/coveralls/reporter.py @@ -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') diff --git a/setup.py b/setup.py index 25c9de5c..2f0d7a06 100644 --- a/setup.py +++ b/setup.py @@ -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', ], @@ -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', ], diff --git a/tests/coverage_templates/bar.py b/tests/coverage_templates/bar.py new file mode 100644 index 00000000..98167f3c --- /dev/null +++ b/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) diff --git a/tests/coverage_templates/bar_310.py b/tests/coverage_templates/bar_310.py new file mode 100644 index 00000000..9856022a --- /dev/null +++ b/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) diff --git a/tests/coverage_templates/foo.py b/tests/coverage_templates/foo.py new file mode 100644 index 00000000..8c21ef8b --- /dev/null +++ b/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 diff --git a/tests/integration_test.py b/tests/integration_test.py new file mode 100644 index 00000000..79b8ebc9 --- /dev/null +++ b/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) diff --git a/tox.ini b/tox.ini index e7d080e6..fafe8a1e 100644 --- a/tox.ini +++ b/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 = @@ -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 @@ -35,3 +36,9 @@ deps = coverage>=5.0,<6.0 commands = coveralls --verbose + +[testenv:coveralls6] +deps = + coverage>=6.0,<7.0 +commands = + coveralls --verbose