Files
cbb-refresh-verify-795/tests/test_review391.py

68 lines
3.4 KiB
Python

import logging
import os
from threading import Event, Thread
from types import SimpleNamespace
import pytest
@pytest.mark.parametrize('damage', ['broken', 'missing', 'wrong_shape'])
def test_unreadable_export_evidence_explains_why_exclusion_is_unavailable(tmp_path, monkeypatch, caplog, damage):
import win32api, win32con
from cbb_refresh_verify import native_engineering_identity as identity
from cbb_refresh_verify.library_lock import LibraryBusy
from cbb_refresh_verify.native_export_guard import assert_retained_exports_idle
root=tmp_path/'analysis';root.mkdir()
if damage=='broken':(root/'ascii-process.json').write_text('{broken','utf-8')
if damage=='wrong_shape':(root/'ascii-process.json').write_text('[]','utf-8')
library=tmp_path/'library/lib.lmc'
handle=win32api.OpenProcess(win32con.SYNCHRONIZE,False,os.getpid())
monkeypatch.setattr(identity,'_retained_exports',[(SimpleNamespace(pid=123456,poll=lambda:0),
{os.getpid():handle},dict(library=str(library),analysis_root=str(root)))])
try:
with caplog.at_level(logging.WARNING),pytest.raises(LibraryBusy) as error:
assert_retained_exports_idle(library)
assert 'exclusion_unavailable' in str(error.value)
assert str(root) in str(error.value)
assert 'exclusion_unavailable' in caplog.text and str(root) in caplog.text
assert ('123456' in caplog.text if damage=='missing' else 'ascii-process.json' in caplog.text)
finally:handle.Close()
@pytest.mark.parametrize('after_result', ['refresh', 'close_summary', 'cancel_refresh'])
def test_batch_result_is_visible_before_queued_refresh_and_survives_user_actions(
qtbot,tmp_path,monkeypatch,after_result):
from test_ui_filters import load_window
from cbb_refresh_verify.verify_runner import VerifyResult
started,release,other_started,other_release,refreshed=(Event() for _ in range(5))
def verify(request):
started.set();release.wait(5)
return VerifyResult('PASS',library_flag='GREEN')
def refresh(names,library):
refreshed.set()
return {'Beta':'READY'}
window=load_window(qtbot,tmp_path,monkeypatch,verifier=verify,status_refresher=refresh)
window.search_edit.setText('Beta')
window._run(['Beta'])
qtbot.waitUntil(started.is_set)
def other():
other_started.set();other_release.wait(5)
thread=Thread(target=lambda:window.native_queue.run(other));thread.start()
try:
qtbot.waitUntil(lambda:len(window.native_queue.pending)==1)
release.set();qtbot.waitUntil(other_started.is_set)
qtbot.waitUntil(lambda:getattr(window,'summary',None) is not None,timeout=1500)
assert window.summary.isVisible() and window.busy
assert not refreshed.is_set()
assert window._records_by_name['Beta'].status=='PENDING'
assert '已结束' in window.status_label.text()
if after_result=='close_summary':window.summary.close()
if after_result=='cancel_refresh':window.request_stop()
finally:
release.set();other_release.set();thread.join(6)
qtbot.waitUntil(lambda:not window.busy,timeout=7000)
assert window._records_by_name['Beta'].status==('UNKNOWN' if after_result=='cancel_refresh' else 'READY')
if after_result=='close_summary':assert window.summary is None
else:assert '成功 1' in window.summary.detailedText()
assert refreshed.is_set() is (after_result!='cancel_refresh')