fix: preload UIA before native proxies and package timezone support
This commit is contained in:
1 parent
ffa7e84d43
commit
1f69480ed8
4 files changed
+65
-1
No files matched your search
@@ -60,3 +60,49 @@ def test_probe_records_dispatch_before_after_import_and_after_source_alignment(t
|
||||
assert records[1]['members']['application.Quit']['dispid'] == 2
|
||||
assert records[2]['paths'] == {'source': str(source), 'pcb': str(pcb), 'library_argument': str(library)}
|
||||
assert 'old.lmc' not in source.read_text()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('operation', ['probe_create_add', 'probe_readd', 'catalog'])
|
||||
def test_probe_preloads_uia_before_com_proxy_creation_but_catalog_stays_read_only(tmp_path, monkeypatch, operation):
|
||||
import sys, win32com.client
|
||||
import cbb_refresh_verify.native_management as native
|
||||
import cbb_refresh_verify.mentor_adapter as mentor
|
||||
root = tmp_path/'job'; root.mkdir()
|
||||
library_path = tmp_path/'fixture.lmc'; library_path.touch()
|
||||
events, running = [], [False]
|
||||
class Uia(ModuleType):
|
||||
def __getattr__(self, name):
|
||||
if name == 'Desktop':
|
||||
events.append('uia-loaded')
|
||||
return object
|
||||
raise AttributeError(name)
|
||||
monkeypatch.setitem(sys.modules, 'pywinauto', Uia('pywinauto'))
|
||||
library = SimpleNamespace(FullName=str(library_path), FlowType=1,
|
||||
Partitions=lambda kind: SimpleNamespace(Count=0), Close=lambda: events.append('library-close'))
|
||||
class App:
|
||||
def OpenLibrary(self, path): return library
|
||||
def CreateLibrary(self, path, flow): return library
|
||||
def Quit(self): events.append('quit'); running[0] = False
|
||||
def dispatch(progid):
|
||||
events.append('dispatch'); running[0] = True
|
||||
return App()
|
||||
monkeypatch.setattr(win32com.client, 'DispatchEx', dispatch)
|
||||
monkeypatch.setattr(native, '_current_desktop', lambda:
|
||||
(SimpleNamespace(EnumDesktopWindows=lambda: []), 'CbbManagement_test'))
|
||||
monkeypatch.setattr(mentor, '_process_details', lambda name:
|
||||
[(123, str(tmp_path/'lm/win32/bin/LibraryManager.exe'), '', 0)] if running[0] else [])
|
||||
monkeypatch.setattr(native, 'prepare_probe_library', lambda *a: library_path)
|
||||
monkeypatch.setattr(native, 'validate_probe_readd', lambda *a: library_path)
|
||||
class Disconnected(RuntimeError):
|
||||
hresult = -2147220995
|
||||
def editor(*a, **k): raise Disconnected('controlled native failure')
|
||||
monkeypatch.setattr(native, '_probe_add_dialog', editor)
|
||||
monkeypatch.setattr(native, '_wait_native_exit', lambda pids: True)
|
||||
result = native._catalog_native({'operation': operation, 'desktop': 'CbbManagement_test',
|
||||
'library': str(library_path), 'mentor_home': str(tmp_path), 'probe_token': 'fixture'}, root)
|
||||
assert events[:2] == (['dispatch', 'library-close'] if operation == 'catalog' else ['uia-loaded', 'dispatch'])
|
||||
if operation == 'catalog':
|
||||
assert result['success'] and 'uia-loaded' not in events
|
||||
else:
|
||||
assert result['exception']['hresult'] == -2147220995
|
||||
assert result['exception']['args'] == ['controlled native failure']
|
||||
@@ -12,3 +12,17 @@ def test_spec_packages_adaptive_dialog_rules_and_uia_modules():
|
||||
text = Path('packaging/CbbRefreshVerify.spec').read_text(encoding='utf-8')
|
||||
assert 'dialog_rules.v1.json' in text
|
||||
assert 'pywinauto' in text
|
||||
|
||||
|
||||
def test_spec_analysis_includes_pywin32_timezone_dynamic_import():
|
||||
from types import SimpleNamespace
|
||||
captured = {}
|
||||
def analysis(*args, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return SimpleNamespace(pure=[], scripts=[], binaries=[], zipfiles=[], datas=[])
|
||||
path = Path('packaging/CbbRefreshVerify.spec')
|
||||
namespace = {'SPECPATH': str(path.parent.resolve()), 'Analysis': analysis,
|
||||
'PYZ': lambda *a, **k: None, 'EXE': lambda *a, **k: None,
|
||||
'COLLECT': lambda *a, **k: None}
|
||||
exec(compile(path.read_text(encoding='utf-8'), str(path), 'exec'), namespace)
|
||||
assert 'win32timezone' in captured['hiddenimports']
|
||||
Reference in new issue
Block a user