|
10 | 10 |
|
11 | 11 | import os |
12 | 12 | import platform |
| 13 | +import subprocess |
13 | 14 | import sys |
14 | 15 | import tempfile |
15 | 16 | import pytest |
16 | 17 | import textwrap |
| 18 | +import time |
| 19 | + |
17 | 20 |
|
18 | 21 | scriptdir = os.path.abspath(os.path.dirname(__file__)) |
19 | 22 | epub = os.path.join(scriptdir, "resources", "Bezier.epub") |
@@ -462,3 +465,50 @@ def test_4155(): |
462 | 465 | assert 'operation forbidden on released memoryview object' in str(e) |
463 | 466 | else: |
464 | 467 | assert 0, f'Did not receive expected exception when using defunct memoryview.' |
| 468 | + |
| 469 | + |
| 470 | +def test_4336(): |
| 471 | + if 0: |
| 472 | + # Compare with last classic release. |
| 473 | + import pickle |
| 474 | + path_out = os.path.normpath(f'{__file__}/../../tests/resources/test_4336_cc') |
| 475 | + code = textwrap.dedent(f''' |
| 476 | + import fitz |
| 477 | + import os |
| 478 | + import time |
| 479 | + import pickle |
| 480 | + |
| 481 | + path = os.path.normpath(f'{__file__}/../../tests/resources/nur-ruhig.jpg') |
| 482 | + pixmap = fitz.Pixmap(path) |
| 483 | + t = time.time() |
| 484 | + for i in range(10): |
| 485 | + cc = pixmap.color_count() |
| 486 | + t = time.time() - t |
| 487 | + print(f'test_4336(): {{t=}}') |
| 488 | + with open({path_out!r}, 'wb') as f: |
| 489 | + pickle.dump(cc, f) |
| 490 | + ''') |
| 491 | + path_code = os.path.normpath(f'{__file__}/../../tests/resources/test_4336.py') |
| 492 | + with open(path_code, 'w') as f: |
| 493 | + f.write(code) |
| 494 | + venv = os.path.normpath(f'{__file__}/../../tests/resources/test_4336_venv') |
| 495 | + command = f'{sys.executable} -m venv {venv}' |
| 496 | + command += f' && . {venv}/bin/activate' |
| 497 | + command += f' && pip install --force-reinstall pymupdf==1.23.8' |
| 498 | + command += f' && python {path_code}' |
| 499 | + print(f'Running: {command}', flush=1) |
| 500 | + subprocess.run(command, shell=1, check=1) |
| 501 | + with open(path_out, 'rb') as f: |
| 502 | + cc_old = pickle.load(f) |
| 503 | + else: |
| 504 | + cc_old = None |
| 505 | + path = os.path.normpath(f'{__file__}/../../tests/resources/nur-ruhig.jpg') |
| 506 | + pixmap = pymupdf.Pixmap(path) |
| 507 | + t = time.time() |
| 508 | + for i in range(10): |
| 509 | + cc = pixmap.color_count() |
| 510 | + t = time.time() - t |
| 511 | + print(f'test_4336(): {t=}') |
| 512 | + |
| 513 | + if cc_old: |
| 514 | + assert cc == cc_old |
0 commit comments