File: test_docs_samples.py

package info (click to toggle)
pymupdf 1.21.1%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,404 kB
  • sloc: python: 8,737; makefile: 8
file content (31 lines) | stat: -rw-r--r-- 853 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
Test sample scripts in docs/samples/.
'''

import glob
import os
import pytest
import runpy

# We only look at sample scripts that can run standalone (i.e. don't require
# sys.argv).
#
root = os.path.abspath(f'{__file__}/../..')
samples = []
for p in glob.glob(f'{root}/docs/samples/*.py'):
    if os.path.basename(p) in (
             'make-bold.py',    # Needs sys.argv[1].
             'multiprocess-gui.py', # GUI.
             'multiprocess-render.py',  # Needs sys.argv[1].
             'text-lister.py',  # Needs sys.argv[1].
            ):
        print(f'Not testing: {p}')
    else:
        samples.append(p)

# We use pytest.mark.parametrize() to run sample scripts via a fn, which
# ensures that pytest treats each script as a test.
#
@pytest.mark.parametrize('sample', samples)
def test_docs_samples(sample):
    runpy.run_path(sample)