Attempt to speed up Steam even more. Sound for link added.
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
from types import SimpleNamespace
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
||||
|
||||
sound_stub = types.ModuleType("cthulhu.sound")
|
||||
sound_stub.getPlayer = mock.Mock(return_value=None)
|
||||
sys.modules.setdefault("cthulhu.sound", sound_stub)
|
||||
|
||||
speech_stub = types.ModuleType("cthulhu.speech")
|
||||
speech_stub.speak = mock.Mock()
|
||||
sys.modules.setdefault("cthulhu.speech", speech_stub)
|
||||
|
||||
from cthulhu import settings
|
||||
from cthulhu.sound_theme_manager import SoundThemeManager
|
||||
from cthulhu.speech_generator import SpeechGenerator
|
||||
from cthulhu.script_utilities import Utilities
|
||||
|
||||
|
||||
class LinkSoundThemeRegressionTests(unittest.TestCase):
|
||||
def test_default_theme_install_manifest_includes_link_sounds(self):
|
||||
mesonPath = Path(__file__).resolve().parents[1] / "sounds" / "meson.build"
|
||||
mesonText = mesonPath.read_text(encoding="utf-8")
|
||||
|
||||
self.assertIn("'default/link.wav'", mesonText)
|
||||
self.assertIn("'default/link_visited.wav'", mesonText)
|
||||
|
||||
def _create_manager(self):
|
||||
app = mock.Mock()
|
||||
settingsManager = mock.Mock()
|
||||
settingsManager.getSetting.return_value = "default"
|
||||
app.getSettingsManager.return_value = settingsManager
|
||||
return SoundThemeManager(app)
|
||||
|
||||
def test_visited_link_prefers_visited_asset(self):
|
||||
manager = self._create_manager()
|
||||
|
||||
with mock.patch.object(
|
||||
manager,
|
||||
"getSoundPath",
|
||||
side_effect=["/tmp/link_visited.wav", "/tmp/link.wav"],
|
||||
):
|
||||
icon = manager.getLinkSoundIcon(visited=True)
|
||||
|
||||
self.assertTrue(icon.path.endswith("link_visited.wav"))
|
||||
|
||||
def test_visited_link_falls_back_to_plain_link_asset(self):
|
||||
manager = self._create_manager()
|
||||
|
||||
with mock.patch.object(
|
||||
manager,
|
||||
"getSoundPath",
|
||||
side_effect=[None, "/tmp/link.wav"],
|
||||
):
|
||||
icon = manager.getLinkSoundIcon(visited=True)
|
||||
|
||||
self.assertTrue(icon.path.endswith("link.wav"))
|
||||
|
||||
|
||||
class SpeechGeneratorLinkSoundRegressionTests(unittest.TestCase):
|
||||
def test_role_sound_icon_uses_visited_link_asset_for_visited_links(self):
|
||||
generator = object.__new__(SpeechGenerator)
|
||||
generator._script = mock.Mock()
|
||||
generator._script.utilities = mock.Mock()
|
||||
|
||||
icon = SimpleNamespace(path="/tmp/link_visited.wav")
|
||||
|
||||
with (
|
||||
mock.patch("cthulhu.speech_generator.AXUtilities.is_link", return_value=True),
|
||||
mock.patch("cthulhu.speech_generator.AXUtilities.is_visited", return_value=True),
|
||||
mock.patch("cthulhu.speech_generator.sound_theme_manager.getManager") as get_manager,
|
||||
):
|
||||
get_manager.return_value.getLinkSoundIcon.return_value = icon
|
||||
result = generator._getRoleSoundIcon(mock.Mock(), "link-role")
|
||||
|
||||
self.assertEqual(result, icon)
|
||||
get_manager.return_value.getLinkSoundIcon.assert_called_once_with(visited=True)
|
||||
|
||||
|
||||
class LinkIndicatorPresentationRegressionTests(unittest.TestCase):
|
||||
def test_sound_only_inline_link_marker_uses_icon_instead_of_word(self):
|
||||
utility = object.__new__(Utilities)
|
||||
utility.adjustForLinks = mock.Mock(return_value="Docs link")
|
||||
|
||||
icon = SimpleNamespace(path="/tmp/link.wav")
|
||||
link = mock.Mock()
|
||||
|
||||
def get_setting(name):
|
||||
values = {
|
||||
"roleSoundPresentation": settings.ROLE_SOUND_PRESENTATION_SOUND_ONLY,
|
||||
"enableSound": True,
|
||||
}
|
||||
return values.get(name)
|
||||
|
||||
fakeApp = mock.Mock()
|
||||
fakeApp.settingsManager.getSetting.side_effect = get_setting
|
||||
|
||||
with (
|
||||
mock.patch("cthulhu.script_utilities.AXObject.supports_hypertext", return_value=True),
|
||||
mock.patch("cthulhu.script_utilities.AXHypertext.get_all_links", return_value=[link]),
|
||||
mock.patch("cthulhu.script_utilities.AXHypertext.get_link_start_offset", return_value=0),
|
||||
mock.patch("cthulhu.script_utilities.AXHypertext.get_link_end_offset", return_value=4),
|
||||
mock.patch("cthulhu.script_utilities.AXUtilities.is_visited", return_value=False),
|
||||
mock.patch("cthulhu.sound_theme_manager.getManager") as get_manager,
|
||||
mock.patch("cthulhu.script_utilities.cthulhu.cthulhuApp", fakeApp),
|
||||
):
|
||||
get_manager.return_value.getLinkSoundIcon.return_value = icon
|
||||
spoken, icons = utility.getLinkIndicatorPresentation(mock.Mock(), "Docs", 0)
|
||||
|
||||
self.assertEqual(spoken, "Docs")
|
||||
self.assertEqual(icons, [icon])
|
||||
|
||||
def test_sound_and_speech_inline_link_marker_keeps_word_and_adds_icon(self):
|
||||
utility = object.__new__(Utilities)
|
||||
utility.adjustForLinks = mock.Mock(return_value="Docs link")
|
||||
|
||||
icon = SimpleNamespace(path="/tmp/link_visited.wav")
|
||||
link = mock.Mock()
|
||||
|
||||
def get_setting(name):
|
||||
values = {
|
||||
"roleSoundPresentation": settings.ROLE_SOUND_PRESENTATION_SOUND_AND_SPEECH,
|
||||
"enableSound": True,
|
||||
}
|
||||
return values.get(name)
|
||||
|
||||
fakeApp = mock.Mock()
|
||||
fakeApp.settingsManager.getSetting.side_effect = get_setting
|
||||
|
||||
with (
|
||||
mock.patch("cthulhu.script_utilities.AXObject.supports_hypertext", return_value=True),
|
||||
mock.patch("cthulhu.script_utilities.AXHypertext.get_all_links", return_value=[link]),
|
||||
mock.patch("cthulhu.script_utilities.AXHypertext.get_link_start_offset", return_value=0),
|
||||
mock.patch("cthulhu.script_utilities.AXHypertext.get_link_end_offset", return_value=4),
|
||||
mock.patch("cthulhu.script_utilities.AXUtilities.is_visited", return_value=True),
|
||||
mock.patch("cthulhu.sound_theme_manager.getManager") as get_manager,
|
||||
mock.patch("cthulhu.script_utilities.cthulhu.cthulhuApp", fakeApp),
|
||||
):
|
||||
get_manager.return_value.getLinkSoundIcon.return_value = icon
|
||||
spoken, icons = utility.getLinkIndicatorPresentation(mock.Mock(), "Docs", 0)
|
||||
|
||||
self.assertEqual(spoken, "Docs link")
|
||||
self.assertEqual(icons, [icon])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -34,13 +34,37 @@ class {class_name}(Plugin):
|
||||
self.deactivation_count += 1
|
||||
"""
|
||||
|
||||
PLUGIN_TEMPLATE_PLAIN_SIGNATURE = """
|
||||
from cthulhu.plugin import Plugin, cthulhu_hookimpl
|
||||
|
||||
|
||||
class {class_name}(Plugin):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.activation_count = 0
|
||||
self.deactivation_count = 0
|
||||
|
||||
@cthulhu_hookimpl
|
||||
def activate(self):
|
||||
self.activation_count += 1
|
||||
|
||||
@cthulhu_hookimpl
|
||||
def deactivate(self):
|
||||
self.deactivation_count += 1
|
||||
"""
|
||||
|
||||
|
||||
class PluginSystemManagerRegressionTests(unittest.TestCase):
|
||||
def _create_plugin_info(self, root_dir: str, module_name: str) -> PluginInfo:
|
||||
def _create_plugin_info(
|
||||
self,
|
||||
root_dir: str,
|
||||
module_name: str,
|
||||
template: str = PLUGIN_TEMPLATE,
|
||||
) -> PluginInfo:
|
||||
plugin_dir = Path(root_dir) / module_name
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "plugin.py").write_text(
|
||||
textwrap.dedent(PLUGIN_TEMPLATE.format(class_name=module_name)),
|
||||
textwrap.dedent(template.format(class_name=module_name)),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return PluginInfo(
|
||||
@@ -93,6 +117,26 @@ class PluginSystemManagerRegressionTests(unittest.TestCase):
|
||||
self.assertEqual(first_plugin.instance.deactivation_count, 0)
|
||||
self.assertEqual(second_instance.deactivation_count, 1)
|
||||
|
||||
@mock.patch("cthulhu.plugin_system_manager.dbus_service.get_remote_controller")
|
||||
def test_loading_plugin_with_plain_activate_signature_succeeds(self, remote_controller):
|
||||
remote_controller.return_value = mock.Mock()
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
manager = self._create_manager()
|
||||
plugin_info = self._create_plugin_info(
|
||||
temp_dir,
|
||||
"PlainSignaturePlugin",
|
||||
template=PLUGIN_TEMPLATE_PLAIN_SIGNATURE,
|
||||
)
|
||||
|
||||
self.assertTrue(manager.loadPlugin(plugin_info))
|
||||
instance = plugin_info.instance
|
||||
self.assertEqual(instance.activation_count, 1)
|
||||
|
||||
self.assertTrue(manager.unloadPlugin(plugin_info))
|
||||
self.assertEqual(instance.deactivation_count, 1)
|
||||
self.assertEqual(plugin_info.instance, None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import mock
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
||||
|
||||
from cthulhu import debug
|
||||
from cthulhu.script_utilities import Utilities
|
||||
|
||||
|
||||
class ScriptUtilitiesRegressionTests(unittest.TestCase):
|
||||
@mock.patch("cthulhu.script_utilities.AXObject.get_application")
|
||||
def test_can_be_active_window_skips_cmdline_lookup_without_info_logging(self, get_application):
|
||||
utility = object.__new__(Utilities)
|
||||
utility._getAppCommandLine = mock.Mock(side_effect=AssertionError("cmdline lookup should be skipped"))
|
||||
utility._isActiveAndShowingAndNotIconified = mock.Mock(return_value=True)
|
||||
|
||||
window = object()
|
||||
app = object()
|
||||
get_application.return_value = app
|
||||
|
||||
with mock.patch.object(debug, "debugLevel", debug.LEVEL_SEVERE):
|
||||
self.assertTrue(utility.canBeActiveWindow(window))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user