diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-15 09:49:39 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-15 09:49:39 -0500 |
commit | 92de04ca5e44532f3fa78dece8df822557805373 (patch) | |
tree | b1be6758ae71de571a8c12ffc7266dd65f703cda /tests/test_testing.py | |
parent | 36a1630ab9b54975369a487595380867a470c06e (diff) | |
download | python-coveragepy-git-92de04ca5e44532f3fa78dece8df822557805373.tar.gz |
Add a test of CheckUniqueFilenames
Diffstat (limited to 'tests/test_testing.py')
-rw-r--r-- | tests/test_testing.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_testing.py b/tests/test_testing.py index d91de28d..d0e75797 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -13,6 +13,7 @@ from coverage.backunittest import TestCase from coverage.files import actual_path from tests.coveragetest import CoverageTest +from tests.helpers import CheckUniqueFilenames class TestingTest(TestCase): @@ -140,6 +141,31 @@ class CoverageTestTest(CoverageTest): self.assertEqual(environ.strip(), "COV_FOOBAR = XYZZY") +class CheckUniqueFilenamesTest(CoverageTest): + """Tests of CheckUniqueFilenames.""" + + class Stub(object): + """A stand-in for the class we're checking.""" + def __init__(self, x): + self.x = x + + def method(self, filename, a=17, b="hello"): + """The method we'll wrap, with args to be sure args work.""" + return (self.x, filename, a, b) + + def test_detect_duplicate(self): + stub = self.Stub(23) + CheckUniqueFilenames.hook(stub, "method") + + # Two method calls with different names are fine. + assert stub.method("file1") == (23, "file1", 17, "hello") + assert stub.method("file2", 1723, b="what") == (23, "file2", 1723, "what") + + # A duplicate file name trips an assertion. + with self.assertRaises(AssertionError): + stub.method("file1") + + def same_python_executable(e1, e2): """Determine if `e1` and `e2` refer to the same Python executable. |