coverage 7.11.1__cp314-cp314-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 (59) hide show
  1. coverage/__init__.py +40 -0
  2. coverage/__main__.py +12 -0
  3. coverage/annotate.py +114 -0
  4. coverage/bytecode.py +196 -0
  5. coverage/cmdline.py +1184 -0
  6. coverage/collector.py +486 -0
  7. coverage/config.py +731 -0
  8. coverage/context.py +74 -0
  9. coverage/control.py +1481 -0
  10. coverage/core.py +139 -0
  11. coverage/data.py +227 -0
  12. coverage/debug.py +669 -0
  13. coverage/disposition.py +59 -0
  14. coverage/env.py +135 -0
  15. coverage/exceptions.py +91 -0
  16. coverage/execfile.py +329 -0
  17. coverage/files.py +553 -0
  18. coverage/html.py +856 -0
  19. coverage/htmlfiles/coverage_html.js +733 -0
  20. coverage/htmlfiles/favicon_32.png +0 -0
  21. coverage/htmlfiles/index.html +164 -0
  22. coverage/htmlfiles/keybd_closed.png +0 -0
  23. coverage/htmlfiles/pyfile.html +149 -0
  24. coverage/htmlfiles/style.css +377 -0
  25. coverage/htmlfiles/style.scss +824 -0
  26. coverage/inorout.py +614 -0
  27. coverage/jsonreport.py +188 -0
  28. coverage/lcovreport.py +219 -0
  29. coverage/misc.py +373 -0
  30. coverage/multiproc.py +120 -0
  31. coverage/numbits.py +146 -0
  32. coverage/parser.py +1213 -0
  33. coverage/patch.py +166 -0
  34. coverage/phystokens.py +197 -0
  35. coverage/plugin.py +617 -0
  36. coverage/plugin_support.py +299 -0
  37. coverage/py.typed +1 -0
  38. coverage/python.py +269 -0
  39. coverage/pytracer.py +369 -0
  40. coverage/regions.py +127 -0
  41. coverage/report.py +298 -0
  42. coverage/report_core.py +117 -0
  43. coverage/results.py +471 -0
  44. coverage/sqldata.py +1153 -0
  45. coverage/sqlitedb.py +239 -0
  46. coverage/sysmon.py +474 -0
  47. coverage/templite.py +306 -0
  48. coverage/tomlconfig.py +210 -0
  49. coverage/tracer.cpython-314-aarch64-linux-musl.so +0 -0
  50. coverage/tracer.pyi +43 -0
  51. coverage/types.py +206 -0
  52. coverage/version.py +35 -0
  53. coverage/xmlreport.py +264 -0
  54. coverage-7.11.1.dist-info/METADATA +221 -0
  55. coverage-7.11.1.dist-info/RECORD +59 -0
  56. coverage-7.11.1.dist-info/WHEEL +5 -0
  57. coverage-7.11.1.dist-info/entry_points.txt +4 -0
  58. coverage-7.11.1.dist-info/licenses/LICENSE.txt +177 -0
  59. coverage-7.11.1.dist-info/top_level.txt +1 -0
