Skip to content

Commit 63ef3d8

Browse files
committed
Add some "pragma: no cover" guards
1 parent f78fdce commit 63ef3d8

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

run

+11-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ function packaging_pypi() {
3030
check-wheel-contents dist/*.whl --ignore W002 --toplevel "pypdfium2,pypdfium2_raw"
3131
}
3232

33+
function coverage_impl() {
34+
python3 -m coverage run --omit "$OMISSIONS" -m pytest tests/ $args
35+
python3 -m coverage report
36+
}
37+
3338
set -x
3439

3540
case $1 in
@@ -38,11 +43,12 @@ test)
3843
python3 -m pytest tests/ $args;;
3944

4045
coverage)
41-
# you can add src/pypdfium2/__main__.py,src/pypdfium2/_cli/* to omission list to check only the core library
42-
# also, you may want to add src/pypdfium2/_library_scope.py because coverage seems to be unreliable for that one
43-
# BTW, you may get a minor increase in coverage by setting DEBUG_AUTOCLOSE=1
44-
python3 -m coverage run --omit "src/pypdfium2_raw/bindings.py,tests/*,setupsrc/*" -m pytest tests/ $args
45-
python3 -m coverage report;;
46+
OMISSIONS="src/pypdfium2_raw/bindings.py,tests/*,setupsrc/*"
47+
coverage_impl;;
48+
49+
coverage-core)
50+
OMISSIONS="src/pypdfium2_raw/bindings.py,src/pypdfium2/__main__.py,src/pypdfium2/_cli/*,tests/*,setupsrc/*"
51+
coverage_impl;;
4652

4753
docs-build)
4854
python3 -m sphinx -b html docs/source docs/build/html $args;;

src/pypdfium2/_deferred.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
logger = logging.getLogger(__name__)
1414

15-
if sys.version_info < (3, 8):
15+
if sys.version_info < (3, 8): # pragma: no cover
1616
# NOTE alternatively, we could write our own cached property backport with python's descriptor protocol
1717
def cached_property(func):
1818
return property( functools.lru_cache(maxsize=1)(func) )

src/pypdfium2/_helpers/document.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ def init_forms(self, config=None):
158158

159159
# safety check for older binaries to prevent a segfault (could be removed at some point)
160160
# https://github.com/bblanchon/pdfium-binaries/issues/105
161-
if "V8" in PDFIUM_INFO.flags and "pdfium-binaries" in PDFIUM_INFO.origin and PDFIUM_INFO.build <= 5677:
161+
if "V8" in PDFIUM_INFO.flags and "pdfium-binaries" in PDFIUM_INFO.origin and PDFIUM_INFO.build <= 5677: # pragma: no cover
162162
raise RuntimeError("V8 enabled pdfium-binaries builds <= 5677 crash on init_forms().")
163163

164164
if not config:
165-
if "XFA" in PDFIUM_INFO.flags:
165+
if "XFA" in PDFIUM_INFO.flags: # pragma: no cover
166166
js_platform = pdfium_c.IPDF_JSPLATFORM(version=3)
167167
config = pdfium_c.FPDF_FORMFILLINFO(version=2, xfa_disabled=False, m_pJsPlatform=ctypes.pointer(js_platform))
168168
else:
@@ -175,7 +175,7 @@ def init_forms(self, config=None):
175175
self._add_kid(self.formenv)
176176

177177
if formtype in (pdfium_c.FORMTYPE_XFA_FULL, pdfium_c.FORMTYPE_XFA_FOREGROUND):
178-
if "XFA" in PDFIUM_INFO.flags:
178+
if "XFA" in PDFIUM_INFO.flags: # pragma: no cover
179179
ok = pdfium_c.FPDF_LoadXFA(self)
180180
if not ok:
181181
# FIXME ability to propagate an optional exception with error code info?

src/pypdfium2/_helpers/textpage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def get_text_range(self, index=0, count=-1, errors="ignore"):
128128
# pdfium builds from fea01fa9e2 (>6167) to d6a4b27d80 (<6415) require assuming 4 bytes per character
129129
# https://github.com/pypdfium2-team/pypdfium2/issues/298
130130
# https://crbug.com/pdfium/2133
131-
if 6167 < PDFIUM_INFO.build < 6415:
131+
if 6167 < PDFIUM_INFO.build < 6415: # pragma: no cover
132132
logger.warning(f"Due to API issues, pdfium builds between 6167 and 6415 (you have {PDFIUM_INFO.build}) require allocating twice the amount of memory in get_text_range().")
133133
in_count *= 2
134134
in_count += 1 # null terminator

src/pypdfium2/_library_scope.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def init_lib():
1111
assert not pdfium_i.LIBRARY_AVAILABLE
12-
if pdfium_i.DEBUG_AUTOCLOSE:
12+
if pdfium_i.DEBUG_AUTOCLOSE: # pragma: no cover
1313
# FIXME not shown on auto-init, because DEBUG_AUTOCLOSE can only be set on the caller side after pypdfium2 has been imported...
1414
print("Initialize PDFium", file=sys.stderr)
1515

@@ -28,7 +28,7 @@ def init_lib():
2828
pdfium_i.LIBRARY_AVAILABLE.value = True
2929

3030

31-
def destroy_lib():
31+
def destroy_lib(): # pragma: no cover
3232
assert pdfium_i.LIBRARY_AVAILABLE
3333
if pdfium_i.DEBUG_AUTOCLOSE:
3434
pdfium_i._safe_debug("Destroy PDFium")

src/pypdfium2/internal/bases.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16-
def _safe_debug(msg):
16+
def _safe_debug(msg): # pragma: no cover
1717
# try to use os.write() rather than print() to avoid "reentrant call" exceptions on shutdown (see https://stackoverflow.com/q/75367828/15547292)
1818
try:
1919
os.write(sys.stderr.fileno(), (msg+"\n").encode())
@@ -56,10 +56,10 @@ def _as_parameter_(self):
5656

5757
def _close_template(close_func, raw, obj_repr, state, parent, *args, **kwargs):
5858

59-
if DEBUG_AUTOCLOSE:
59+
if DEBUG_AUTOCLOSE: # pragma: no cover
6060
_safe_debug(f"Close ({state.value.name.lower()}) {obj_repr}")
6161

62-
if not LIBRARY_AVAILABLE:
62+
if not LIBRARY_AVAILABLE: # pragma: no cover
6363
_safe_debug(f"-> Cannot close object; pdfium library is destroyed. This may cause a memory leak!")
6464
return
6565

src/pypdfium2/internal/consts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get(self, key, default_prefix="Unhandled constant"):
126126
})
127127

128128

129-
if "XFA" in PDFIUM_INFO.flags:
129+
if "XFA" in PDFIUM_INFO.flags: # pragma: no cover
130130
#: [XFA builds only] Convert a PDFium XFA error constant (:attr:`FPDF_ERR_XFA*`) to string.
131131
XFAErrorToStr = _fallback_dict({
132132
pdfium_c.FPDF_ERR_XFALOAD: "Load error",

0 commit comments

Comments
 (0)