Skip to content

Commit d52351a

Browse files
tests/test_pixmap.py: test_4336(): new, timing of Pixmap.color_count().
1 parent 3e5b526 commit d52351a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/test_pixmap.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
import os
1212
import platform
13+
import subprocess
1314
import sys
1415
import tempfile
1516
import pytest
1617
import textwrap
18+
import time
19+
1720

1821
scriptdir = os.path.abspath(os.path.dirname(__file__))
1922
epub = os.path.join(scriptdir, "resources", "Bezier.epub")
@@ -462,3 +465,50 @@ def test_4155():
462465
assert 'operation forbidden on released memoryview object' in str(e)
463466
else:
464467
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

Comments
 (0)