diff options
Diffstat (limited to 'tests/test_concurrency.py')
-rw-r--r-- | tests/test_concurrency.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 71006042..9e2d73d9 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -1,5 +1,5 @@ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 -# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt +# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt """Tests for concurrency libraries.""" @@ -14,6 +14,7 @@ from flaky import flaky import coverage from coverage import env from coverage.backward import import_local_file +from coverage.data import line_counts from coverage.files import abs_file from tests.coveragetest import CoverageTest @@ -235,8 +236,8 @@ class ConcurrencyTest(CoverageTest): # Read the coverage file and see that try_it.py has all its lines # executed. - data = coverage.CoverageData() - data.read_file(".coverage") + data = coverage.CoverageData(".coverage") + data.read() # If the test fails, it's helpful to see this info: fname = abs_file("try_it.py") @@ -245,7 +246,7 @@ class ConcurrencyTest(CoverageTest): print_simple_annotation(code, linenos) lines = line_count(code) - self.assertEqual(data.line_counts()['try_it.py'], lines) + self.assertEqual(line_counts(data)['try_it.py'], lines) def test_threads(self): code = (THREAD + SUM_RANGE_Q + PRINT_SUM_RANGE).format(QLIMIT=self.QLIMIT) @@ -335,7 +336,7 @@ MULTI_CODE = """ import sys def process_worker_main(args): - # Need to pause, or the tasks go too quick, and some processes + # Need to pause, or the tasks go too quickly, and some processes # in the pool don't get any work, and then don't record data. time.sleep(0.02) ret = work(*args) @@ -359,7 +360,7 @@ MULTI_CODE = """ """ -@flaky(max_runs=10) # Sometimes a test fails due to inherent randomness. Try one more time. +@flaky(max_runs=10) # Sometimes a test fails due to inherent randomness. Try more times. class MultiprocessingTest(CoverageTest): """Test support of the multiprocessing module.""" @@ -403,7 +404,7 @@ class MultiprocessingTest(CoverageTest): last_line = self.squeezed_lines(out)[-1] self.assertRegex(last_line, r"multi.py \d+ 0 100%") - def test_multiprocessing(self): + def test_multiprocessing_simple(self): nprocs = 3 upto = 30 code = (SQUARE_OR_CUBE_WORK + MULTI_CODE).format(NPROCS=nprocs, UPTO=upto) @@ -430,6 +431,7 @@ class MultiprocessingTest(CoverageTest): [run] concurrency = multiprocessing branch = True + omit = */site-packages/* """) if env.PYVERSION >= (3, 4): @@ -464,7 +466,7 @@ def test_coverage_stop_in_threads(): has_started_coverage = [] has_stopped_coverage = [] - def run_thread(): + def run_thread(): # pragma: nested """Check that coverage is stopping properly in threads.""" deadline = time.time() + 5 ident = threading.currentThread().ident @@ -480,11 +482,11 @@ def test_coverage_stop_in_threads(): cov = coverage.coverage() cov.start() - t = threading.Thread(target=run_thread) - t.start() + t = threading.Thread(target=run_thread) # pragma: nested + t.start() # pragma: nested - time.sleep(0.1) - cov.stop() + time.sleep(0.1) # pragma: nested + cov.stop() # pragma: nested time.sleep(0.1) assert has_started_coverage == [t.ident] @@ -513,7 +515,7 @@ def test_thread_safe_save_data(tmpdir): for module_name in module_names: import_local_file(module_name) - def random_load(): + def random_load(): # pragma: nested """Import modules randomly to stress coverage.""" while should_run[0]: module_name = random.choice(module_names) @@ -529,12 +531,12 @@ def test_thread_safe_save_data(tmpdir): cov = coverage.coverage() cov.start() - threads = [threading.Thread(target=random_load) for _ in range(10)] - should_run[0] = True - for t in threads: + threads = [threading.Thread(target=random_load) for _ in range(10)] # pragma: nested + should_run[0] = True # pragma: nested + for t in threads: # pragma: nested t.start() - time.sleep(duration) + time.sleep(duration) # pragma: nested cov.stop() @@ -546,7 +548,7 @@ def test_thread_safe_save_data(tmpdir): for t in threads: t.join() - if (not imported) and duration < 10: + if (not imported) and duration < 10: # pragma: only failure duration *= 2 finally: |