Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Tests are broken in 1.9.0 release #263

Open
mgorny opened this issue Jun 19, 2024 · 5 comments · May be fixed by #270
Open

Tests are broken in 1.9.0 release #263

mgorny opened this issue Jun 19, 2024 · 5 comments · May be fixed by #270

Comments

@mgorny
Copy link
Contributor

mgorny commented Jun 19, 2024

$ tox -e py310
.pkg: install_requires> python -I -m pip install 'setuptools>=40.8.0' wheel
.pkg: _optional_hooks> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: install_requires_for_build_wheel> python -I -m pip install wheel
.pkg: prepare_metadata_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py310: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/pyperclip/.tox/.tmp/package/1/pyperclip-1.9.0.tar.gz
py310: commands[0]> python tests/test_pyperclip.py
Traceback (most recent call last):
  File "/tmp/pyperclip/tests/test_pyperclip.py", line 11, in <module>
    from pyperclip import _executable_exists, HAS_DISPLAY
ImportError: cannot import name 'HAS_DISPLAY' from 'pyperclip' (/tmp/pyperclip/.tox/py310/lib/python3.10/site-packages/pyperclip/__init__.py)
py310: exit 1 (0.05 seconds) /tmp/pyperclip> python tests/test_pyperclip.py pid=68651
  py310: FAIL code 1 (5.28=setup[5.23]+cmd[0.05] seconds)
  evaluation failed :( (5.46 seconds)

…and indeed, there is no HAS_DISPLAY in it anymore.

@mtelka
Copy link

mtelka commented Jun 19, 2024

With the HAS_DISPLAY removed:

--- pyperclip-1.9.0/tests/test_pyperclip.py.orig
+++ pyperclip-1.9.0/tests/test_pyperclip.py
@@ -8,7 +8,7 @@
 #import sys
 #sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
 
-from pyperclip import _executable_exists, HAS_DISPLAY
+from pyperclip import _executable_exists
 from pyperclip import (init_osx_pbcopy_clipboard, init_osx_pyobjc_clipboard,
                                   init_dev_clipboard_clipboard,
                                   init_qt_clipboard,
@@ -134,16 +134,6 @@
             clipboard = init_osx_pyobjc_clipboard()
 
 
-class TestQt(_TestClipboard):
-    if HAS_DISPLAY:
-        try:
-            import PyQt5.QtWidgets
-        except ImportError:
-            pass
-        else:
-            clipboard = init_qt_clipboard()
-
-
 class TestXClip(_TestClipboard):
     if _executable_exists("xclip"):
         clipboard = init_xclip_clipboard()

I see following two test failures:

FAIL: test_non_str (__main__.TestXClip)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "$(BUILD_DIR)/tests/test_pyperclip.py", line 104, in test_non_str
    self.copy(None)
AssertionError: PyperclipException not raised

======================================================================
FAIL: test_non_str (__main__.TestXSel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "$(BUILD_DIR)/tests/test_pyperclip.py", line 104, in test_non_str
    self.copy(None)
AssertionError: PyperclipException not raised

@musicinmybrain
Copy link

I was looking at updating python-pyperclip in Fedora, and I followed exactly the same process – noticing that pyperclip.HAS_DISPLAY was removed but the tests were not adapted, devising and testing the patch in #263 (comment), and encountering AssertionError: PyperclipException not raised test failures (I also see the failure on tests/test_pyperclip.py::TestQt::test_non_str).

@MeggyCal
Copy link

MeggyCal commented Oct 14, 2024

Hi, read the changelog (5aef21c) and maybe you should delete also the whole test_non_str judging from this quote:

Pyperclip now "stringifies" all data types by passing it to str() (or globals()['__builtins__'].unicode on Python 2), so passing [1, 2, 3] would put '[1, 2, 3]' on the clipboard.

@kulikjak
Copy link

From my quick digging, HAS_DISPLAY can be replaced with os.getenv("DISPLAY") (the same way it was replaced in __init__.py).

As for the failing tests, they were not adjusted to the new "stringifying" behavior @MeggyCal pointed to. So I guess the whole fix should look something like this:

--- pyperclip-1.9.0/tests/test_pyperclip.py
+++ pyperclip-1.9.0/tests/test_pyperclip.py
@@ -8,7 +8,7 @@ import platform
 #import sys
 #sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
 
-from pyperclip import _executable_exists, HAS_DISPLAY
+from pyperclip import _executable_exists
 from pyperclip import (init_osx_pbcopy_clipboard, init_osx_pyobjc_clipboard,
                                   init_dev_clipboard_clipboard,
                                   init_qt_clipboard,
@@ -99,12 +99,11 @@ class _TestClipboard(unittest.TestCase):
         self.copy(False)
         self.assertEqual(self.paste(), 'False')
 
-        # All other non-str values raise an exception.
-        with self.assertRaises(PyperclipException):
-            self.copy(None)
+        self.copy(None)
+        self.assertEqual(self.paste(), 'None')
 
-        with self.assertRaises(PyperclipException):
-            self.copy([2, 4, 6, 8])
+        self.copy([2, 4, 6, 8])
+        self.assertEqual(self.paste(), '[2, 4, 6, 8]')
 
 
 class TestCygwin(_TestClipboard):
@@ -135,7 +134,7 @@ class TestOSX(_TestClipboard):
 
 
 class TestQt(_TestClipboard):
-    if HAS_DISPLAY:
+    if os.getenv("DISPLAY"):
         try:
             import PyQt5.QtWidgets
         except ImportError:

That said, I am in an interesting situation where I don't have any of the clipboard utilities available, so I cannot test much :).

@kulikjak kulikjak linked a pull request Nov 13, 2024 that will close this issue
@kulikjak
Copy link

I managed to test it with xclip on another machine and all tests are passing, so I created a PR.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants