diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gold/html/Makefile | 2 | ||||
-rw-r--r-- | tests/test_arcs.py | 17 | ||||
-rw-r--r-- | tests/test_cmdline.py | 18 | ||||
-rw-r--r-- | tests/test_config.py | 39 | ||||
-rw-r--r-- | tests/test_json.py | 8 | ||||
-rw-r--r-- | tests/test_phystokens.py | 2 | ||||
-rw-r--r-- | tests/test_process.py | 4 | ||||
-rw-r--r-- | tests/test_xml.py | 13 |
8 files changed, 89 insertions, 14 deletions
diff --git a/tests/gold/html/Makefile b/tests/gold/html/Makefile index fa98714e..604ece7a 100644 --- a/tests/gold/html/Makefile +++ b/tests/gold/html/Makefile @@ -7,7 +7,7 @@ help: complete: ## Copy support files into directories so the HTML can be viewed properly. @for sub in *; do \ - if [[ -f $$sub/index.html ]]; then \ + if [ -f "$$sub/index.html" ]; then \ echo Copying into $$sub ; \ cp -n support/* $$sub ; \ fi ; \ diff --git a/tests/test_arcs.py b/tests/test_arcs.py index bf17f712..a02e9f7d 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -1557,6 +1557,23 @@ class AsyncTest(CoverageTest): arcz_missing=".2 23 3.", ) + def test_async_decorator(self): + if env.PYBEHAVIOR.trace_decorated_def: + arcz = ".1 14 45 5. .2 2. -46 6-4" + else: + arcz = ".1 14 4. .2 2. -46 6-4" + self.check_coverage("""\ + def wrap(f): # 1 + return f + + @wrap # 4 + async def go(): + return + """, + arcz=arcz, + arcz_missing='-46 6-4', + ) + class ExcludeTest(CoverageTest): """Tests of exclusions to indicate known partial branches.""" diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index f5e8e96a..2406d93d 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -37,11 +37,11 @@ class BaseCmdLineTest(CoverageTest): _defaults.Coverage().html_report( directory=None, ignore_errors=None, include=None, omit=None, morfs=[], skip_covered=None, show_contexts=None, title=None, contexts=None, - skip_empty=None, + skip_empty=None, precision=None, ) _defaults.Coverage().report( ignore_errors=None, include=None, omit=None, morfs=[], - show_missing=None, skip_covered=None, contexts=None, skip_empty=None, + show_missing=None, skip_covered=None, contexts=None, skip_empty=None, precision=None, ) _defaults.Coverage().xml_report( ignore_errors=None, include=None, omit=None, morfs=[], outfile=None, @@ -49,7 +49,7 @@ class BaseCmdLineTest(CoverageTest): ) _defaults.Coverage().json_report( ignore_errors=None, include=None, omit=None, morfs=[], outfile=None, - contexts=None, pretty_print=None, show_contexts=None + contexts=None, pretty_print=None, show_contexts=None, ) _defaults.Coverage( cover_pylib=None, data_suffix=None, timid=None, branch=None, @@ -324,6 +324,11 @@ class CmdLineTest(BaseCmdLineTest): cov.load() cov.html_report(morfs=["mod1", "mod2", "mod3"]) """) + self.cmd_executes("html --precision=3", """\ + cov = Coverage() + cov.load() + cov.html_report(precision=3) + """) self.cmd_executes("html --title=Hello_there", """\ cov = Coverage() cov.load() @@ -367,6 +372,11 @@ class CmdLineTest(BaseCmdLineTest): cov.load() cov.report(morfs=["mod1", "mod2", "mod3"]) """) + self.cmd_executes("report --precision=7", """\ + cov = Coverage() + cov.load() + cov.report(precision=7) + """) self.cmd_executes("report --skip-covered", """\ cov = Coverage() cov.load() @@ -781,7 +791,7 @@ class CmdLineStdoutTest(BaseCmdLineTest): def test_minimum_help(self): self.command_line("") out = self.stdout() - self.assertIn("Code coverage for Python.", out) + self.assertIn("Code coverage for Python", out) self.assertLess(out.count("\n"), 4) def test_version(self): diff --git a/tests/test_config.py b/tests/test_config.py index fe9e001e..89ecb17c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -4,6 +4,8 @@ """Test the config file handling for coverage.py""" +from collections import OrderedDict + import mock import coverage @@ -61,6 +63,8 @@ class ConfigTest(CoverageTest): # A .coveragerc file will be read into the configuration. self.make_file("pyproject.toml", """\ # This is just a bogus toml file for testing. + [tool.somethingelse] + authors = ["Joe D'Ávila <joe@gmail.com>"] [tool.coverage.run] concurrency = ["a", "b"] timid = true @@ -69,20 +73,23 @@ class ConfigTest(CoverageTest): [tool.coverage.report] precision = 3 fail_under = 90.5 + [tool.coverage.html] + title = "tabblo & «ταБЬℓσ»" [tool.coverage.plugins.a_plugin] hello = "world" """) cov = coverage.Coverage(config_file="pyproject.toml") self.assertTrue(cov.config.timid) self.assertFalse(cov.config.branch) - self.assertEqual(cov.config.concurrency, ["a", "b"]) - self.assertEqual(cov.config.data_file, ".hello_kitty.data") - self.assertEqual(cov.config.plugins, ["plugins.a_plugin"]) + self.assertEqual(cov.config.concurrency, [u"a", u"b"]) + self.assertEqual(cov.config.data_file, u".hello_kitty.data") + self.assertEqual(cov.config.plugins, [u"plugins.a_plugin"]) self.assertEqual(cov.config.precision, 3) + self.assertEqual(cov.config.html_title, u"tabblo & «ταБЬℓσ»") self.assertAlmostEqual(cov.config.fail_under, 90.5) self.assertEqual( cov.config.get_plugin_options("plugins.a_plugin"), - {'hello': 'world'} + {u"hello": u"world"} ) # Test that our class doesn't reject integers when loading floats @@ -340,6 +347,30 @@ class ConfigTest(CoverageTest): self.assertFalse(cov.get_option("run:branch")) self.assertEqual(cov.get_option("run:data_file"), "fooey.dat") + def test_tweaks_paths_after_constructor(self): + self.make_file(".coveragerc", """\ + [paths] + first = + /first/1 + /first/2 + + second = + /second/a + /second/b + """) + old_paths = OrderedDict() + old_paths["first"] = ["/first/1", "/first/2"] + old_paths["second"] = ["/second/a", "/second/b"] + cov = coverage.Coverage() + paths = cov.get_option("paths") + self.assertEqual(paths, old_paths) + + new_paths = OrderedDict() + new_paths['magic'] = ['src', 'ok'] + cov.set_option("paths", new_paths) + + self.assertEqual(cov.get_option("paths"), new_paths) + def test_tweak_error_checking(self): # Trying to set an unknown config value raises an error. cov = coverage.Coverage() diff --git a/tests/test_json.py b/tests/test_json.py index 2d2ae9f4..f7ce7934 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -54,7 +54,9 @@ class JsonReportTest(UsingModulesMixin, CoverageTest): 'num_branches': 2, 'excluded_lines': 0, 'num_partial_branches': 1, - 'percent_covered': 60.0 + 'covered_branches': 1, + 'missing_branches': 1, + 'percent_covered': 60.0, } } }, @@ -65,7 +67,9 @@ class JsonReportTest(UsingModulesMixin, CoverageTest): 'num_branches': 2, 'excluded_lines': 0, 'num_partial_branches': 1, - 'percent_covered': 60.0 + 'percent_covered': 60.0, + 'covered_branches': 1, + 'missing_branches': 1, } } self._assert_expected_json_report(cov, expected_result) diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index 6f38fc94..1256694a 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -285,5 +285,5 @@ class CompileUnicodeTest(CoverageTest): def test_double_coding_declaration(self): # Build this string in a weird way so that actual vim's won't try to # interpret it... - uni = u"# -*- coding:utf-8 -*-\n# v" "im: fileencoding=utf-8\n" + uni = u"# -*- coding:utf-8 -*-\n# v" + "im: fileencoding=utf-8\n" self.assert_compile_unicode(uni) diff --git a/tests/test_process.py b/tests/test_process.py index e4c0ae8f..a9b8e00a 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -4,13 +4,13 @@ """Tests for process behavior of coverage.py.""" -import distutils.sysconfig import glob import os import os.path import re import stat import sys +import sysconfig import textwrap import time from xml.etree import ElementTree @@ -1399,7 +1399,7 @@ def possible_pth_dirs(): # If we're still looking, then try the Python library directory. # https://bitbucket.org/ned/coveragepy/issue/339/pth-test-malfunctions - yield distutils.sysconfig.get_python_lib() # pragma: cant happen + yield sysconfig.get_python_lib() # pragma: cant happen def find_writable_pth_directory(): diff --git a/tests/test_xml.py b/tests/test_xml.py index 93fee9b7..0d789fca 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -370,6 +370,19 @@ class XmlPackageStructureTest(XmlTestHelpers, CoverageTest): dom = ElementTree.parse("coverage.xml") self.assert_source(dom, "src") + def test_relative_source(self): + self.make_file("src/mod.py", "print(17)") + cov = coverage.Coverage(source=["src"]) + cov.set_option("run:relative_files", True) + self.start_import_stop(cov, "mod", modfile="src/mod.py") + cov.xml_report() + + with open("coverage.xml") as x: + print(x.read()) + dom = ElementTree.parse("coverage.xml") + elts = dom.findall(".//sources/source") + assert [elt.text for elt in elts] == ["src"] + def compare_xml(expected, actual, **kwargs): """Specialized compare function for our XML files.""" |