coverage 7.13.1__cp314-cp314t-musllinux_1_2_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. a1_coverage.pth +1 -0
  2. coverage/__init__.py +38 -0
  3. coverage/__main__.py +12 -0
  4. coverage/annotate.py +113 -0
  5. coverage/bytecode.py +197 -0
  6. coverage/cmdline.py +1220 -0
  7. coverage/collector.py +487 -0
  8. coverage/config.py +732 -0
  9. coverage/context.py +74 -0
  10. coverage/control.py +1514 -0
  11. coverage/core.py +139 -0
  12. coverage/data.py +251 -0
  13. coverage/debug.py +669 -0
  14. coverage/disposition.py +59 -0
  15. coverage/env.py +135 -0
  16. coverage/exceptions.py +85 -0
  17. coverage/execfile.py +329 -0
  18. coverage/files.py +553 -0
  19. coverage/html.py +860 -0
  20. coverage/htmlfiles/coverage_html.js +735 -0
  21. coverage/htmlfiles/favicon_32.png +0 -0
  22. coverage/htmlfiles/index.html +199 -0
  23. coverage/htmlfiles/keybd_closed.png +0 -0
  24. coverage/htmlfiles/pyfile.html +149 -0
  25. coverage/htmlfiles/style.css +389 -0
  26. coverage/htmlfiles/style.scss +844 -0
  27. coverage/inorout.py +590 -0
  28. coverage/jsonreport.py +200 -0
  29. coverage/lcovreport.py +218 -0
  30. coverage/misc.py +381 -0
  31. coverage/multiproc.py +120 -0
  32. coverage/numbits.py +146 -0
  33. coverage/parser.py +1215 -0
  34. coverage/patch.py +118 -0
  35. coverage/phystokens.py +197 -0
  36. coverage/plugin.py +617 -0
  37. coverage/plugin_support.py +299 -0
  38. coverage/pth_file.py +16 -0
  39. coverage/py.typed +1 -0
  40. coverage/python.py +272 -0
  41. coverage/pytracer.py +370 -0
  42. coverage/regions.py +127 -0
  43. coverage/report.py +298 -0
  44. coverage/report_core.py +117 -0
  45. coverage/results.py +502 -0
  46. coverage/sqldata.py +1212 -0
  47. coverage/sqlitedb.py +226 -0
  48. coverage/sysmon.py +509 -0
  49. coverage/templite.py +319 -0
  50. coverage/tomlconfig.py +212 -0
  51. coverage/tracer.cpython-314t-aarch64-linux-musl.so +0 -0
  52. coverage/tracer.pyi +43 -0
  53. coverage/types.py +214 -0
  54. coverage/version.py +35 -0
  55. coverage/xmlreport.py +263 -0
  56. coverage-7.13.1.dist-info/METADATA +200 -0
  57. coverage-7.13.1.dist-info/RECORD +61 -0
  58. coverage-7.13.1.dist-info/WHEEL +5 -0
  59. coverage-7.13.1.dist-info/entry_points.txt +4 -0
  60. coverage-7.13.1.dist-info/licenses/LICENSE.txt +177 -0
  61. coverage-7.13.1.dist-info/top_level.txt +1 -0
