Install Wnck session support helpers
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gdk", "3.0")
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
||||
|
||||
from cthulhu import wnck_support
|
||||
from cthulhu.plugins.OCR import plugin as ocr_plugin
|
||||
|
||||
|
||||
class WnckSupportTests(unittest.TestCase):
|
||||
def test_load_wnck_skips_import_when_session_is_wayland(self):
|
||||
with mock.patch.object(
|
||||
wnck_support.importlib,
|
||||
"import_module",
|
||||
side_effect=AssertionError("import_module should not be called"),
|
||||
):
|
||||
self.assertIsNone(wnck_support.load_wnck(session_type="wayland"))
|
||||
|
||||
def test_load_wnck_imports_wnck_when_session_is_x11(self):
|
||||
fakeGi = mock.Mock()
|
||||
fakeWnck = object()
|
||||
|
||||
def importModule(name):
|
||||
if name == "gi":
|
||||
return fakeGi
|
||||
if name == "gi.repository.Wnck":
|
||||
return fakeWnck
|
||||
raise AssertionError(f"Unexpected import: {name}")
|
||||
|
||||
with mock.patch.object(wnck_support.importlib, "import_module", side_effect=importModule):
|
||||
self.assertIs(wnck_support.load_wnck(session_type="x11"), fakeWnck)
|
||||
|
||||
fakeGi.require_version.assert_called_once_with("Wnck", "3.0")
|
||||
|
||||
|
||||
class OCRWnckHandlingTests(unittest.TestCase):
|
||||
def test_check_dependencies_does_not_fail_when_wnck_is_unavailable(self):
|
||||
testPlugin = ocr_plugin.OCRDesktop.__new__(ocr_plugin.OCRDesktop)
|
||||
|
||||
with (
|
||||
mock.patch.object(ocr_plugin, "PIL_AVAILABLE", True),
|
||||
mock.patch.object(ocr_plugin, "PYTESSERACT_AVAILABLE", True),
|
||||
mock.patch.object(ocr_plugin, "GTK_AVAILABLE", True),
|
||||
mock.patch.object(ocr_plugin, "WNCK_AVAILABLE", False),
|
||||
):
|
||||
self.assertTrue(testPlugin._checkDependencies())
|
||||
|
||||
def test_screen_shot_window_returns_false_when_wnck_is_unavailable(self):
|
||||
testPlugin = ocr_plugin.OCRDesktop.__new__(ocr_plugin.OCRDesktop)
|
||||
|
||||
with (
|
||||
mock.patch.object(ocr_plugin, "GTK_AVAILABLE", True),
|
||||
mock.patch.object(ocr_plugin, "WNCK_AVAILABLE", False),
|
||||
):
|
||||
self.assertFalse(testPlugin._screenShotWindow())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user