Skip to content

Commit 9afbd1a

Browse files
committed
test: handle excluded lines in coverage plugin
1 parent be4e863 commit 9afbd1a

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
plugins = coverage_plugin
33

44
[report]
5-
exclude_lines =
5+
exclude_also =
66
assert False

coverage_plugin.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_cython_build_rules():
6262

6363

6464
@cache
65-
def parse_all_cfile_lines():
65+
def parse_all_cfile_lines(exclude_patterns=None):
6666
"""Parse all generated C files from the build directory."""
6767
#
6868
# Each .c file can include code generated from multiple Cython files (e.g.
@@ -80,7 +80,7 @@ def parse_all_cfile_lines():
8080

8181
for c_file, _ in get_cython_build_rules():
8282

83-
cfile_lines = parse_cfile_lines(c_file)
83+
cfile_lines = parse_cfile_lines(c_file, exclude_patterns=exclude_patterns)
8484

8585
for cython_file, line_map in cfile_lines.items():
8686
if cython_file == '(tree fragment)':
@@ -94,15 +94,22 @@ def parse_all_cfile_lines():
9494
return all_code_lines
9595

9696

97-
def parse_cfile_lines(c_file):
97+
def parse_cfile_lines(c_file, exclude_patterns=None):
9898
"""Use Cython's coverage plugin to parse the C code."""
9999
from Cython.Coverage import Plugin
100-
return Plugin()._parse_cfile_lines(c_file)
100+
p = Plugin()
101+
p._excluded_line_patterns = list(exclude_patterns)
102+
return p._parse_cfile_lines(c_file)
101103

102104

103105
class Plugin(CoveragePlugin):
104106
"""A coverage plugin for a spin/meson project with Cython code."""
105107

108+
def configure(self, config):
109+
# Entry point for coverage "configurer".
110+
# Read the regular expressions from the coverage config that match lines to be excluded from coverage.
111+
self.exclude_patterns = tuple(config.get_option("report:exclude_lines"))
112+
106113
def file_tracer(self, filename):
107114
"""Find a tracer for filename to handle trace events."""
108115
path = Path(filename)
@@ -121,7 +128,7 @@ def file_tracer(self, filename):
121128
def file_reporter(self, filename):
122129
"""Return a file reporter for filename."""
123130
srcfile = Path(filename).relative_to(src_dir)
124-
return CyFileReporter(srcfile)
131+
return CyFileReporter(srcfile, exclude_patterns=self.exclude_patterns)
125132

126133

127134
class CyFileTracer(FileTracer):
@@ -157,14 +164,15 @@ def get_source_filename(filename):
157164
class CyFileReporter(FileReporter):
158165
"""File reporter for Cython or Python files (.pyx,.pxd,.py)."""
159166

160-
def __init__(self, srcpath):
167+
def __init__(self, srcpath, exclude_patterns):
161168
abspath = (src_dir / srcpath)
162169
assert abspath.exists()
163170

164171
# filepath here needs to match dynamic_source_filename
165172
super().__init__(str(abspath))
166173

167174
self.srcpath = srcpath
175+
self.exclude_patterns = exclude_patterns
168176

169177
def relative_filename(self):
170178
"""Path displayed in the coverage reports."""
@@ -173,7 +181,7 @@ def relative_filename(self):
173181
def lines(self):
174182
"""Set of line numbers for possibly traceable lines."""
175183
srcpath = str(self.srcpath)
176-
all_line_maps = parse_all_cfile_lines()
184+
all_line_maps = parse_all_cfile_lines(exclude_patterns=self.exclude_patterns)
177185
line_map = all_line_maps[srcpath]
178186
return set(line_map)
179187

src/flint/types/fmpz_poly.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ cdef class fmpz_poly(flint_poly):
107107
cdef bint r
108108
if op != 2 and op != 3:
109109
raise TypeError("polynomials cannot be ordered")
110-
self = any_as_fmpz_poly(self)
111-
if self is NotImplemented:
112-
return self
113110
other = any_as_fmpz_poly(other)
114111
if other is NotImplemented:
115112
return other
@@ -456,7 +453,7 @@ cdef class fmpz_poly(flint_poly):
456453
return []
457454
flags = 0
458455
if verbose:
459-
flags = 1
456+
flags = 1 # pragma: no cover
460457
roots = []
461458
fmpz_poly_factor_init(fac)
462459
fmpz_poly_factor_squarefree(fac, self.val)
@@ -551,8 +548,8 @@ cdef class fmpz_poly(flint_poly):
551548
arb_poly_init(t)
552549
arb_poly_swinnerton_dyer_ui(t, n, 0)
553550
if not arb_poly_get_unique_fmpz_poly((<fmpz_poly>u).val, t):
554-
arb_poly_clear(t)
555-
raise ValueError("insufficient precision")
551+
arb_poly_clear(t) # pragma: no cover
552+
raise ValueError("insufficient precision") # pragma: no cover
556553
arb_poly_clear(t)
557554
else:
558555
fmpz_poly_swinnerton_dyer((<fmpz_poly>u).val, n)

0 commit comments

Comments
 (0)