Skip to content

Commit 4b69994

Browse files
tests/: avoid process-related test failures on Pyodide.
Pyodide does not support child processes or multiprocesses, so those tests that use these features now return immediately if we are running on Pyodide.
1 parent 58c2b3a commit 4b69994

File tree

10 files changed

+90
-1
lines changed

10 files changed

+90
-1
lines changed

tests/test_codespell.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def test_codespell():
1212
'''
1313
Check rebased Python code with codespell.
1414
'''
15+
if os.environ.get('PYODIDE_ROOT'):
16+
print('test_codespell(): not running on Pyodide - cannot run child processes.')
17+
return
18+
1519
if not hasattr(pymupdf, 'mupdf'):
1620
print('Not running codespell with classic implementation.')
1721
return

tests/test_flake8.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def test_flake8():
99
'''
1010
Check rebased Python code with flake8.
1111
'''
12+
if os.environ.get('PYODIDE_ROOT'):
13+
print('test_flake8(): not running on Pyodide - cannot run child processes.')
14+
return
15+
1216
if not hasattr(pymupdf, 'mupdf'):
1317
print(f'Not running flake8 with classic implementation.')
1418
return

tests/test_font.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def test_2608():
8383
assert text == expected
8484

8585
def test_fontarchive():
86+
if os.environ.get('PYODIDE_ROOT'):
87+
print('test_fontarchive(): not running on Pyodide - we get ValueError: No font code \'notos\' found in pymupdf-fonts..')
88+
return
89+
8690
import subprocess
8791
arch = pymupdf.Archive()
8892
css = pymupdf.css_for_pymupdf_font("notos", archive=arch, name="sans-serif")
@@ -234,6 +238,10 @@ def test_3887():
234238

235239

