Mercurial > hgrepos > Python2 > PyMuPDF
comparison tests/test_docs_samples.py @ 1:1d09e1dec1d9 upstream
ADD: PyMuPDF v1.26.4: the original sdist.
It does not yet contain MuPDF. This normally will be downloaded when
building PyMuPDF.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:37:51 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:1d09e1dec1d9 |
|---|---|
| 1 ''' | |
| 2 Test sample scripts in docs/samples/. | |
| 3 ''' | |
| 4 | |
| 5 import glob | |
| 6 import os | |
| 7 import pytest | |
| 8 import runpy | |
| 9 | |
| 10 # We only look at sample scripts that can run standalone (i.e. don't require | |
| 11 # sys.argv). | |
| 12 # | |
| 13 root = os.path.abspath(f'{__file__}/../..') | |
| 14 samples = [] | |
| 15 for p in glob.glob(f'{root}/docs/samples/*.py'): | |
| 16 if os.path.basename(p) in ( | |
| 17 'make-bold.py', # Needs sys.argv[1]. | |
| 18 'multiprocess-gui.py', # GUI. | |
| 19 'multiprocess-render.py', # Needs sys.argv[1]. | |
| 20 'text-lister.py', # Needs sys.argv[1]. | |
| 21 ): | |
| 22 print(f'Not testing: {p}') | |
| 23 else: | |
| 24 p = os.path.relpath(p, root) | |
| 25 samples.append(p) | |
| 26 | |
| 27 def _test_all(): | |
| 28 # Allow runnings tests directly without pytest. | |
| 29 import subprocess | |
| 30 import sys | |
| 31 e = 0 | |
| 32 for sample in samples: | |
| 33 print( f'Running: {sample}', flush=1) | |
| 34 try: | |
| 35 if 0: | |
| 36 # Curiously this fails in an odd way when testing compound | |
| 37 # package with $PYTHONPATH set. | |
| 38 print( f'os.environ is:') | |
| 39 for n, v in os.environ.items(): | |
| 40 print( f' {n}: {v!r}') | |
| 41 command = f'{sys.executable} {sample}' | |
| 42 print( f'command is: {command!r}') | |
| 43 sys.stdout.flush() | |
| 44 subprocess.check_call( command, shell=1, text=1) | |
| 45 else: | |
| 46 runpy.run_path(sample) | |
| 47 except Exception: | |
| 48 print( f'Failed: {sample}') | |
| 49 e += 1 | |
| 50 if e: | |
| 51 raise Exception( f'Errors: {e}') | |
| 52 | |
| 53 # We use pytest.mark.parametrize() to run sample scripts via a fn, which | |
| 54 # ensures that pytest treats each script as a test. | |
| 55 # | |
| 56 @pytest.mark.parametrize('sample', samples) | |
| 57 def test_docs_samples(sample): | |
| 58 sample = f'{root}/{sample}' | |
| 59 runpy.run_path(sample) |
