|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +import os |
| 16 | +import pathlib |
| 17 | +import sys |
15 | 18 | import unittest
|
16 | 19 |
|
17 | 20 | from lib import main
|
18 | 21 |
|
19 | 22 |
|
20 | 23 | class ExampleTest(unittest.TestCase):
|
| 24 | + def test_coverage_doesnt_shadow_stdlib(self): |
| 25 | + # When we try to import the html module |
| 26 | + import html as html_stdlib |
| 27 | + |
| 28 | + try: |
| 29 | + import coverage.html as html_coverage |
| 30 | + except ImportError: |
| 31 | + self.skipTest("not running under coverage, skipping") |
| 32 | + |
| 33 | + self.assertNotEqual( |
| 34 | + html_stdlib, |
| 35 | + html_coverage, |
| 36 | + "'html' import should not be shadowed by coverage", |
| 37 | + ) |
| 38 | + |
| 39 | + def test_coverage_sys_path(self): |
| 40 | + all_paths = ",\n ".join(sys.path) |
| 41 | + |
| 42 | + for i, path in enumerate(sys.path[1:-2]): |
| 43 | + self.assertFalse( |
| 44 | + "/coverage" in path, |
| 45 | + f"Expected {i + 2}th '{path}' to not contain 'coverage.py' paths, " |
| 46 | + f"sys.path has {len(sys.path)} items:\n {all_paths}", |
| 47 | + ) |
| 48 | + |
| 49 | + first_item, last_item = sys.path[0], sys.path[-1] |
| 50 | + self.assertFalse( |
| 51 | + first_item.endswith("coverage"), |
| 52 | + f"Expected the first item in sys.path '{first_item}' to not be related to coverage", |
| 53 | + ) |
| 54 | + if os.environ.get("COVERAGE_MANIFEST"): |
| 55 | + # we are running under the 'bazel coverage :test' |
| 56 | + self.assertTrue( |
| 57 | + "pypi__coverage_cp" in last_item, |
| 58 | + f"Expected {last_item} to be related to coverage", |
| 59 | + ) |
| 60 | + self.assertEqual(pathlib.Path(last_item).name, "coverage") |
| 61 | + else: |
| 62 | + self.assertFalse( |
| 63 | + "coverage" in last_item, f"Expected coverage tooling to not be present" |
| 64 | + ) |
| 65 | + |
21 | 66 | def test_main(self):
|
22 | 67 | self.assertEquals(
|
23 | 68 | """\
|
|
0 commit comments