python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.29k stars 2.23k forks source link

9.4.0: pytest is failing in `Tests/test_imagegrab.py::TestImageGrab::test_grabclipboard` unit #6858

Closed kloczek closed 1 year ago

kloczek commented 1 year ago

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

Here is pytest output:

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pillow-9.4.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pillow-9.4.0-2.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra -m 'not network' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/1.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/binary_preview_map.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/illu10_no_preview.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/illu10_preview.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/illuCS6_no_preview.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/illuCS6_preview.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/non_zero_bb.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/pil_sample_cmyk.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/reqd_showpage.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/zero_bb_emptyline.eps]' --deselect 'Tests/oss-fuzz/test_fuzzers.py::test_fuzz_images[Tests/images/zero_bb.eps]' --deselect Tests/test_features.py::test_version --deselect Tests/test_file_eps.py::test_bytesio_object --deselect Tests/test_file_eps.py::test_cmyk --deselect Tests/test_file_eps.py::test_emptyline --deselect Tests/test_file_eps.py::test_file_object --deselect Tests/test_file_eps.py::test_iobase_object --deselect Tests/test_file_eps.py::test_load --deselect Tests/test_file_eps.py::test_render_scale1 --deselect Tests/test_file_eps.py::test_render_scale2 --deselect Tests/test_file_eps.py::test_resize --deselect Tests/test_file_eps.py::test_sanity --deselect Tests/test_file_eps.py::test_showpage --deselect Tests/test_file_eps.py::test_thumbnail --deselect Tests/test_file_eps.py::test_transparency --deselect Tests/test_file_png.py::TestFilePng::test_sanity --deselect Tests/test_imagefile.py::TestImageFile::test_parser ==================================================================================== test session starts ==================================================================================== platform linux -- Python 3.8.16, pytest-7.2.0, pluggy-1.0.0 rootdir: /home/tkloczko/rpmbuild/BUILD/Pillow-9.4.0, configfile: setup.cfg, testpaths: Tests plugins: timeout-2.1.0 collected 3973 items / 29 deselected / 1 skipped / 3944 selected Tests/test_000_sanity.py . [ 0%] Tests/test_binary.py ... [ 0%] Tests/test_bmp_reference.py ... [ 0%] Tests/test_box_blur.py .............. [ 0%] Tests/test_color_lut.py .......................... [ 1%] Tests/test_core_resources.py .............. [ 1%] Tests/test_decompression_bomb.py .......... [ 1%] Tests/test_deprecate.py .......... [ 2%] Tests/test_deprecated_imageqt.py . [ 2%] Tests/test_features.py .................... [ 2%] Tests/test_file_apng.py ................................ [ 3%] Tests/test_file_blp.py ............. [ 3%] Tests/test_file_bmp.py .................. [ 4%] Tests/test_file_bufrstub.py ..... [ 4%] Tests/test_file_container.py ............... [ 4%] Tests/test_file_cur.py .. [ 4%] Tests/test_file_dcx.py ......... [ 4%] Tests/test_file_dds.py ................................ [ 5%] Tests/test_file_eps.py .......... [ 6%] Tests/test_file_fits.py ..... [ 6%] Tests/test_file_fli.py ............... [ 6%] Tests/test_file_fpx.py ... [ 6%] Tests/test_file_ftex.py .... [ 6%] Tests/test_file_gbr.py .... [ 6%] Tests/test_file_gd.py ... [ 6%] Tests/test_file_gif.py ......................ss............................................................ [ 9%] Tests/test_file_gimpgradient.py .......... [ 9%] Tests/test_file_gimppalette.py .. [ 9%] Tests/test_file_gribstub.py ..... [ 9%] Tests/test_file_hdf5stub.py ..... [ 9%] Tests/test_file_icns.py ........... [ 9%] Tests/test_file_ico.py .................... [ 10%] Tests/test_file_im.py ............... [ 10%] Tests/test_file_imt.py .... [ 10%] Tests/test_file_iptc.py ..... [ 10%] Tests/test_file_jpeg.py ....................................................ss.................................s [ 13%] Tests/test_file_jpeg2k.py ............................................ssss.... [ 14%] Tests/test_file_libtiff.py ......................................................s............................. [ 16%] Tests/test_file_libtiff_small.py ... [ 16%] Tests/test_file_mcidas.py .. [ 16%] Tests/test_file_mic.py ...... [ 16%] Tests/test_file_mpo.py ............................. [ 17%] Tests/test_file_msp.py ....ss. [ 17%] Tests/test_file_palm.py .X.. [ 17%] Tests/test_file_pcd.py . [ 17%] Tests/test_file_pcx.py ................ [ 18%] Tests/test_file_pdf.py ................ [ 18%] Tests/test_file_pixar.py .. [ 18%] Tests/test_file_png.py ......................................................... [ 20%] Tests/test_file_ppm.py ..................................... [ 21%] Tests/test_file_psd.py .................. [ 21%] Tests/test_file_sgi.py .......... [ 21%] Tests/test_file_spider.py ................ [ 22%] Tests/test_file_sun.py ..s [ 22%] Tests/test_file_tar.py .... [ 22%] Tests/test_file_tga.py .................. [ 22%] Tests/test_file_tiff.py ..............................................................................s..s [ 25%] Tests/test_file_tiff_metadata.py ........................ [ 25%] Tests/test_file_wal.py .. [ 25%] Tests/test_file_webp.py .................... [ 26%] Tests/test_file_webp_alpha.py ..... [ 26%] Tests/test_file_webp_animated.py ...... [ 26%] Tests/test_file_webp_lossless.py . [ 26%] Tests/test_file_webp_metadata.py ........ [ 26%] Tests/test_file_wmf.py ....... [ 26%] Tests/test_file_xbm.py ...... [ 27%] Tests/test_file_xpm.py ... [ 27%] Tests/test_file_xvthumb.py ... [ 27%] Tests/test_font_bdf.py .. [ 27%] Tests/test_font_crash.py . [ 27%] Tests/test_font_leaks.py .. [ 27%] Tests/test_font_pcf.py ...... [ 27%] Tests/test_font_pcf_charsets.py ......... [ 27%] Tests/test_format_hsv.py .... [ 27%] Tests/test_format_lab.py ... [ 27%] Tests/test_image.py ............................................................................................................ [ 30%] Tests/test_image_access.py ......................................................................s [ 32%] Tests/test_image_array.py ... [ 32%] Tests/test_image_convert.py .............................. [ 33%] Tests/test_image_copy.py ....... [ 33%] Tests/test_image_crop.py ............. [ 33%] Tests/test_image_draft.py ... [ 33%] Tests/test_image_entropy.py . [ 33%] Tests/test_image_filter.py ...................................................................................... [ 36%] Tests/test_image_frombytes.py . [ 36%] Tests/test_image_fromqimage.py sssss [ 36%] Tests/test_image_getbands.py . [ 36%] Tests/test_image_getbbox.py .. [ 36%] Tests/test_image_getcolors.py .. [ 36%] Tests/test_image_getdata.py .. [ 36%] Tests/test_image_getextrema.py .. [ 36%] Tests/test_image_getim.py . [ 36%] Tests/test_image_getpalette.py .. [ 36%] Tests/test_image_getprojection.py . [ 36%] Tests/test_image_histogram.py . [ 36%] Tests/test_image_load.py ..... [ 36%] Tests/test_image_mode.py .. [ 36%] Tests/test_image_paste.py .................................. [ 37%] Tests/test_image_point.py ..... [ 37%] Tests/test_image_putalpha.py ... [ 37%] Tests/test_image_putdata.py ............ [ 38%] Tests/test_image_putpalette.py ..... [ 38%] Tests/test_image_quantize.py ............... [ 38%] Tests/test_image_reduce.py .......................................................................................................................................................... [ 42%] ....................................................... [ 43%] Tests/test_image_resample.py ...............................................xx................................... [ 46%] Tests/test_image_resize.py ............................................................................. [ 47%] Tests/test_image_rotate.py .......................... [ 48%] Tests/test_image_split.py ........... [ 48%] Tests/test_image_thumbnail.py .......... [ 49%] Tests/test_image_tobitmap.py . [ 49%] Tests/test_image_tobytes.py . [ 49%] Tests/test_image_transform.py ........................................................................... [ 51%] Tests/test_image_transpose.py ........................................ [ 52%] Tests/test_imagechops.py .............................. [ 52%] Tests/test_imagecms.py ............................... [ 53%] Tests/test_imagecolor.py ..... [ 53%] Tests/test_imagedraw.py ......................................................................................s.................................. [ 56%] Tests/test_imagedraw2.py ................ [ 57%] Tests/test_imageenhance.py ...... [ 57%] Tests/test_imagefile.py ........................ [ 58%] Tests/test_imagefont.py .......................................................................................s..................................................................... [ 62%] ..................s............. [ 62%] Tests/test_imagefontctl.py ......................................ss........................................ [ 64%] Tests/test_imagegrab.py sss.Fss [ 65%] Tests/test_imagemath.py ......................... [ 65%] Tests/test_imagemorph.py ....................... [ 66%] Tests/test_imageops.py ............................ [ 66%] Tests/test_imageops_usm.py ..... [ 67%] Tests/test_imagepalette.py ............... [ 67%] Tests/test_imagepath.py ............. [ 67%] Tests/test_imageqt.py sss [ 67%] Tests/test_imagesequence.py ........ [ 68%] Tests/test_imageshow.py ....sssss...ss [ 68%] Tests/test_imagestat.py ... [ 68%] Tests/test_imagetk.py ssssssssssssss [ 68%] Tests/test_imagewin.py ...sssss [ 69%] Tests/test_lib_image.py . [ 69%] Tests/test_lib_pack.py .................................... [ 70%] Tests/test_locale.py . [ 70%] Tests/test_main.py . [ 70%] Tests/test_map.py ... [ 70%] Tests/test_mode_i16.py ....... [ 70%] Tests/test_numpy.py ................................... [ 71%] Tests/test_pdfparser.py .... [ 71%] Tests/test_pickle.py ............................................................................................ [ 73%] Tests/test_psdraw.py ... [ 73%] Tests/test_qt_image_qapplication.py s [ 73%] Tests/test_qt_image_toqimage.py sssss [ 73%] Tests/test_sgi_crash.py ........... [ 74%] Tests/test_shell_injection.py ssss [ 74%] Tests/test_tiff_crashes.py ss...........s. [ 74%] Tests/test_tiff_ifdrational.py .... [ 74%] Tests/test_util.py ...... [ 74%] Tests/test_webp_leaks.py . [ 74%] Tests/oss-fuzz/test_fuzzers.py ...................................................................................................................................................... [ 78%] ..................................................................................................................................................................................... [ 83%] ..................................................................................................................................................................................... [ 87%] ..................................................................................................................................................................................... [ 92%] ..................................................................................................................................................................................... [ 97%] ................................................................................................................... [100%] ========================================================================================= FAILURES ========================================================================================== _____________________________________________________________________________ TestImageGrab.test_grabclipboard ______________________________________________________________________________ self = def test_grabclipboard(self): if sys.platform == "darwin": subprocess.call(["screencapture", "-cx"]) elif sys.platform == "win32": p = subprocess.Popen(["powershell", "-command", "-"], stdin=subprocess.PIPE) p.stdin.write( b"""[Reflection.Assembly]::LoadWithPartialName("System.Drawing") [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $bmp = New-Object Drawing.Bitmap 200, 200 [Windows.Forms.Clipboard]::SetImage($bmp)""" ) p.communicate() else: if not shutil.which("wl-paste"): with pytest.raises( NotImplementedError, match="wl-paste or xclip is required for" r" ImageGrab.grabclipboard\(\) on Linux", ): > ImageGrab.grabclipboard() Tests/test_imagegrab.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ../../BUILDROOT/python-pillow-9.4.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages/PIL/ImageGrab.py:146: in grabclipboard im = Image.open(filepath) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ fp = <_io.BufferedReader name='/tmp/tmp_zvn5co0'>, mode = 'r', formats = ['PNG', 'BLP', 'BMP', 'DIB', 'BUFR', 'CUR', ...] def open(fp, mode="r", formats=None): """ Opens and identifies the given image file. This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the :py:meth:`~PIL.Image.Image.load` method). See :py:func:`~PIL.Image.new`. See :ref:`file-handling`. :param fp: A filename (string), pathlib.Path object or a file object. The file object must implement ``file.read``, ``file.seek``, and ``file.tell`` methods, and be opened in binary mode. :param mode: The mode. If given, this argument must be "r". :param formats: A list or tuple of formats to attempt to load the file in. This can be used to restrict the set of formats checked. Pass ``None`` to try all supported formats. You can print the set of available formats by running ``python3 -m PIL`` or using the :py:func:`PIL.features.pilinfo` function. :returns: An :py:class:`~PIL.Image.Image` object. :exception FileNotFoundError: If the file cannot be found. :exception PIL.UnidentifiedImageError: If the image cannot be opened and identified. :exception ValueError: If the ``mode`` is not "r", or if a ``StringIO`` instance is used for ``fp``. :exception TypeError: If ``formats`` is not ``None``, a list or a tuple. """ if mode != "r": msg = f"bad mode {repr(mode)}" raise ValueError(msg) elif isinstance(fp, io.StringIO): msg = ( "StringIO cannot be used to open an image. " "Binary data must be used instead." ) raise ValueError(msg) if formats is None: formats = ID elif not isinstance(formats, (list, tuple)): msg = "formats must be a list or tuple" raise TypeError(msg) exclusive_fp = False filename = "" if isinstance(fp, Path): filename = str(fp.resolve()) elif is_path(fp): filename = fp if filename: fp = builtins.open(filename, "rb") exclusive_fp = True try: fp.seek(0) except (AttributeError, io.UnsupportedOperation): fp = io.BytesIO(fp.read()) exclusive_fp = True prefix = fp.read(16) preinit() accept_warnings = [] def _open_core(fp, filename, prefix, formats): for i in formats: i = i.upper() if i not in OPEN: init() try: factory, accept = OPEN[i] result = not accept or accept(prefix) if type(result) in [str, bytes]: accept_warnings.append(result) elif result: fp.seek(0) im = factory(fp, filename) _decompression_bomb_check(im.size) return im except (SyntaxError, IndexError, TypeError, struct.error): # Leave disabled by default, spams the logs with image # opening failures that are entirely expected. # logger.debug("", exc_info=True) continue except BaseException: if exclusive_fp: fp.close() raise return None im = _open_core(fp, filename, prefix, formats) if im is None: if init(): im = _open_core(fp, filename, prefix, formats) if im: im._exclusive_fp = exclusive_fp return im if exclusive_fp: fp.close() for message in accept_warnings: warnings.warn(message) msg = "cannot identify image file %r" % (filename if filename else fp) > raise UnidentifiedImageError(msg) E PIL.UnidentifiedImageError: cannot identify image file '/tmp/tmp_zvn5co0' ../../BUILDROOT/python-pillow-9.4.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages/PIL/Image.py:3283: UnidentifiedImageError ----------------------------------------------------------------------------------- Captured stderr call ------------------------------------------------------------------------------------ xclip: Error: Can't open display: (null) ================================================================================== short test summary info ================================================================================== SKIPPED [1] Tests/test_pyroma.py:5: Pyroma not installed SKIPPED [1] Tests/test_file_gif.py:337: Netpbm not available SKIPPED [1] Tests/test_file_gif.py:348: Netpbm not available SKIPPED [1] Tests/test_file_jpeg.py:644: djpeg not available SKIPPED [1] Tests/test_file_jpeg.py:650: cjpeg not available SKIPPED [1] Tests/test_file_jpeg.py:945: Windows only SKIPPED [4] Tests/test_file_jpeg2k.py:337: Extra image files not installed SKIPPED [1] Tests/test_file_libtiff.py:840: LZMA compression support is not configured SKIPPED [1] Tests/test_file_msp.py:58: Extra image files not installed SKIPPED [1] Tests/test_file_msp.py:72: Even More Extra image files not installed SKIPPED [1] Tests/test_file_sun.py:35: Extra image files not installed SKIPPED [1] Tests/test_file_tiff.py:840: Extra image files not installed SKIPPED [1] Tests/test_file_tiff.py:877: Windows only SKIPPED [1] Tests/test_image_access.py:408: requires Windows SKIPPED [1] Tests/test_image_fromqimage.py:44: Qt bindings are not installed SKIPPED [1] Tests/test_image_fromqimage.py:49: Qt bindings are not installed SKIPPED [1] Tests/test_image_fromqimage.py:54: Qt bindings are not installed SKIPPED [1] Tests/test_image_fromqimage.py:59: Qt bindings are not installed SKIPPED [1] Tests/test_image_fromqimage.py:64: Qt bindings are not installed SKIPPED [1] Tests/test_imagedraw.py:970: failing SKIPPED [2] Tests/test_imagefont.py:1077: FreeType compiled without brotli or WOFF2 support SKIPPED [2] Tests/test_imagefontctl.py:233: fails with this font SKIPPED [1] Tests/test_imagegrab.py:14: requires Windows or macOS SKIPPED [1] Tests/test_imagegrab.py:33: X connection failed: error 5 SKIPPED [1] Tests/test_imagegrab.py:35: tests missing XCB SKIPPED [1] Tests/test_imagegrab.py:78: Windows only SKIPPED [1] Tests/test_imagegrab.py:88: Windows only SKIPPED [1] Tests/test_imageqt.py:20: Qt bindings are not installed SKIPPED [1] Tests/test_imageqt.py:49: Qt bindings are not installed SKIPPED [1] Tests/test_imageqt.py:63: Qt bindings are not installed SKIPPED [5] Tests/test_imageshow.py:44: Only run on CIs; hangs on Windows CIs SKIPPED [1] Tests/test_imageshow.py:82: IPython not installed SKIPPED [1] Tests/test_imageshow.py:94: Only run on CIs; hangs on Windows CIs SKIPPED [14] Tests/test_imagetk.py:32: TCL Error: no display name and no $DISPLAY environment variable SKIPPED [1] Tests/test_imagewin.py:37: Windows only SKIPPED [1] Tests/test_imagewin.py:47: Windows only SKIPPED [1] Tests/test_imagewin.py:58: Windows only SKIPPED [1] Tests/test_imagewin.py:72: Windows only SKIPPED [1] Tests/test_imagewin.py:87: Windows only SKIPPED [1] Tests/test_qt_image_qapplication.py:54: Qt bindings are not installed SKIPPED [5] Tests/test_qt_image_toqimage.py:19: Qt bindings are not installed SKIPPED [1] Tests/test_shell_injection.py:25: djpeg not available SKIPPED [1] Tests/test_shell_injection.py:34: cjpeg not available SKIPPED [1] Tests/test_shell_injection.py:39: Netpbm not available SKIPPED [1] Tests/test_shell_injection.py:45: Netpbm not available SKIPPED [3] Tests/test_tiff_crashes.py:50: test image not found XFAIL Tests/test_image_resample.py::TestCoreResampleAlphaCorrect::test_levels_rgba - Current implementation isn't precise enough XFAIL Tests/test_image_resample.py::TestCoreResampleAlphaCorrect::test_levels_la - Current implementation isn't precise enough XPASS Tests/test_file_palm.py::test_p_mode Palm P image is wrong FAILED Tests/test_imagegrab.py::TestImageGrab::test_grabclipboard - PIL.UnidentifiedImageError: cannot identify image file '/tmp/tmp_zvn5co0' ================================================ 1 failed, 3867 passed, 74 skipped, 29 deselected, 2 xfailed, 1 xpassed in 192.74s (0:03:12) ================================================ ```

Here is list of installed modules in build env

```console Package Version ----------------------------- ----------------- alabaster 0.7.12 asn1crypto 1.5.1 attrs 22.2.0 Babel 2.11.0 bcrypt 3.2.2 build 0.9.0 cffi 1.15.1 charset-normalizer 3.0.1 contourpy 1.0.6 cryptography 38.0.4 cycler 0.11.0 distro 1.8.0 docutils 0.19 exceptiongroup 1.0.0 extras 1.0.0 fixtures 4.0.0 fonttools 4.38.0 gpg 1.18.0-unknown idna 3.4 imagesize 1.4.1 importlib-metadata 5.1.0 iniconfig 1.1.1 Jinja2 3.1.2 kiwisolver 1.4.4 libcomps 0.1.19 MarkupSafe 2.1.1 matplotlib 3.6.2 numpy 1.24.1 olefile 0.46 packaging 21.3 pbr 5.9.0 pep517 0.13.0 Pillow 9.3.0 pip 22.3.1 pluggy 1.0.0 ply 3.11 pyasn1 0.4.8 pyasn1-modules 0.2.8 pycparser 2.21 Pygments 2.14.0 PyGObject 3.42.2 pyparsing 3.0.9 pytest 7.2.0 pytest-timeout 2.1.0 python-dateutil 2.8.2 pytz 2022.4 PyYAML 6.0 requests 2.28.1 rpm 4.17.0 setuptools 65.6.3 six 1.16.0 snowballstemmer 2.2.0 Sphinx 5.3.0 sphinx-copybutton 0.5.1 sphinx_inline_tabs 2022.1.2b11 sphinx-issues 3.0.1 sphinx-removed-in 0.2.1 sphinx-rtd-theme 1.1.1 sphinxcontrib-applehelp 1.0.2.dev20221204 sphinxcontrib-devhelp 1.0.2.dev20221204 sphinxcontrib-htmlhelp 2.0.0 sphinxcontrib-jsmath 1.0.1.dev20221204 sphinxcontrib-qthelp 1.0.3.dev20221204 sphinxcontrib-serializinghtml 1.1.5 sphinxext-opengraph 0.7.4 testtools 2.5.0 tomli 2.0.1 tpm2-pkcs11-tools 1.33.7 tpm2-pytss 1.1.0 urllib3 1.26.12 wheel 0.38.4 zipp 3.11.0 ```
radarhere commented 1 year ago

I've created PR #6859 to resolve this.

kloczek commented 1 year ago

Ha so xclip binary is needed .. let me check πŸ˜„

kloczek commented 1 year ago

Indeed after add xclip to build env everything is fine πŸ˜„