eric6/DebugClients/Python/coverage/collector.py

branch
multi_processing
changeset 7802
eefe954f01e8
parent 7702
f8b97639deb5
equal deleted inserted replaced
7646:39e3db2b4936 7802:eefe954f01e8
193 self.data = {} 193 self.data = {}
194 194
195 # A dictionary mapping file names to file tracer plugin names that will 195 # A dictionary mapping file names to file tracer plugin names that will
196 # handle them. 196 # handle them.
197 self.file_tracers = {} 197 self.file_tracers = {}
198
199 self.disabled_plugins = set()
198 200
199 # The .should_trace_cache attribute is a cache from file names to 201 # The .should_trace_cache attribute is a cache from file names to
200 # coverage.FileDisposition objects, or None. When a file is first 202 # coverage.FileDisposition objects, or None. When a file is first
201 # considered for tracing, a FileDisposition is obtained from 203 # considered for tracing, a FileDisposition is obtained from
202 # Coverage.should_trace. Its .trace attribute indicates whether the 204 # Coverage.should_trace. Its .trace attribute indicates whether the
254 if hasattr(tracer, 'check_include'): 256 if hasattr(tracer, 'check_include'):
255 tracer.check_include = self.check_include 257 tracer.check_include = self.check_include
256 if hasattr(tracer, 'should_start_context'): 258 if hasattr(tracer, 'should_start_context'):
257 tracer.should_start_context = self.should_start_context 259 tracer.should_start_context = self.should_start_context
258 tracer.switch_context = self.switch_context 260 tracer.switch_context = self.switch_context
261 if hasattr(tracer, 'disable_plugin'):
262 tracer.disable_plugin = self.disable_plugin
259 263
260 fn = tracer.start() 264 fn = tracer.start()
261 self.tracers.append(tracer) 265 self.tracers.append(tracer)
262 266
263 return fn 267 return fn
378 if new_context: 382 if new_context:
379 context += "|" + new_context 383 context += "|" + new_context
380 else: 384 else:
381 context = new_context 385 context = new_context
382 self.covdata.set_context(context) 386 self.covdata.set_context(context)
387
388 def disable_plugin(self, disposition):
389 """Disable the plugin mentioned in `disposition`."""
390 file_tracer = disposition.file_tracer
391 plugin = file_tracer._coverage_plugin
392 plugin_name = plugin._coverage_plugin_name
393 self.warn("Disabling plug-in {!r} due to previous exception".format(plugin_name))
394 plugin._coverage_enabled = False
395 disposition.trace = False
383 396
384 def cached_mapped_file(self, filename): 397 def cached_mapped_file(self, filename):
385 """A locally cached version of file names mapped through file_mapper.""" 398 """A locally cached version of file names mapped through file_mapper."""
386 key = (type(filename), filename) 399 key = (type(filename), filename)
387 try: 400 try:
406 else: 419 else:
407 raise runtime_err 420 raise runtime_err
408 421
409 return dict((self.cached_mapped_file(k), v) for k, v in items if v) 422 return dict((self.cached_mapped_file(k), v) for k, v in items if v)
410 423
424 def plugin_was_disabled(self, plugin):
425 """Record that `plugin` was disabled during the run."""
426 self.disabled_plugins.add(plugin._coverage_plugin_name)
427
411 def flush_data(self): 428 def flush_data(self):
412 """Save the collected data to our associated `CoverageData`. 429 """Save the collected data to our associated `CoverageData`.
413 430
414 Data may have also been saved along the way. This forces the 431 Data may have also been saved along the way. This forces the
415 last of the data to be saved. 432 last of the data to be saved.
421 438
422 if self.branch: 439 if self.branch:
423 self.covdata.add_arcs(self.mapped_file_dict(self.data)) 440 self.covdata.add_arcs(self.mapped_file_dict(self.data))
424 else: 441 else:
425 self.covdata.add_lines(self.mapped_file_dict(self.data)) 442 self.covdata.add_lines(self.mapped_file_dict(self.data))
426 self.covdata.add_file_tracers(self.mapped_file_dict(self.file_tracers)) 443
444 file_tracers = {
445 k: v for k, v in self.file_tracers.items()
446 if v not in self.disabled_plugins
447 }
448 self.covdata.add_file_tracers(self.mapped_file_dict(file_tracers))
427 449
428 self._clear_data() 450 self._clear_data()
429 return True 451 return True

eric ide

mercurial