diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_desktop.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_desktop.py b/tests/test_desktop.py new file mode 100644 index 0000000..a273617 --- /dev/null +++ b/tests/test_desktop.py @@ -0,0 +1,33 @@ +import subprocess +import unittest +from unittest.mock import MagicMock, patch + +from parley.desktop import DesktopIntegrationError, copy_text + + +class ClipboardTests(unittest.TestCase): + @patch("parley.desktop.subprocess.run") + @patch("parley.desktop.shutil.which", return_value="/usr/bin/xclip") + def test_copies_utf8_text(self, which: MagicMock, run: MagicMock) -> None: + run.return_value.returncode = 0 + run.return_value.stderr = "" + + copy_text("héllo") + + run.assert_called_once_with( + ["/usr/bin/xclip", "-selection", "clipboard", "-in"], + input="héllo", + text=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + timeout=10, + ) + + @patch("parley.desktop.shutil.which", return_value=None) + def test_reports_missing_xclip(self, which: MagicMock) -> None: + with self.assertRaisesRegex(DesktopIntegrationError, "xclip is not installed"): + copy_text("text") + + +if __name__ == "__main__": + unittest.main() |
