Fix stuff, apply ruff rules.
This commit is contained in:
61
tests/test_script_initialization.py
Normal file
61
tests/test_script_initialization.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""Regression tests for script startup ordering."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from cthulhu.scripts import default
|
||||
|
||||
script_module = default.script
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_script_initializes_formatting_before_generators(monkeypatch):
|
||||
"""Generator construction needs script.formatting during startup."""
|
||||
|
||||
monkeypatch.setattr(script_module.AXObject, "get_name", staticmethod(lambda _app: "test-app"))
|
||||
init_order = []
|
||||
formatting = {"sentinel": True}
|
||||
|
||||
class FormattingAwareScript(script_module.Script):
|
||||
def get_formatting(self):
|
||||
init_order.append("formatting")
|
||||
return formatting
|
||||
|
||||
def get_listeners(self):
|
||||
return {}
|
||||
|
||||
def get_utilities(self):
|
||||
return object()
|
||||
|
||||
def _create_braille_generator(self):
|
||||
init_order.append("braille")
|
||||
assert self.formatting is formatting
|
||||
return "braille"
|
||||
|
||||
def _create_sound_generator(self):
|
||||
init_order.append("sound")
|
||||
assert self.formatting is formatting
|
||||
return "sound"
|
||||
|
||||
def _create_speech_generator(self):
|
||||
init_order.append("speech")
|
||||
assert self.formatting is formatting
|
||||
return "speech"
|
||||
|
||||
def get_label_inference(self):
|
||||
return None
|
||||
|
||||
def get_chat(self):
|
||||
return None
|
||||
|
||||
def set_up_commands(self):
|
||||
pass
|
||||
|
||||
test_script = FormattingAwareScript(object())
|
||||
|
||||
assert init_order == ["formatting", "braille", "sound", "speech"]
|
||||
assert test_script.formatting is formatting
|
||||
assert test_script.get_braille_generator() == "braille"
|
||||
assert test_script.get_sound_generator() == "sound"
|
||||
assert test_script.get_speech_generator() == "speech"
|
||||
Reference in New Issue
Block a user