fix: preserve native calls on stop and keep status reads observational
This commit is contained in:
1 parent
97a3de20c9
commit
8d3eab1164
19 files changed
+631
-290
No files matched your search
@@ -0,0 +1,41 @@
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from cbb_refresh_verify import mentor_adapter as adapter
|
||||
from cbb_refresh_verify.library_reader import scan_open_library_status
|
||||
|
||||
|
||||
@pytest.mark.parametrize('prompt', ['', 'Repair database', 'Overwrite existing library',
|
||||
'Save changes?', 'Unknown license warning'])
|
||||
def test_compat_readers_neither_launch_nor_answer_native_prompts(monkeypatch, tmp_path, prompt):
|
||||
import win32process, win32service, win32gui
|
||||
from pywinauto import Desktop
|
||||
def forbidden(*a, **kw):
|
||||
pytest.fail('status observation attempted a native action')
|
||||
monkeypatch.setattr(win32process, 'CreateProcess', forbidden)
|
||||
monkeypatch.setattr(win32service, 'CreateDesktop', forbidden)
|
||||
monkeypatch.setattr(win32gui, 'PostMessage', forbidden)
|
||||
monkeypatch.setattr(adapter, 'handle_known_dialogs', forbidden)
|
||||
monkeypatch.setattr(adapter, 'close_library_reader', forbidden)
|
||||
library = tmp_path/'lib.lmc'
|
||||
target = SimpleNamespace(window_text=lambda: f'Library Manager: {library}',
|
||||
is_enabled=lambda: not bool(prompt), descendants=lambda: [], handle=0)
|
||||
monkeypatch.setattr(Desktop, 'windows', lambda *_: [target] if prompt else [])
|
||||
assert adapter.read_library_flag(library, 'A')[0] == adapter.FLAG_UNKNOWN
|
||||
assert adapter.read_library_tree_image_map(library, ['A']) == {'A': None}
|
||||
assert scan_open_library_status(library, ['A']) == {'A': 'UNKNOWN'}
|
||||
|
||||
|
||||
def test_wrong_library_window_is_not_a_status_source(monkeypatch, tmp_path):
|
||||
from pywinauto import Desktop
|
||||
import win32process, win32service
|
||||
monkeypatch.setattr(win32process, 'CreateProcess', lambda *a, **kw: pytest.fail('implicit launch'))
|
||||
monkeypatch.setattr(win32service, 'CreateDesktop', lambda *a, **kw: pytest.fail('implicit desktop'))
|
||||
def forbidden():
|
||||
pytest.fail('read another library tree')
|
||||
window = SimpleNamespace(window_text=lambda: 'Library Manager: C:/Other/lib.lmc',
|
||||
descendants=forbidden)
|
||||
monkeypatch.setattr(Desktop, 'windows', lambda *_: [window])
|
||||
assert adapter.read_library_tree_image_map(tmp_path/'lib.lmc', ['A']) == {'A': None}
|
||||
Reference in new issue
Block a user