MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / wrap

Function wrap

tests/conftest.py:49–193  ·  view source on GitHub ↗

Check that tests return with empty MuPDF warnings buffer. For example this detects failure to call fz_close_output() before fz_drop_output(), which (as of 2024-4-12) generates a warning from MuPDF. As of 2024-09-12 we also detect whether tests leave fds open; but for now do

(request)

Source from the content-addressed store, hash-verified

47
48@pytest.fixture(autouse=True)
49def wrap(request):
50 '''
51 Check that tests return with empty MuPDF warnings buffer. For example this
52 detects failure to call fz_close_output() before fz_drop_output(), which
53 (as of 2024-4-12) generates a warning from MuPDF.
54
55 As of 2024-09-12 we also detect whether tests leave fds open; but for now
56 do not fail tests, because many tests need fixing.
57 '''
58 global PYMUPDF_PYTEST_RESUME
59 if PYMUPDF_PYTEST_RESUME:
60 # Skip all tests until we reach a matching name.
61 if PYMUPDF_PYTEST_RESUME == request.function.__name__:
62 print(f'### {PYMUPDF_PYTEST_RESUME=}: resuming at {request.function.__name__=}.')
63 PYMUPDF_PYTEST_RESUME = None
64 else:
65 print(f'### {PYMUPDF_PYTEST_RESUME=}: Skipping {request.function.__name__=}.')
66 return
67
68 wt = pymupdf.TOOLS.mupdf_warnings()
69 assert not wt, f'{wt=}'
70 if platform.python_implementation() == 'GraalVM':
71 pymupdf.TOOLS.set_small_glyph_heights()
72 else:
73 assert not pymupdf.TOOLS.set_small_glyph_heights()
74 next_fd_before = os.open(__file__, os.O_RDONLY)
75 os.close(next_fd_before)
76
77 if platform.system() == 'Linux' and platform.python_implementation() != 'GraalVM':
78 test_fds = True
79 else:
80 test_fds = False
81
82 if test_fds:
83 # Gather detailed information about leaked fds.
84 def get_fds():
85 import subprocess
86 path = 'PyMuPDF-linx-fds'
87 path_l = 'PyMuPDF-linx-fds-l'
88 command = f'ls /proc/{os.getpid()}/fd > {path}'
89 command_l = f'ls -l /proc/{os.getpid()}/fd > {path_l}'
90 subprocess.run(command, shell=1)
91 subprocess.run(command_l, shell=1)
92 with open(path) as f:
93 ret = f.read()
94 ret = ret.replace('\n', ' ')
95 with open(path_l) as f:
96 ret_l = f.read()
97 return ret, ret_l
98 open_fds_before, open_fds_before_l = get_fds()
99
100 pymupdf._log_items_clear()
101 pymupdf._log_items_active(True)
102
103 JM_annot_id_stem = pymupdf.JM_annot_id_stem
104
105 def get_members(a):
106 ret = dict()

Callers

nothing calls this directly

Calls 6

get_fdsFunction · 0.85
get_membersFunction · 0.85
mupdf_warningsMethod · 0.80
flushMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…