More fixes to pty reading.
This commit is contained in:
@@ -61,6 +61,7 @@ def incoming_command():
|
||||
},
|
||||
"screen": {
|
||||
"new_delta": "",
|
||||
"new_delta_is_typing": False,
|
||||
"old_content_text": "",
|
||||
"new_content_text": "",
|
||||
"old_cursor": {"x": 0, "y": 0},
|
||||
@@ -138,3 +139,12 @@ class TestIncomingCommand:
|
||||
output_manager.present_text.assert_called_once_with(
|
||||
"Status new\nUsers new", interrupt=False, flush=False
|
||||
)
|
||||
|
||||
def test_skips_typing_delta(self, incoming_command):
|
||||
command, env, output_manager = incoming_command
|
||||
env["screen"]["new_delta"] = "x"
|
||||
env["screen"]["new_delta_is_typing"] = True
|
||||
|
||||
command.run()
|
||||
|
||||
output_manager.present_text.assert_not_called()
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def _load_progress_module():
|
||||
module_path = (
|
||||
Path(__file__).resolve().parents[2]
|
||||
/ "src"
|
||||
/ "fenrirscreenreader"
|
||||
/ "commands"
|
||||
/ "onScreenUpdate"
|
||||
/ "65000-progress_detector.py"
|
||||
)
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"fenrir_progress_detector", module_path
|
||||
)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_progress_detector_skips_typing_delta():
|
||||
progress_module = _load_progress_module()
|
||||
command = progress_module.command()
|
||||
command.env = {
|
||||
"commandBuffer": {"progress_monitoring": True},
|
||||
"runtime": {"DebugManager": Mock(write_debug_out=Mock())},
|
||||
"screen": {"new_delta": "x", "new_delta_is_typing": True},
|
||||
}
|
||||
command.is_current_line_prompt = Mock(return_value=False)
|
||||
command.is_real_progress_update = Mock(return_value=True)
|
||||
command.detect_progress = Mock()
|
||||
|
||||
command.run()
|
||||
|
||||
command.is_real_progress_update.assert_not_called()
|
||||
command.detect_progress.assert_not_called()
|
||||
@@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from fenrirscreenreader.screenDriver.ptyDriver import PTYConstants
|
||||
from fenrirscreenreader.screenDriver.ptyDriver import Terminal
|
||||
from fenrirscreenreader.screenDriver.ptyDriver import driver as PtyDriver
|
||||
|
||||
|
||||
class DummyProcessInput:
|
||||
@@ -20,3 +22,23 @@ def test_csi_sequences_with_intermediate_characters_do_not_render_final_byte():
|
||||
|
||||
assert screen["text"].splitlines()[0] == "X "
|
||||
assert "p" not in screen["text"]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_optional_float_setting_uses_default_when_missing():
|
||||
settings_manager = type(
|
||||
"SettingsManager",
|
||||
(),
|
||||
{"get_setting": lambda self, section, setting: ""},
|
||||
)()
|
||||
pty_driver = PtyDriver()
|
||||
|
||||
assert (
|
||||
pty_driver._get_optional_float_setting(
|
||||
settings_manager,
|
||||
"screen",
|
||||
"ptyOutputTimeout",
|
||||
PTYConstants.OUTPUT_READ_TIMEOUT,
|
||||
)
|
||||
== PTYConstants.OUTPUT_READ_TIMEOUT
|
||||
)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from fenrirscreenreader.core.screenManager import ScreenManager
|
||||
|
||||
|
||||
def _build_screen_manager(old_text, old_cursor):
|
||||
manager = ScreenManager()
|
||||
env = {
|
||||
"runtime": {
|
||||
"AttributeManager": Mock(
|
||||
reset_attributes=Mock(),
|
||||
reset_attribute_cursor=Mock(),
|
||||
set_attributes=Mock(),
|
||||
reset_attribute_delta=Mock(),
|
||||
is_attribute_change=Mock(return_value=False),
|
||||
),
|
||||
"CursorManager": Mock(is_application_window_set=Mock(return_value=False)),
|
||||
"DebugManager": Mock(write_debug_out=Mock()),
|
||||
"ScreenManager": manager,
|
||||
"SettingsManager": Mock(get_setting_as_bool=Mock(return_value=False)),
|
||||
},
|
||||
"screen": {
|
||||
"newContentBytes": b"",
|
||||
"oldContentBytes": b"",
|
||||
"new_content_text": old_text,
|
||||
"old_content_text": "",
|
||||
"new_cursor": old_cursor.copy(),
|
||||
"old_cursor": {"x": 0, "y": 0},
|
||||
"new_delta": "",
|
||||
"new_delta_is_typing": False,
|
||||
"oldDelta": "",
|
||||
"newNegativeDelta": "",
|
||||
"oldNegativeDelta": "",
|
||||
"oldTTY": "pty",
|
||||
"newTTY": "pty",
|
||||
},
|
||||
}
|
||||
manager.initialize = Mock()
|
||||
manager.env = env
|
||||
return manager, env
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_prompt_repaint_during_typing_keeps_only_typed_delta():
|
||||
manager, env = _build_screen_manager("[0] ", {"x": 4, "y": 0})
|
||||
|
||||
manager.update(
|
||||
{
|
||||
"bytes": b"[1] h",
|
||||
"lines": 1,
|
||||
"columns": 20,
|
||||
"textCursor": {"x": 5, "y": 0},
|
||||
"screen": "pty",
|
||||
"text": "[1] h",
|
||||
"attributes": [],
|
||||
},
|
||||
"onScreenUpdate",
|
||||
)
|
||||
|
||||
assert env["screen"]["new_delta"] == "h"
|
||||
assert env["screen"]["new_delta_is_typing"] is True
|
||||
Reference in New Issue
Block a user