Mercurial > hgrepos > Python2 > PyMuPDF
comparison tests/test_codespell.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 | a6bc019ac0b2 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:1d09e1dec1d9 |
|---|---|
| 1 import pymupdf | |
| 2 | |
| 3 import os | |
| 4 import platform | |
| 5 import shlex | |
| 6 import subprocess | |
| 7 import sys | |
| 8 import textwrap | |
| 9 | |
| 10 | |
| 11 def test_codespell(): | |
| 12 ''' | |
| 13 Check rebased Python code with codespell. | |
| 14 ''' | |
| 15 if not hasattr(pymupdf, 'mupdf'): | |
| 16 print('Not running codespell with classic implementation.') | |
| 17 return | |
| 18 | |
| 19 if platform.system() == 'Windows': | |
| 20 # Git commands seem to fail on Github Windows runners. | |
| 21 print(f'test_codespell(): Not running on Widows') | |
| 22 return | |
| 23 | |
| 24 root = os.path.abspath(f'{__file__}/../..') | |
| 25 | |
| 26 # For now we ignore files that we would ideally still look at, because it | |
| 27 # is difficult to exclude some text sections. | |
| 28 skips = textwrap.dedent(''' | |
| 29 *.pdf | |
| 30 docs/_static/prism/prism.js | |
| 31 docs/_static/prism/prism.js | |
| 32 docs/locales/ja/LC_MESSAGES/changes.po | |
| 33 docs/locales/ja/LC_MESSAGES/recipes-common-issues-and-their-solutions.po | |
| 34 docs/locales/ | |
| 35 src_classic/* | |
| 36 ''') | |
| 37 skips = skips.strip().replace('\n', ',') | |
| 38 | |
| 39 command = textwrap.dedent(f''' | |
| 40 cd {root} && codespell | |
| 41 --skip {shlex.quote(skips)} | |
| 42 --ignore-words-list re-use,flate,thirdparty,re-using | |
| 43 --ignore-regex 'https?://[a-z0-9/_.]+' | |
| 44 --ignore-multiline-regex 'codespell:ignore-begin.*codespell:ignore-end' | |
| 45 ''') | |
| 46 | |
| 47 sys.path.append(root) | |
| 48 try: | |
| 49 import pipcl | |
| 50 finally: | |
| 51 del sys.path[0] | |
| 52 git_files = pipcl.git_items(root) | |
| 53 | |
| 54 for p in git_files: | |
| 55 _, ext = os.path.splitext(p) | |
| 56 if ext in ('.png', '.pdf', '.jpg', '.svg'): | |
| 57 pass | |
| 58 else: | |
| 59 command += f' {p}\n' | |
| 60 | |
| 61 if platform.system() != 'Windows': | |
| 62 command = command.replace('\n', ' \\\n') | |
| 63 # Don't print entire command because very long, and will be displayed | |
| 64 # anyway if there is an error. | |
| 65 #print(f'test_codespell(): Running: {command}') | |
| 66 print(f'Running codespell.') | |
| 67 subprocess.run(command, shell=1, check=1) | |
| 68 print('test_codespell(): codespell succeeded.') |