236240
def test_4457():
241+
if os.environ.get('PYODIDE_ROOT'):
242+
print('test_4457(): not running on Pyodide - cannot run child processes.')
243+
return
244+
237245
print()
238246
files = (
239247
('https://github.com/user-attachments/files/20862923/test_4457_a.pdf', 'test_4457_a.pdf', None, 4),

tests/test_general.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,9 @@ def test_2736():
785785

786786

787787
def test_subset_fonts():
788+
if os.environ.get('PYODIDE_ROOT'):
789+
print('test_subset_fonts(): not running on Pyodide - ValueError: No font code \'ubuntu\' found in pymupdf-fonts.')
790+
return
788791
"""Confirm subset_fonts is working."""
789792
if not hasattr(pymupdf, "mupdf"):
790793
print("Not testing 'test_subset_fonts' in classic.")
@@ -1026,6 +1029,10 @@ def next_fd():
10261029
os.remove(oldfile)
10271030

10281031
def test_cli():
1032+
if os.environ.get('PYODIDE_ROOT'):
1033+
print('test_cli(): not running on Pyodide - cannot run child processes.')
1034+
return
1035+
10291036
if not hasattr(pymupdf, 'mupdf'):
10301037
print('test_cli(): Not running on classic because of fitz_old.')
10311038
return
@@ -1063,6 +1070,10 @@ def test_cli_out():
10631070
Check redirection of messages and log diagnostics with environment
10641071
variables PYMUPDF_LOG and PYMUPDF_MESSAGE.
10651072
'''
1073+
if os.environ.get('PYODIDE_ROOT'):
1074+
print('test_cli_out(): not running on Pyodide - cannot run child processes.')
1075+
return
1076+
10661077
if not hasattr(pymupdf, 'mupdf'):
10671078
print('test_cli(): Not running on classic because of fitz_old.')
10681079
return
@@ -1150,6 +1161,10 @@ def test_use_python_logging():
11501161
'''
11511162
Checks pymupdf.use_python_logging().
11521163
'''
1164+
if os.environ.get('PYODIDE_ROOT'):
1165+
print('test_cli(): not running on Pyodide - cannot run child processes.')
1166+
return
1167+
11531168
log_prefix = None
11541169
if os.environ.get('PYMUPDF_USE_EXTRA') == '0':
11551170
log_prefix = f'.+Using non-default setting from PYMUPDF_USE_EXTRA: \'0\''
@@ -1433,6 +1448,10 @@ def test_open2():
14331448
Checks behaviour of fz_open_document() and fz_open_document_with_stream()
14341449
with different filenames/magic values.
14351450
'''
1451+
if os.environ.get('PYODIDE_ROOT'):
1452+
print('test_open2(): not running on Pyodide - cannot run child processes.')
1453+
return
1454+
14361455
if platform.system() == 'Windows':
14371456
print(f'test_open2(): not running on Windows because `git ls-files` known fail on Github Windows runners.')
14381457
return
@@ -1789,6 +1808,10 @@ def test_4309():
17891808
document.delete_page()
17901809

17911810
def test_4263():
1811+
if os.environ.get('PYODIDE_ROOT'):
1812+
print('test_4263(): not running on Pyodide - cannot run child processes.')
1813+
return
1814+
17921815
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4263.pdf')
17931816
path_out = f'{path}.linerarized.pdf'
17941817
command = f'pymupdf clean -linear {path} {path_out}'
@@ -1915,6 +1938,10 @@ def show(items):
19151938

19161939

19171940
def test_4533():
1941+
if os.environ.get('PYODIDE_ROOT'):
1942+
print('test_4533(): not running on Pyodide - cannot run child processes.')
1943+
return
1944+
19181945
print()
19191946
path = util.download(
19201947
'https://github.com/user-attachments/files/20497146/NineData_user_manual_V3.0.5.pdf',
@@ -1966,6 +1993,10 @@ def test_gitinfo():
19661993

19671994

19681995
def test_4392():
1996+
if os.environ.get('PYODIDE_ROOT'):
1997+
print('test_4392(): not running on Pyodide - cannot run child processes.')
1998+
return
1999+
19692000
print()
19702001
path = os.path.normpath(f'{__file__}/../../tests/test_4392.py')
19712002
with open(path, 'w') as f:

tests/test_import.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66

77
def test_import():
8+
if os.environ.get('PYODIDE_ROOT'):
9+
print('test_import(): not running on Pyodide - cannot run child processes.')
10+
return
11+
812
root = os.path.abspath(f'{__file__}/../../')
913
p = f'{root}/tests/resources_test_import.py'
1014
with open(p, 'w') as f:

tests/test_memory.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def test_2791():
1717
'''
1818
Check for memory leaks.
1919
'''
20+
if os.environ.get('PYODIDE_ROOT'):
21+
print('test_2791(): not running on Pyodide - No module named \'psutil\'.')
22+
return
23+
2024
if os.environ.get('PYMUPDF_RUNNING_ON_VALGRIND') == '1':
2125
print(f'test_2791(): not running because PYMUPDF_RUNNING_ON_VALGRIND=1.')
2226
return
@@ -94,6 +98,10 @@ def get_stat():
9498

9599

96100
def test_4090():
101+
if os.environ.get('PYODIDE_ROOT'):
102+
print('test_4090(): not running on Pyodide - No module named \'psutil\'.')
103+
return
104+
97105
print(f'test_4090(): {os.environ.get("PYTHONMALLOC")=}.')
98106
import psutil
99107
process = psutil.Process()
@@ -148,6 +156,10 @@ def show_tracemalloc_diff(snapshot1, snapshot2):
148156

149157

150158
def test_4125():
159+
if os.environ.get('PYODIDE_ROOT'):
160+
print('test_4125(): not running on Pyodide - No module named \'psutil\'.')
161+
return
162+
151163
if os.environ.get('PYMUPDF_RUNNING_ON_VALGRIND') == '1':
152164
print(f'test_4125(): not running because PYMUPDF_RUNNING_ON_VALGRIND=1.')
153165
return

tests/test_pixmap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_pilsave():
7070
pix2 = pymupdf.Pixmap(stream)
7171
assert repr(pix1) == repr(pix2)
7272
except ModuleNotFoundError:
73-
assert platform.system() == 'Windows' and sys.maxsize == 2**31 - 1
73+
assert platform.system() in ('Windows', 'Emscripten') and sys.maxsize == 2**31 - 1
7474

7575

7676
def test_save(tmpdir):
@@ -556,6 +556,9 @@ def test_4423():
556556

557557

558558
def test_4445():
559+
if os.environ.get('PYODIDE_ROOT'):
560+
print('test_4445(): not running on Pyodide - cannot run child processes.')
561+
return
559562
print()
560563
# Test case is large so we download it instead of having it in PyMuPDF
561564
# git. We put it in `cache/` directory do it is not removed by `git clean`

tests/test_pylint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
def test_pylint():
99

10+
if os.environ.get('PYODIDE_ROOT'):
11+
print('test_pylint(): not running on Pyodide - cannot run child processes.')
12+
return
13+
1014
if not hasattr(pymupdf, 'mupdf'):
1115
print(f'test_pylint(): Not running with classic implementation.')
1216
return

tests/test_tesseract.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def test_tesseract():
1515
But if TESSDATA_PREFIX is set in the environment, we assert that
1616
FzPage.get_textpage_ocr() succeeds.
1717
'''
18+
if os.environ.get('PYODIDE_ROOT'):
19+
print('test_tesseract(): not running on Pyodide - cannot run child processes.')
20+
return
21+
1822
path = os.path.abspath( f'{__file__}/../resources/2.pdf')
1923
doc = pymupdf.open( path)
2024
page = doc[5]
@@ -71,6 +75,10 @@ def test_3842b():
7175
#
7276
# Note that Tesseract seems to output its own diagnostics.
7377
#
78+
if os.environ.get('PYODIDE_ROOT'):
79+
print('test_3842b(): not running on Pyodide - cannot run child processes.')
80+
return
81+
7482
path = os.path.normpath(f'{__file__}/../../tests/resources/test_3842.pdf')
7583
with pymupdf.open(path) as document:
7684
page = document[6]
@@ -91,6 +99,10 @@ def test_3842b():
9199

92100

93101
def test_3842():
102+
if os.environ.get('PYODIDE_ROOT'):
103+
print('test_3842(): not running on Pyodide - cannot run child processes.')
104+
return
105+
94106
path = os.path.normpath(f'{__file__}/../../tests/resources/test_3842.pdf')
95107
with pymupdf.open(path) as document:
96108
page = document[6]

tests/test_textextract.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def test_3197():
263263

264264

265265
def test_document_text():
266+
if os.environ.get('PYODIDE_ROOT'):
267+
print('test_document_text(): not running on Pyodide - multiprocessing not available.')
268+
return
269+
266270
import platform
267271
import time
268272

@@ -310,6 +314,9 @@ def llen(texts):
310314

311315

312316
def test_4524():
317+
if os.environ.get('PYODIDE_ROOT'):
318+
print('test_4524(): not running on Pyodide - multiprocessing not available.')
319+
return
313320
path = os.path.abspath(f'{__file__}/../../tests/resources/mupdf_explored.pdf')
314321
print('')
315322
document = pymupdf.Document(path)

0 commit comments

Comments
 (0)