coverage/pytracer.py ADDED
@@ -0,0 +1,369 @@
1
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
3
+
4
+ """Raw data collector for coverage.py."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import atexit
9
+ import dis
10
+ import itertools
11
+ import sys
12
+ import threading
13
+ from types import FrameType, ModuleType
14
+ from typing import Any, Callable, cast
15
+
16
+ from coverage import env
17
+ from coverage.types import (
18
+ TArc,
19
+ TFileDisposition,
20
+ TLineNo,
21
+ Tracer,
22
+ TShouldStartContextFn,
23
+ TShouldTraceFn,
24
+ TTraceData,
25
+ TTraceFileData,
26
+ TTraceFn,
27
+ TWarnFn,
28
+ )
29
+
30
+ # I don't understand why, but if we use `cast(set[TLineNo], ...)` inside
31
+ # the _trace() function, we get some strange behavior on PyPy 3.10.
32
+ # Assigning these names here and using them below fixes the problem.
33
+ # See https://github.com/nedbat/coveragepy/issues/1902
34
+ set_TLineNo = set[TLineNo]
35
+ set_TArc = set[TArc]
36
+
37
+
38
+ # We need the YIELD_VALUE opcode below, in a comparison-friendly form.
39
+ # PYVERSIONS: RESUME is new in Python3.11
40
+ RESUME = dis.opmap.get("RESUME")
41
+ RETURN_VALUE = dis.opmap["RETURN_VALUE"]
42
+ if RESUME is None:
43
+ YIELD_VALUE = dis.opmap["YIELD_VALUE"]
44
+ YIELD_FROM = dis.opmap["YIELD_FROM"]
45
+ YIELD_FROM_OFFSET = 0 if env.PYPY else 2
46
+ else:
47
+ YIELD_VALUE = YIELD_FROM = YIELD_FROM_OFFSET = -1
48
+
49
+ # When running meta-coverage, this file can try to trace itself, which confuses
50
+ # everything. Don't trace ourselves.
51
+
52
+ THIS_FILE = __file__.rstrip("co")
53
+
54
+
55
+ class PyTracer(Tracer):
56
+ """Python implementation of the raw data tracer."""
57
+
58
+ # Because of poor implementations of trace-function-manipulating tools,
59
+ # the Python trace function must be kept very simple. In particular, there
60
+ # must be only one function ever set as the trace function, both through
61
+ # sys.settrace, and as the return value from the trace function. Put
62
+ # another way, the trace function must always return itself. It cannot
63
+ # swap in other functions, or return None to avoid tracing a particular
64
+ # frame.
65
+ #
66
+ # The trace manipulator that introduced this restriction is DecoratorTools,
67
+ # which sets a trace function, and then later restores the pre-existing one
68
+ # by calling sys.settrace with a function it found in the current frame.
69
+ #
70
+ # Systems that use DecoratorTools (or similar trace manipulations) must use
71
+ # PyTracer to get accurate results. The command-line --timid argument is
72
+ # used to force the use of this tracer.
73
+
74
+ tracer_ids = itertools.count()
75
+
76
+ def __init__(self) -> None:
77
+ # Which tracer are we?
78
+ self.id = next(self.tracer_ids)
79
+
80
+ # Attributes set from the collector:
81
+ self.data: TTraceData
82
+ self.trace_arcs = False
83
+ self.should_trace: TShouldTraceFn
84
+ self.should_trace_cache: dict[str, TFileDisposition | None]
85
+ self.should_start_context: TShouldStartContextFn | None = None
86
+ self.switch_context: Callable[[str | None], None] | None = None
87
+ self.lock_data: Callable[[], None]
88
+ self.unlock_data: Callable[[], None]
89
+ self.warn: TWarnFn
90
+
91
+ # The threading module to use, if any.
92
+ self.threading: ModuleType | None = None
93
+
94
+ self.cur_file_data: TTraceFileData | None = None
95
+ self.last_line: TLineNo = 0
96
+ self.cur_file_name: str | None = None
97
+ self.context: str | None = None
98
+ self.started_context = False
99
+
100
+ # The data_stack parallels the Python call stack. Each entry is
101
+ # information about an active frame, a four-element tuple:
102
+ # [0] The TTraceData for this frame's file. Could be None if we
103
+ # aren't tracing this frame.
104
+ # [1] The current file name for the frame. None if we aren't tracing
105
+ # this frame.
106
+ # [2] The last line number executed in this frame.
107
+ # [3] Boolean: did this frame start a new context?
108
+ self.data_stack: list[tuple[TTraceFileData | None, str | None, TLineNo, bool]] = []
109
+ self.thread: threading.Thread | None = None
110
+ self.stopped = False
111
+ self._activity = False
112
+
113
+ self.in_atexit = False
114
+ # On exit, self.in_atexit = True
115
+ atexit.register(setattr, self, "in_atexit", True)
116
+
117
+ # Cache a bound method on the instance, so that we don't have to
118
+ # re-create a bound method object all the time.
119
+ self._cached_bound_method_trace: TTraceFn = self._trace
120
+
121
+ def __repr__(self) -> str:
122
+ points = sum(len(v) for v in self.data.values())
123
+ files = len(self.data)
124
+ return f"<PyTracer at {id(self):#x}: {points} data points in {files} files>"
125
+
126
+ def log(self, marker: str, *args: Any) -> None:
127
+ """For hard-core logging of what this tracer is doing."""
128
+ with open("/tmp/debug_trace.txt", "a", encoding="utf-8") as f:
129
+ f.write(f"{marker} {self.id}[{len(self.data_stack)}]")
130
+ if 0: # if you want thread ids..
131
+ f.write( # type: ignore[unreachable]
132
+ ".{:x}.{:x}".format(
133
+ self.thread.ident,
134
+ self.threading.current_thread().ident,
135
+ )
136
+ )
137
+ f.write(" {}".format(" ".join(map(str, args))))
138
+ if 0: # if you want callers..
139
+ f.write(" | ") # type: ignore[unreachable]
140
+ stack = " / ".join(
141
+ (fname or "???").rpartition("/")[-1] for _, fname, _, _ in self.data_stack
142
+ )
143
+ f.write(stack)
144
+ f.write("\n")
145
+
146
+ def _trace(
147
+ self,
148
+ frame: FrameType,
149
+ event: str,
150
+ arg: Any, # pylint: disable=unused-argument
151
+ lineno: TLineNo | None = None, # pylint: disable=unused-argument
152
+ ) -> TTraceFn | None:
153
+ """The trace function passed to sys.settrace."""
154
+
155
+ if THIS_FILE in frame.f_code.co_filename:
156
+ return None
157
+
158
+ # f = frame; code = f.f_code
159
+ # self.log(":", f"{code.co_filename} {f.f_lineno} {code.co_name}()", event)
160
+
161
+ if self.stopped and sys.gettrace() == self._cached_bound_method_trace: # pylint: disable=comparison-with-callable
162
+ # The PyTrace.stop() method has been called, possibly by another
163
+ # thread, let's deactivate ourselves now.
164
+ if 0:
165
+ f = frame # type: ignore[unreachable]
166
+ self.log("---\nX", f.f_code.co_filename, f.f_lineno)
167
+ while f:
168
+ self.log(">", f.f_code.co_filename, f.f_lineno, f.f_code.co_name, f.f_trace)
169
+ f = f.f_back
170
+ sys.settrace(None)
171
+ try:
172
+ self.cur_file_data, self.cur_file_name, self.last_line, self.started_context = (
173
+ self.data_stack.pop()
174
+ )
175
+ except IndexError:
176
+ self.log(
177
+ "Empty stack!",
178
+ frame.f_code.co_filename,
179
+ frame.f_lineno,
180
+ frame.f_code.co_name,
181
+ )
182
+ return None
183
+
184
+ # if event != "call" and frame.f_code.co_filename != self.cur_file_name:
185
+ # self.log("---\n*", frame.f_code.co_filename, self.cur_file_name, frame.f_lineno)
186
+
187
+ if event == "call":
188
+ # Should we start a new context?
189
+ if self.should_start_context and self.context is None:
190
+ context_maybe = self.should_start_context(frame) # pylint: disable=not-callable
191
+ if context_maybe is not None:
192
+ self.context = context_maybe
193
+ started_context = True
194
+ assert self.switch_context is not None
195
+ self.switch_context(self.context) # pylint: disable=not-callable
196
+ else:
197
+ started_context = False
198
+ else:
199
+ started_context = False
200
+ self.started_context = started_context
201
+
202
+ # Entering a new frame. Decide if we should trace in this file.
203
+ self._activity = True
204
+ self.data_stack.append(
205
+ (
206
+ self.cur_file_data,
207
+ self.cur_file_name,
208
+ self.last_line,
209
+ started_context,
210
+ ),
211
+ )
212
+
213
+ # Improve tracing performance: when calling a function, both caller
214
+ # and callee are often within the same file. if that's the case, we
215
+ # don't have to re-check whether to trace the corresponding
216
+ # function (which is a little bit expensive since it involves
217
+ # dictionary lookups). This optimization is only correct if we
218
+ # didn't start a context.
219
+ filename = frame.f_code.co_filename
220
+ if filename != self.cur_file_name or started_context:
221
+ self.cur_file_name = filename
222
+ disp = self.should_trace_cache.get(filename)
223
+ if disp is None:
224
+ disp = self.should_trace(filename, frame)
225
+ self.should_trace_cache[filename] = disp
226
+
227
+ self.cur_file_data = None
228
+ if disp.trace:
229
+ tracename = disp.source_filename
230
+ assert tracename is not None
231
+ self.lock_data()
232
+ try:
233
+ if tracename not in self.data:
234
+ self.data[tracename] = set()
235
+ finally:
236
+ self.unlock_data()
237
+ self.cur_file_data = self.data[tracename]
238
+ else:
239
+ frame.f_trace_lines = False
240
+ elif not self.cur_file_data:
241
+ frame.f_trace_lines = False
242
+
243
+ # The call event is really a "start frame" event, and happens for
244
+ # function calls and re-entering generators. The f_lasti field is
245
+ # -1 for calls, and a real offset for generators. Use <0 as the
246
+ # line number for calls, and the real line number for generators.
247
+ if RESUME is not None:
248
+ # The current opcode is guaranteed to be RESUME. The argument
249
+ # determines what kind of resume it is.
250
+ oparg = frame.f_code.co_code[frame.f_lasti + 1]
251
+ real_call = (oparg == 0) # fmt: skip
252
+ else:
253
+ real_call = (getattr(frame, "f_lasti", -1) < 0) # fmt: skip
254
+ if real_call:
255
+ self.last_line = -frame.f_code.co_firstlineno
256
+ else:
257
+ self.last_line = frame.f_lineno
258
+
259
+ elif event == "line":
260
+ # Record an executed line.
261
+ if self.cur_file_data is not None:
262
+ flineno: TLineNo = frame.f_lineno
263
+
264
+ if self.trace_arcs:
265
+ cast(set_TArc, self.cur_file_data).add((self.last_line, flineno))
266
+ else:
267
+ cast(set_TLineNo, self.cur_file_data).add(flineno)
268
+ self.last_line = flineno
269
+
270
+ elif event == "return":
271
+ if self.trace_arcs and self.cur_file_data:
272
+ # Record an arc leaving the function, but beware that a
273
+ # "return" event might just mean yielding from a generator.
274
+ code = frame.f_code.co_code
275
+ lasti = frame.f_lasti
276
+ if RESUME is not None:
277
+ if len(code) == lasti + 2:
278
+ # A return from the end of a code object is a real return.
279
+ real_return = True
280
+ else:
281
+ # It is a real return if we aren't going to resume next.
282
+ if env.PYBEHAVIOR.lasti_is_yield:
283
+ lasti += 2
284
+ real_return = code[lasti] != RESUME
285
+ else:
286
+ if code[lasti] == RETURN_VALUE:
287
+ real_return = True
288
+ elif code[lasti] == YIELD_VALUE:
289
+ real_return = False
290
+ elif len(code) <= lasti + YIELD_FROM_OFFSET:
291
+ real_return = True
292
+ elif code[lasti + YIELD_FROM_OFFSET] == YIELD_FROM:
293
+ real_return = False
294
+ else:
295
+ real_return = True
296
+ if real_return:
297
+ first = frame.f_code.co_firstlineno
298
+ cast(set_TArc, self.cur_file_data).add((self.last_line, -first))
299
+
300
+ # Leaving this function, pop the filename stack.
301
+ self.cur_file_data, self.cur_file_name, self.last_line, self.started_context = (
302
+ self.data_stack.pop()
303
+ )
304
+ # Leaving a context?
305
+ if self.started_context:
306
+ assert self.switch_context is not None
307
+ self.context = None
308
+ self.switch_context(None) # pylint: disable=not-callable
309
+
310
+ return self._cached_bound_method_trace
311
+
312
+ def start(self) -> TTraceFn:
313
+ """Start this Tracer.
314
+
315
+ Return a Python function suitable for use with sys.settrace().
316
+
317
+ """
318
+ self.stopped = False
319
+ if self.threading:
320
+ if self.thread is None:
321
+ self.thread = self.threading.current_thread()
322
+
323
+ sys.settrace(self._cached_bound_method_trace)
324
+ return self._cached_bound_method_trace
325
+
326
+ def stop(self) -> None:
327
+ """Stop this Tracer."""
328
+ # Get the active tracer callback before setting the stop flag to be
329
+ # able to detect if the tracer was changed prior to stopping it.
330
+ tf = sys.gettrace()
331
+
332
+ # Set the stop flag. The actual call to sys.settrace(None) will happen
333
+ # in the self._trace callback itself to make sure to call it from the
334
+ # right thread.
335
+ self.stopped = True
336
+
337
+ if self.threading:
338
+ assert self.thread is not None
339
+ if self.thread.ident != self.threading.current_thread().ident:
340
+ # Called on a different thread than started us: we can't unhook
341
+ # ourselves, but we've set the flag that we should stop, so we
342
+ # won't do any more tracing.
343
+ # self.log("~", "stopping on different threads")
344
+ return
345
+
346
+ # PyPy clears the trace function before running atexit functions,
347
+ # so don't warn if we are in atexit on PyPy and the trace function
348
+ # has changed to None. Metacoverage also messes this up, so don't
349
+ # warn if we are measuring ourselves.
350
+ suppress_warning = (env.PYPY and self.in_atexit and tf is None) or env.METACOV
351
+ if self.warn and not suppress_warning:
352
+ if tf != self._cached_bound_method_trace: # pylint: disable=comparison-with-callable
353
+ self.warn(
354
+ "Trace function changed, data is likely wrong: "
355
+ + f"{tf!r} != {self._cached_bound_method_trace!r}",
356
+ slug="trace-changed",
357
+ )
358
+
359
+ def activity(self) -> bool:
360
+ """Has there been any activity?"""
361
+ return self._activity
362
+
363
+ def reset_activity(self) -> None:
364
+ """Reset the activity() flag."""
365
+ self._activity = False
366
+
367
+ def get_stats(self) -> dict[str, int] | None:
368
+ """Return a dictionary of statistics, or None."""
369
+ return None
coverage/regions.py ADDED
@@ -0,0 +1,127 @@
1
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
3
+
4
+ """Find functions and classes in Python code."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import ast
9
+ import dataclasses
10
+ from typing import cast
11
+
12
+ from coverage.plugin import CodeRegion
13
+
14
+
15
+ @dataclasses.dataclass
16
+ class Context:
17
+ """The nested named context of a function or class."""
18
+
19
+ name: str
20
+ kind: str
21
+ lines: set[int]
22
+
23
+
24
+ class RegionFinder:
25
+ """An ast visitor that will find and track regions of code.
26
+
27
+ Functions and classes are tracked by name. Results are in the .regions
28
+ attribute.
29
+
30
+ """
31
+
32
+ def __init__(self) -> None:
33
+ self.regions: list[CodeRegion] = []
34
+ self.context: list[Context] = []
35
+
36
+ def parse_source(self, source: str) -> None:
37
+ """Parse `source` and walk the ast to populate the .regions attribute."""
38
+ self.handle_node(ast.parse(source))
39
+
40
+ def fq_node_name(self) -> str:
41
+ """Get the current fully qualified name we're processing."""
42
+ return ".".join(c.name for c in self.context)
43
+
44
+ def handle_node(self, node: ast.AST) -> None:
45
+ """Recursively handle any node."""
46
+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
47
+ self.handle_FunctionDef(node)
48
+ elif isinstance(node, ast.ClassDef):
49
+ self.handle_ClassDef(node)
50
+ else:
51
+ self.handle_node_body(node)
52
+
53
+ def handle_node_body(self, node: ast.AST) -> None:
54
+ """Recursively handle the nodes in this node's body, if any."""
55
+ for body_node in getattr(node, "body", ()):
56
+ self.handle_node(body_node)
57
+
58
+ def handle_FunctionDef(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
59
+ """Called for `def` or `async def`."""
60
+ lines = set(range(node.body[0].lineno, cast(int, node.body[-1].end_lineno) + 1))
61
+ if self.context and self.context[-1].kind == "class":
62
+ # Function bodies are part of their enclosing class.
63
+ self.context[-1].lines |= lines
64
+ # Function bodies should be excluded from the nearest enclosing function.
65
+ for ancestor in reversed(self.context):
66
+ if ancestor.kind == "function":
67
+ ancestor.lines -= lines
68
+ break
69
+ self.context.append(Context(node.name, "function", lines))
70
+ self.regions.append(
71
+ CodeRegion(
72
+ kind="function",
73
+ name=self.fq_node_name(),
74
+ start=node.lineno,
75
+ lines=lines,
76
+ )
77
+ )
78
+ self.handle_node_body(node)
79
+ self.context.pop()
80
+
81
+ def handle_ClassDef(self, node: ast.ClassDef) -> None:
82
+ """Called for `class`."""
83
+ # The lines for a class are the lines in the methods of the class.
84
+ # We start empty, and count on visit_FunctionDef to add the lines it
85
+ # finds.
86
+ lines: set[int] = set()
87
+ self.context.append(Context(node.name, "class", lines))
88
+ self.regions.append(
89
+ CodeRegion(
90
+ kind="class",
91
+ name=self.fq_node_name(),
92
+ start=node.lineno,
93
+ lines=lines,
94
+ )
95
+ )
96
+ self.handle_node_body(node)
97
+ self.context.pop()
98
+ # Class bodies should be excluded from the enclosing classes.
99
+ for ancestor in reversed(self.context):
100
+ if ancestor.kind == "class":
101
+ ancestor.lines -= lines
102
+
103
+
104
+ def code_regions(source: str) -> list[CodeRegion]:
105
+ """Find function and class regions in source code.
106
+
107
+ Analyzes the code in `source`, and returns a list of :class:`CodeRegion`
108
+ objects describing functions and classes as regions of the code::
109
+
110
+ [
111
+ CodeRegion(kind="function", name="func1", start=8, lines={10, 11, 12}),
112
+ CodeRegion(kind="function", name="MyClass.method", start=30, lines={34, 35, 36}),
113
+ CodeRegion(kind="class", name="MyClass", start=25, lines={34, 35, 36}),
114
+ ]
115
+
116
+ The line numbers will include comments and blank lines. Later processing
117
+ will need to ignore those lines as needed.
118
+
119
+ Nested functions and classes are excluded from their enclosing region. No
120
+ line should be reported as being part of more than one function, or more
121
+ than one class. Lines in methods are reported as being in a function and
122
+ in a class.
123
+
124
+ """
125
+ rf = RegionFinder()
126
+ rf.parse_source(source)
127
+ return rf.regions