summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-02-12 09:27:25 -0500
committerNed Batchelder <ned@nedbatchelder.com>2023-02-12 11:52:05 -0500
commitf77be1770a9d93ed69d6b5a26dcbe5dbfe14e380 (patch)
tree57ee04342aef1966e9a73563306f5dceb415b6a5 /tests
parent6bc043981f6548852844ea6b16d5ef7d37c0417d (diff)
downloadpython-coveragepy-git-f77be1770a9d93ed69d6b5a26dcbe5dbfe14e380.tar.gz
fix: Path objects are ok for data_file and config_file. #1552
Diffstat (limited to 'tests')
-rw-r--r--tests/test_api.py12
-rw-r--r--tests/test_config.py8
-rw-r--r--tests/test_data.py9
3 files changed, 18 insertions, 11 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
index 1c565421..596510eb 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -25,7 +25,7 @@ from coverage.data import line_counts, sorted_lines
from coverage.exceptions import CoverageException, DataError, NoDataError, NoSource
from coverage.files import abs_file, relative_filename
from coverage.misc import import_local_file
-from coverage.types import Protocol, TCovKwargs
+from coverage.types import FilePathClasses, FilePathType, Protocol, TCovKwargs
from tests.coveragetest import CoverageTest, TESTS_DIR, UsingModulesMixin
from tests.goldtest import contains, doesnt_contain
@@ -221,26 +221,28 @@ class ApiTest(CoverageTest):
cov.save()
self.assertFiles(["datatest1.py", ".coverage"])
- def test_datafile_specified(self) -> None:
+ @pytest.mark.parametrize("file_class", FilePathClasses)
+ def test_datafile_specified(self, file_class: FilePathType) -> None:
# You can specify the data file name.
self.make_file("datatest2.py", """\
fooey = 17
""")
self.assertFiles(["datatest2.py"])
- cov = coverage.Coverage(data_file="cov.data")
+ cov = coverage.Coverage(data_file=file_class("cov.data"))
self.start_import_stop(cov, "datatest2")
cov.save()
self.assertFiles(["datatest2.py", "cov.data"])
- def test_datafile_and_suffix_specified(self) -> None:
+ @pytest.mark.parametrize("file_class", FilePathClasses)
+ def test_datafile_and_suffix_specified(self, file_class: FilePathType) -> None:
# You can specify the data file name and suffix.
self.make_file("datatest3.py", """\
fooey = 17
""")
self.assertFiles(["datatest3.py"])
- cov = coverage.Coverage(data_file="cov.data", data_suffix="14")
+ cov = coverage.Coverage(data_file=file_class("cov.data"), data_suffix="14")
self.start_import_stop(cov, "datatest3")
cov.save()
self.assertFiles(["datatest3.py", "cov.data.14"])
diff --git a/tests/test_config.py b/tests/test_config.py
index d60a4eeb..2ee5eae0 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -6,8 +6,8 @@
from __future__ import annotations
import sys
-
from unittest import mock
+
import pytest
import coverage
@@ -15,6 +15,7 @@ from coverage import Coverage
from coverage.config import HandyConfigParser
from coverage.exceptions import ConfigError, CoverageWarning
from coverage.tomlconfig import TomlConfigParser
+from coverage.types import FilePathClasses, FilePathType
from tests.coveragetest import CoverageTest, UsingModulesMixin
@@ -50,7 +51,8 @@ class ConfigTest(CoverageTest):
assert not cov.config.branch
assert cov.config.data_file == ".hello_kitty.data"
- def test_named_config_file(self) -> None:
+ @pytest.mark.parametrize("file_class", FilePathClasses)
+ def test_named_config_file(self, file_class: FilePathType) -> None:
# You can name the config file what you like.
self.make_file("my_cov.ini", """\
[run]
@@ -58,7 +60,7 @@ class ConfigTest(CoverageTest):
; I wouldn't really use this as a data file...
data_file = delete.me
""")
- cov = coverage.Coverage(config_file="my_cov.ini")
+ cov = coverage.Coverage(config_file=file_class("my_cov.ini"))
assert cov.config.timid
assert not cov.config.branch
assert cov.config.data_file == "delete.me"
diff --git a/tests/test_data.py b/tests/test_data.py
index 1cc64572..ab3f5f5b 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -24,7 +24,7 @@ from coverage.data import add_data_to_hash, line_counts
from coverage.debug import DebugControlString
from coverage.exceptions import DataError, NoDataError
from coverage.files import PathAliases, canonical_filename
-from coverage.types import TArc, TLineNo
+from coverage.types import FilePathClasses, FilePathType, TArc, TLineNo
from tests.coveragetest import CoverageTest
from tests.helpers import assert_count_equal
@@ -621,10 +621,13 @@ class CoverageDataTest(CoverageTest):
class CoverageDataInTempDirTest(CoverageTest):
"""Tests of CoverageData that need a temporary directory to make files."""
- def test_read_write_lines(self) -> None:
- covdata1 = DebugCoverageData("lines.dat")
+ @pytest.mark.parametrize("file_class", FilePathClasses)
+ def test_read_write_lines(self, file_class: FilePathType) -> None:
+ self.assert_doesnt_exist("lines.dat")
+ covdata1 = DebugCoverageData(file_class("lines.dat"))
covdata1.add_lines(LINES_1)
covdata1.write()
+ self.assert_exists("lines.dat")
covdata2 = DebugCoverageData("lines.dat")
covdata2.read()