coverage/collector.py ADDED
@@ -0,0 +1,487 @@
1
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2
+ # For details: https://github.com/coveragepy/coveragepy/blob/main/NOTICE.txt
3
+
4
+ """Raw data collector for coverage.py."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import contextlib
9
+ import functools
10
+ import os
11
+ import sys
12
+ from collections.abc import Callable, Mapping
13
+ from types import FrameType
14
+ from typing import Any, TypeVar, cast
15
+
16
+ from coverage import env
17
+ from coverage.core import Core
18
+ from coverage.data import CoverageData
19
+ from coverage.debug import short_stack
20
+ from coverage.exceptions import ConfigError
21
+ from coverage.misc import human_sorted_items, isolate_module
22
+ from coverage.plugin import CoveragePlugin
23
+ from coverage.types import (
24
+ TArc,
25
+ TCheckIncludeFn,
26
+ TFileDisposition,
27
+ Tracer,
28
+ TShouldStartContextFn,
29
+ TShouldTraceFn,
30
+ TTraceData,
31
+ TTraceFn,
32
+ TWarnFn,
33
+ )
34
+
35
+ os = isolate_module(os)
36
+
37
+
38
+ T = TypeVar("T")
39
+
40
+
41
+ class Collector:
42
+ """Collects trace data.
43
+
44
+ Creates a Tracer object for each thread, since they track stack
45
+ information. Each Tracer points to the same shared data, contributing
46
+ traced data points.
47
+
48
+ When the Collector is started, it creates a Tracer for the current thread,
49
+ and installs a function to create Tracers for each new thread started.
50
+ When the Collector is stopped, all active Tracers are stopped.
51
+
52
+ Threads started while the Collector is stopped will never have Tracers
53
+ associated with them.
54
+
55
+ """
56
+
57
+ # The stack of active Collectors. Collectors are added here when started,
58
+ # and popped when stopped. Collectors on the stack are paused when not
59
+ # the top, and resumed when they become the top again.
60
+ _collectors: list[Collector] = []
61
+
62
+ def __init__(
63
+ self,
64
+ core: Core,
65
+ should_trace: TShouldTraceFn,
66
+ check_include: TCheckIncludeFn,
67
+ should_start_context: TShouldStartContextFn | None,
68
+ file_mapper: Callable[[str], str],
69
+ branch: bool,
70
+ warn: TWarnFn,
71
+ concurrency: list[str],
72
+ ) -> None:
73
+ """Create a collector.
74
+
75
+ `should_trace` is a function, taking a file name and a frame, and
76
+ returning a `coverage.FileDisposition object`.
77
+
78
+ `check_include` is a function taking a file name and a frame. It returns
79
+ a boolean: True if the file should be traced, False if not.
80
+
81
+ `should_start_context` is a function taking a frame, and returning a
82
+ string. If the frame should be the start of a new context, the string
83
+ is the new context. If the frame should not be the start of a new
84
+ context, return None.
85
+
86
+ `file_mapper` is a function taking a filename, and returning a Unicode
87
+ filename. The result is the name that will be recorded in the data
88
+ file.
89
+
90
+ If `branch` is true, then branches will be measured. This involves
91
+ collecting data on which statements followed each other (arcs). Use
92
+ `get_arc_data` to get the arc data.
93
+
94
+ `warn` is a warning function, taking a single string message argument
95
+ and an optional slug argument which will be a string or None, to be
96
+ used if a warning needs to be issued.
97
+
98
+ `concurrency` is a list of strings indicating the concurrency libraries
99
+ in use. Valid values are "greenlet", "eventlet", "gevent", or "thread"
100
+ (the default). "thread" can be combined with one of the other three.
101
+ Other values are ignored.
102
+
103
+ """
104
+ self.core = core
105
+ self.should_trace = should_trace
106
+ self.check_include = check_include
107
+ self.should_start_context = should_start_context
108
+ self.file_mapper = file_mapper
109
+ self.branch = branch
110
+ self.warn = warn
111
+ assert isinstance(concurrency, list), f"Expected a list: {concurrency!r}"
112
+
113
+ self.pid = os.getpid()
114
+
115
+ self.covdata: CoverageData
116
+ self.threading = None
117
+ self.static_context: str | None = None
118
+
119
+ self.origin = short_stack()
120
+
121
+ self.concur_id_func = None
122
+
123
+ do_threading = False
124
+
125
+ tried = "nothing" # to satisfy pylint
126
+ try:
127
+ if "greenlet" in concurrency:
128
+ tried = "greenlet"
129
+ import greenlet
130
+
131
+ self.concur_id_func = greenlet.getcurrent
132
+ elif "eventlet" in concurrency:
133
+ tried = "eventlet"
134
+ import eventlet.greenthread
135
+
136
+ self.concur_id_func = eventlet.greenthread.getcurrent
137
+ elif "gevent" in concurrency:
138
+ tried = "gevent"
139
+ import gevent
140
+
141
+ self.concur_id_func = gevent.getcurrent
142
+
143
+ if "thread" in concurrency:
144
+ do_threading = True
145
+ except ImportError as ex:
146
+ msg = f"Couldn't trace with concurrency={tried}, the module isn't installed."
147
+ raise ConfigError(msg) from ex
148
+
149
+ if self.concur_id_func and not hasattr(core.tracer_class, "concur_id_func"):
150
+ raise ConfigError(
151
+ "Can't support concurrency={} with {}, only threads are supported.".format(
152
+ tried,
153
+ self.tracer_name(),
154
+ ),
155
+ )
156
+
157
+ if do_threading or not concurrency:
158
+ # It's important to import threading only if we need it. If
159
+ # it's imported early, and the program being measured uses
160
+ # gevent, then gevent's monkey-patching won't work properly.
161
+ import threading
162
+
163
+ self.threading = threading
164
+
165
+ self.reset()
166
+
167
+ def __repr__(self) -> str:
168
+ return f"<Collector at {id(self):#x}: {self.tracer_name()}>"
169
+
170
+ def use_data(self, covdata: CoverageData, context: str | None) -> None:
171
+ """Use `covdata` for recording data."""
172
+ self.covdata = covdata
173
+ self.static_context = context
174
+ self.covdata.set_context(self.static_context)
175
+
176
+ def tracer_name(self) -> str:
177
+ """Return the class name of the tracer we're using."""
178
+ return self.core.tracer_class.__name__
179
+
180
+ def _clear_data(self) -> None:
181
+ """Clear out existing data, but stay ready for more collection."""
182
+ # We used to use self.data.clear(), but that would remove filename
183
+ # keys and data values that were still in use higher up the stack
184
+ # when we are called as part of switch_context.
185
+ with self.data_lock or contextlib.nullcontext():
186
+ for d in self.data.values():
187
+ d.clear()
188
+
189
+ for tracer in self.tracers:
190
+ tracer.reset_activity()
191
+
192
+ def reset(self) -> None:
193
+ """Clear collected data, and prepare to collect more."""
194
+ self.data_lock = self.threading.Lock() if self.threading else None
195
+
196
+ # The trace data we are collecting.
197
+ self.data: TTraceData = {}
198
+
199
+ # A dictionary mapping file names to file tracer plugin names that will
200
+ # handle them.
201
+ self.file_tracers: dict[str, str] = {}
202
+
203
+ self.disabled_plugins: set[str] = set()
204
+
205
+ # The .should_trace_cache attribute is a cache from file names to
206
+ # coverage.FileDisposition objects, or None. When a file is first
207
+ # considered for tracing, a FileDisposition is obtained from
208
+ # Coverage.should_trace. Its .trace attribute indicates whether the
209
+ # file should be traced or not. If it should be, a plugin with dynamic
210
+ # file names can decide not to trace it based on the dynamic file name
211
+ # being excluded by the inclusion rules, in which case the
212
+ # FileDisposition will be replaced by None in the cache.
213
+ if env.PYPY:
214
+ import __pypy__ # pylint: disable=import-error
215
+
216
+ # Alex Gaynor said:
217
+ # should_trace_cache is a strictly growing key: once a key is in
218
+ # it, it never changes. Further, the keys used to access it are
219
+ # generally constant, given sufficient context. That is to say, at
220
+ # any given point _trace() is called, pypy is able to know the key.
221
+ # This is because the key is determined by the physical source code
222
+ # line, and that's invariant with the call site.
223
+ #
224
+ # This property of a dict with immutable keys, combined with
225
+ # call-site-constant keys is a match for PyPy's module dict,
226
+ # which is optimized for such workloads.
227
+ #
228
+ # This gives a 20% benefit on the workload described at
229
+ # https://bitbucket.org/pypy/pypy/issue/1871/10x-slower-than-cpython-under-coverage
230
+ self.should_trace_cache = __pypy__.newdict("module")
231
+ else:
232
+ self.should_trace_cache = {}
233
+
234
+ # Our active Tracers.
235
+ self.tracers: list[Tracer] = []
236
+
237
+ self._clear_data()
238
+
239
+ def lock_data(self) -> None:
240
+ """Lock self.data_lock, for use by the C tracer."""
241
+ if self.data_lock is not None:
242
+ self.data_lock.acquire()
243
+
244
+ def unlock_data(self) -> None:
245
+ """Unlock self.data_lock, for use by the C tracer."""
246
+ if self.data_lock is not None:
247
+ self.data_lock.release()
248
+
249
+ def _start_tracer(self) -> TTraceFn | None:
250
+ """Start a new Tracer object, and store it in self.tracers."""
251
+ tracer = self.core.tracer_class(**self.core.tracer_kwargs)
252
+ tracer.data = self.data
253
+ tracer.lock_data = self.lock_data
254
+ tracer.unlock_data = self.unlock_data
255
+ tracer.trace_arcs = self.branch
256
+ tracer.should_trace = self.should_trace
257
+ tracer.should_trace_cache = self.should_trace_cache
258
+ tracer.warn = self.warn
259
+
260
+ if hasattr(tracer, "concur_id_func"):
261
+ tracer.concur_id_func = self.concur_id_func
262
+ if hasattr(tracer, "file_tracers"):
263
+ tracer.file_tracers = self.file_tracers
264
+ if hasattr(tracer, "threading"):
265
+ tracer.threading = self.threading
266
+ if hasattr(tracer, "check_include"):
267
+ tracer.check_include = self.check_include
268
+ if hasattr(tracer, "should_start_context"):
269
+ tracer.should_start_context = self.should_start_context
270
+ if hasattr(tracer, "switch_context"):
271
+ tracer.switch_context = self.switch_context
272
+ if hasattr(tracer, "disable_plugin"):
273
+ tracer.disable_plugin = self.disable_plugin
274
+
275
+ fn = tracer.start()
276
+ self.tracers.append(tracer)
277
+
278
+ return fn
279
+
280
+ # The trace function has to be set individually on each thread before
281
+ # execution begins. Ironically, the only support the threading module has
282
+ # for running code before the thread main is the tracing function. So we
283
+ # install this as a trace function, and the first time it's called, it does
284
+ # the real trace installation.
285
+ #
286
+ # PYVERSIONS
287
+ # New in 3.12: threading.settrace_all_threads: https://github.com/python/cpython/pull/96681
288
+
289
+ def _installation_trace(self, frame: FrameType, event: str, arg: Any) -> TTraceFn | None:
290
+ """Called on new threads, installs the real tracer."""
291
+ # Remove ourselves as the trace function.
292
+ sys.settrace(None)
293
+ # Install the real tracer.
294
+ fn: TTraceFn | None = self._start_tracer()
295
+ # Invoke the real trace function with the current event, to be sure
296
+ # not to lose an event.
297
+ if fn:
298
+ fn = fn(frame, event, arg)
299
+ # Return the new trace function to continue tracing in this scope.
300
+ return fn
301
+
302
+ def start(self) -> None:
303
+ """Start collecting trace information."""
304
+ # We may be a new collector in a forked process. The old process'
305
+ # collectors will be in self._collectors, but they won't be usable.
306
+ # Find them and discard them.
307
+ keep_collectors = []
308
+ for c in self._collectors:
309
+ if c.pid == self.pid:
310
+ keep_collectors.append(c)
311
+ else:
312
+ c.post_fork()
313
+ self._collectors[:] = keep_collectors
314
+
315
+ if self._collectors:
316
+ self._collectors[-1].pause()
317
+
318
+ self.tracers = []
319
+
320
+ try:
321
+ # Install the tracer on this thread.
322
+ self._start_tracer()
323
+ except:
324
+ if self._collectors:
325
+ self._collectors[-1].resume()
326
+ raise
327
+
328
+ # If _start_tracer succeeded, then we add ourselves to the global
329
+ # stack of collectors.
330
+ self._collectors.append(self)
331
+
332
+ # Install our installation tracer in threading, to jump-start other
333
+ # threads.
334
+ if self.core.systrace and self.threading:
335
+ self.threading.settrace(self._installation_trace)
336
+
337
+ def stop(self) -> None:
338
+ """Stop collecting trace information."""
339
+ assert self._collectors
340
+ if self._collectors[-1] is not self:
341
+ print("self._collectors:")
342
+ for c in self._collectors:
343
+ print(f" {c!r}\n{c.origin}")
344
+ assert self._collectors[-1] is self, (
345
+ f"Expected current collector to be {self!r}, but it's {self._collectors[-1]!r}"
346
+ )
347
+
348
+ self.pause()
349
+
350
+ # Remove this Collector from the stack, and resume the one underneath (if any).
351
+ self._collectors.pop()
352
+ if self._collectors:
353
+ self._collectors[-1].resume()
354
+
355
+ def pause(self) -> None:
356
+ """Pause tracing, but be prepared to `resume`."""
357
+ for tracer in self.tracers:
358
+ tracer.stop()
359
+ stats = tracer.get_stats()
360
+ if stats:
361
+ print(f"\nCoverage.py {tracer.__class__.__name__} stats:")
362
+ for k, v in human_sorted_items(stats.items()):
363
+ print(f"{k:>20}: {v}")
364
+ if self.threading:
365
+ self.threading.settrace(None)
366
+
367
+ def resume(self) -> None:
368
+ """Resume tracing after a `pause`."""
369
+ for tracer in self.tracers:
370
+ tracer.start()
371
+ if self.core.systrace:
372
+ if self.threading:
373
+ self.threading.settrace(self._installation_trace)
374
+ else:
375
+ self._start_tracer()
376
+
377
+ def post_fork(self) -> None:
378
+ """After a fork, tracers might need to adjust."""
379
+ for tracer in self.tracers:
380
+ if hasattr(tracer, "post_fork"):
381
+ tracer.post_fork()
382
+
383
+ def _activity(self) -> bool:
384
+ """Has any activity been traced?
385
+
386
+ Returns a boolean, True if any trace function was invoked.
387
+
388
+ """
389
+ return any(tracer.activity() for tracer in self.tracers)
390
+
391
+ def switch_context(self, new_context: str | None) -> None:
392
+ """Switch to a new dynamic context."""
393
+ context: str | None
394
+ self.flush_data()
395
+ if self.static_context:
396
+ context = self.static_context
397
+ if new_context:
398
+ context += "|" + new_context
399
+ else:
400
+ context = new_context
401
+ self.covdata.set_context(context)
402
+
403
+ def disable_plugin(self, disposition: TFileDisposition) -> None:
404
+ """Disable the plugin mentioned in `disposition`."""
405
+ file_tracer = disposition.file_tracer
406
+ assert file_tracer is not None
407
+ plugin = file_tracer._coverage_plugin
408
+ plugin_name = plugin._coverage_plugin_name
409
+ self.warn(f"Disabling plug-in {plugin_name!r} due to previous exception")
410
+ plugin._coverage_enabled = False
411
+ disposition.trace = False
412
+
413
+ @functools.cache # pylint: disable=method-cache-max-size-none
414
+ def cached_mapped_file(self, filename: str) -> str:
415
+ """A locally cached version of file names mapped through file_mapper."""
416
+ return self.file_mapper(filename)
417
+
418
+ def mapped_file_dict(self, d: Mapping[str, T]) -> dict[str, T]:
419
+ """Return a dict like d, but with keys modified by file_mapper."""
420
+ # The call to list(items()) ensures that the GIL protects the dictionary
421
+ # iterator against concurrent modifications by tracers running
422
+ # in other threads. We try three times in case of concurrent
423
+ # access, hoping to get a clean copy.
424
+ runtime_err = None
425
+ for _ in range(3): # pragma: part covered
426
+ try:
427
+ items = list(d.items())
428
+ except RuntimeError as ex: # pragma: cant happen
429
+ runtime_err = ex
430
+ else:
431
+ break
432
+ else: # pragma: cant happen
433
+ assert isinstance(runtime_err, Exception)
434
+ raise runtime_err
435
+
436
+ return {self.cached_mapped_file(k): v for k, v in items if v}
437
+
438
+ def plugin_was_disabled(self, plugin: CoveragePlugin) -> None:
439
+ """Record that `plugin` was disabled during the run."""
440
+ self.disabled_plugins.add(plugin._coverage_plugin_name)
441
+
442
+ def flush_data(self) -> bool:
443
+ """Save the collected data to our associated `CoverageData`.
444
+
445
+ Data may have also been saved along the way. This forces the
446
+ last of the data to be saved.
447
+
448
+ Returns True if there was data to save, False if not.
449
+ """
450
+ if not self._activity():
451
+ return False
452
+
453
+ if self.branch:
454
+ if self.core.packed_arcs:
455
+ # Unpack the line number pairs packed into integers. See
456
+ # tracer.c:CTracer_record_pair for the C code that creates
457
+ # these packed ints.
458
+ arc_data: dict[str, list[TArc]] = {}
459
+ packed_data = cast(dict[str, set[int]], self.data)
460
+
461
+ # The list() here and in the inner loop are to get a clean copy
462
+ # even as tracers are continuing to add data.
463
+ for fname, packeds in list(packed_data.items()):
464
+ tuples = []
465
+ for packed in list(packeds):
466
+ l1 = packed & 0xFFFFF
467
+ l2 = (packed & (0xFFFFF << 20)) >> 20
468
+ if packed & (1 << 40):
469
+ l1 *= -1
470
+ if packed & (1 << 41):
471
+ l2 *= -1
472
+ tuples.append((l1, l2))
473
+ arc_data[fname] = tuples
474
+ else:
475
+ arc_data = cast(dict[str, list[TArc]], self.data)
476
+ self.covdata.add_arcs(self.mapped_file_dict(arc_data))
477
+ else:
478
+ line_data = cast(dict[str, set[int]], self.data)
479
+ self.covdata.add_lines(self.mapped_file_dict(line_data))
480
+
481
+ file_tracers = {
482
+ k: v for k, v in self.file_tracers.items() if v not in self.disabled_plugins
483
+ }
484
+ self.covdata.add_file_tracers(self.mapped_file_dict(file_tracers))
485
+
486
+ self._clear_data()
487
+ return True