OLD | NEW |
(Empty) | |
| 1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
| 2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt |
| 3 |
| 4 """Tests of coverage/collector.py and other collectors.""" |
| 5 |
| 6 import os.path |
| 7 |
| 8 import coverage |
| 9 |
| 10 from tests.coveragetest import CoverageTest |
| 11 from tests.helpers import CheckUniqueFilenames |
| 12 |
| 13 |
| 14 class CollectorTest(CoverageTest): |
| 15 """Test specific aspects of the collection process.""" |
| 16 |
| 17 def test_should_trace_cache(self): |
| 18 # The tracers should only invoke should_trace once for each file name. |
| 19 |
| 20 # Make some files that invoke each other. |
| 21 self.make_file("f1.py", """\ |
| 22 def f1(x, f): |
| 23 return f(x) |
| 24 """) |
| 25 |
| 26 self.make_file("f2.py", """\ |
| 27 import f1 |
| 28 |
| 29 def func(x): |
| 30 return f1.f1(x, otherfunc) |
| 31 |
| 32 def otherfunc(x): |
| 33 return x*x |
| 34 |
| 35 for i in range(10): |
| 36 func(i) |
| 37 """) |
| 38 |
| 39 # Trace one file, but not the other. CheckUniqueFilenames will assert |
| 40 # that _should_trace hasn't been called twice for the same file. |
| 41 cov = coverage.Coverage(include=["f1.py"]) |
| 42 should_trace_hook = CheckUniqueFilenames.hook(cov, '_should_trace') |
| 43 |
| 44 # Import the Python file, executing it. |
| 45 self.start_import_stop(cov, "f2") |
| 46 |
| 47 # Double-check that our files were checked. |
| 48 abs_files = set(os.path.abspath(f) for f in should_trace_hook.filenames) |
| 49 self.assertIn(os.path.abspath("f1.py"), abs_files) |
| 50 self.assertIn(os.path.abspath("f2.py"), abs_files) |
OLD | NEW |