Initial import of DxDesigner part replacement tool (r21)
This commit is contained in:
commit
ffe066cb1e
151 files changed
+58745
No files matched your search
@@ -0,0 +1,517 @@
|
||||
import ast
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / 'integration/dxdesigner795/QuickPartReplace.vbs'
|
||||
|
||||
FAKES = r'''
|
||||
Dim FakeApp, AttachCalls, LaunchCalls, ReadyAfter, SleepCalls
|
||||
Set FakeApp = New SessionApp
|
||||
AttachCalls = 0
|
||||
LaunchCalls = 0
|
||||
SleepCalls = 0
|
||||
ReadyAfter = 0
|
||||
Function FakeAttach()
|
||||
AttachCalls = AttachCalls + 1
|
||||
Set FakeAttach = Nothing
|
||||
If AttachCalls > ReadyAfter Then Set FakeAttach = FakeApp
|
||||
End Function
|
||||
Function FakeLaunch()
|
||||
LaunchCalls = LaunchCalls + 1
|
||||
Set FakeLaunch = FakeApp
|
||||
End Function
|
||||
Sub FakeSleep(ByVal Milliseconds)
|
||||
SleepCalls = SleepCalls + 1
|
||||
End Sub
|
||||
Sub Require(ByVal Condition, ByVal Message)
|
||||
If Not Condition Then Err.Raise 51000, "Test", Message
|
||||
End Sub
|
||||
Class SessionApp
|
||||
Public ProjectPath, Visible, OpenCount, OpenResult, ActiveView, Documents, ActualSheet, CloseCount, SaveCount, RefuseClose, Components
|
||||
Private Sub Class_Initialize()
|
||||
ProjectPath = ""
|
||||
OpenCount = 0
|
||||
OpenResult = True
|
||||
ActualSheet = "1"
|
||||
Set ActiveView = Nothing
|
||||
Set Components = CreateObject("Scripting.Dictionary")
|
||||
Set Documents = New SessionDocuments
|
||||
Set Documents.Owner = Me
|
||||
End Sub
|
||||
Public Function GetProjectData()
|
||||
Set GetProjectData = Me
|
||||
End Function
|
||||
Public Function GetProjectFilePath()
|
||||
GetProjectFilePath = ProjectPath
|
||||
End Function
|
||||
Public Function OpenProject(ByVal Target)
|
||||
OpenCount = OpenCount + 1
|
||||
If OpenResult Then ProjectPath = Target
|
||||
OpenProject = OpenResult
|
||||
End Function
|
||||
Public Function SchematicSheetDocuments()
|
||||
Set SchematicSheetDocuments = Documents
|
||||
End Function
|
||||
Public Sub CloseProject()
|
||||
CloseCount = CloseCount + 1
|
||||
If Not RefuseClose Then ProjectPath = ""
|
||||
End Sub
|
||||
Public Function GetName(ByVal Flags)
|
||||
GetName = "Main"
|
||||
End Function
|
||||
Public Property Get Block()
|
||||
Set Block = Me
|
||||
End Property
|
||||
Public Property Get SheetNum()
|
||||
SheetNum = ActualSheet
|
||||
End Property
|
||||
Public Function Query(ByVal Kind, ByVal Scope)
|
||||
Set Query = Components
|
||||
End Function
|
||||
End Class
|
||||
Class SessionDocuments
|
||||
Public Owner, OpenCount, SheetCount
|
||||
Private Sub Class_Initialize()
|
||||
OpenCount = 0
|
||||
SheetCount = 1
|
||||
End Sub
|
||||
Public Function GetAvailableSchematics()
|
||||
Dim Names
|
||||
Set Names = CreateObject("Scripting.Dictionary")
|
||||
Names.Add "Main", True
|
||||
Set GetAvailableSchematics = Names
|
||||
End Function
|
||||
Public Function GetAvailableSheets(ByVal Schematic)
|
||||
Dim Names, Index
|
||||
Set Names = CreateObject("Scripting.Dictionary")
|
||||
For Index = 1 To SheetCount
|
||||
Names.Add CStr(Index), True
|
||||
Next
|
||||
Set GetAvailableSheets = Names
|
||||
End Function
|
||||
Public Function Open(ByVal Schematic, ByVal Sheet)
|
||||
OpenCount = OpenCount + 1
|
||||
Set Owner.ActiveView = Owner
|
||||
Set Open = Me
|
||||
End Function
|
||||
Public Sub Activate()
|
||||
End Sub
|
||||
Public Property Get Count
|
||||
Count = 1
|
||||
End Property
|
||||
Public Function Item(ByVal Index)
|
||||
If Index <> 1 Then Err.Raise 51000,"Test","bad document index"
|
||||
Set Item = Me
|
||||
End Function
|
||||
Public Sub Close(ByVal SaveChanges, ByVal FileName)
|
||||
If SaveChanges Then Owner.SaveCount = Owner.SaveCount + 1
|
||||
Set Owner.ActiveView = Nothing
|
||||
End Sub
|
||||
End Class
|
||||
Class SessionComponent
|
||||
Public PartNumber, Refdes
|
||||
Public Function FindAttribute(ByVal Name)
|
||||
Dim Attribute
|
||||
Set FindAttribute = Nothing
|
||||
If Name = "Part Number" Then
|
||||
Set Attribute = New SessionAttribute
|
||||
Attribute.Value = PartNumber
|
||||
Set FindAttribute = Attribute
|
||||
End If
|
||||
End Function
|
||||
End Class
|
||||
Class SessionAttribute
|
||||
Public InstanceValue, Value
|
||||
End Class
|
||||
'''
|
||||
|
||||
|
||||
def run_session(tmp_path, body):
|
||||
source = SOURCE.read_text(encoding='ascii')
|
||||
header = source[:source.index('Set QP_Fso =')]
|
||||
routines = source[source.index('Sub QPMain()'):]
|
||||
routines = routines.replace('GetObject(, "Viewdraw.Application")', 'FakeAttach()')
|
||||
routines = routines.replace('CreateObject("Viewdraw.Application")', 'FakeLaunch()')
|
||||
routines = routines.replace('WScript.Sleep ', 'FakeSleep ')
|
||||
routines = routines.replace('QPAttachOrStart(QPDesignerProcessCount())', 'QPAttachOrStart(0)')
|
||||
target = tmp_path / 'target.prj'
|
||||
target.touch()
|
||||
setup = f'''
|
||||
Set QP_Fso = CreateObject("Scripting.FileSystemObject")
|
||||
QP_Root = "{tmp_path}"
|
||||
Dim Target, Attached
|
||||
Target = "{target}"
|
||||
'''
|
||||
wrapper = tmp_path / 'session-test.vbs'
|
||||
wrapper.write_text(header + FAKES + setup + body + '\nWScript.Echo "PASS"\nWScript.Quit 0\n' + routines, encoding='ascii')
|
||||
result = subprocess.run(['cscript.exe', '//nologo', str(wrapper)], capture_output=True, timeout=15,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW)
|
||||
assert result.returncode == 0, (result.stdout + result.stderr).decode(errors='replace')
|
||||
assert b'PASS' in result.stdout, result.stderr.decode('gbk', errors='replace')
|
||||
|
||||
|
||||
def test_batch_refuses_to_take_over_an_existing_project(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
QP_BatchMode=True
|
||||
FakeApp.ProjectPath=Target
|
||||
On Error Resume Next
|
||||
QPEnsureProject FakeApp,Target
|
||||
Dim Failure
|
||||
Failure=Err.Number
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure<>0,"batch took over user project"
|
||||
Require FakeApp.OpenCount=0,"opened another project"
|
||||
Require IsEmpty(FakeApp.CloseCount),"closed user project"
|
||||
''')
|
||||
|
||||
|
||||
def test_batch_no_match_commits_only_after_owned_project_close(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
Set QP_App=FakeApp
|
||||
FakeApp.ProjectPath=Target
|
||||
QP_CurrentJobId="batch-job": QP_ExpectedJobId="batch-job"
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root,"command.tsv"),"task_id" & vbTab & "job_id" & vbTab & "project_path" & vbTab & "old_part" & vbTab & "new_part" & vbTab & "value_mode" & vbCrLf & "task" & vbTab & "batch-job" & vbTab & Target & vbTab & "OLD" & vbTab & "NEW" & vbTab & "preserve" & vbCrLf
|
||||
QP_BatchMode=True: QP_OwnedProject=True
|
||||
QPWriteStatus QP_Root,QP_CurrentJobId,"no_match","","not found"
|
||||
Require Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root,"status.tsv")),"published success before close"
|
||||
Require QPReadState(QP_Fso.BuildPath(QP_Root,"status.tsv"),QP_CurrentJobId)="no_match","pending no-match not visible to worker"
|
||||
QPFinishBatchItem
|
||||
Require FakeApp.CloseCount=1,"project not closed exactly once"
|
||||
Require FakeApp.SaveCount=1,"sheet not closed with saving allowed"
|
||||
Require InStr(QPReadUtf8(QP_Fso.BuildPath(QP_Root,"status.tsv")),"batch_closed")>0,"no completion proof"
|
||||
''')
|
||||
|
||||
|
||||
def test_batch_never_closes_unowned_project(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
Set QP_App=FakeApp
|
||||
FakeApp.ProjectPath=Target
|
||||
QP_OwnedProject=False
|
||||
On Error Resume Next
|
||||
QPCloseBatchProject Target
|
||||
Dim Failure
|
||||
Failure=Err.Number
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure<>0,"unowned project accepted"
|
||||
Require IsEmpty(FakeApp.CloseCount),"unowned project closed"
|
||||
''')
|
||||
|
||||
|
||||
def test_batch_close_failure_is_not_reported_as_done(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
Set QP_App=FakeApp
|
||||
FakeApp.ProjectPath=Target
|
||||
QP_OwnedProject=True: FakeApp.RefuseClose=True
|
||||
On Error Resume Next
|
||||
QPCloseBatchProject Target
|
||||
Dim Failure
|
||||
Failure=Err.Number
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure<>0,"close refusal ignored"
|
||||
Require Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root,"status.tsv")),"false terminal status"
|
||||
''')
|
||||
|
||||
|
||||
def test_absent_designer_is_started_once(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
ReadyAfter = 999
|
||||
Set Attached = QPAttachOrStart(0)
|
||||
Require LaunchCalls = 1, "did not start exactly once"
|
||||
Require Attached Is FakeApp, "wrong application"
|
||||
Require FakeApp.Visible, "new application not visible"
|
||||
''')
|
||||
|
||||
|
||||
def test_existing_designer_is_reused(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
Set Attached = QPAttachOrStart(1)
|
||||
Require LaunchCalls = 0, "started duplicate"
|
||||
Require Attached Is FakeApp, "wrong application"
|
||||
''')
|
||||
|
||||
|
||||
def test_starting_designer_is_waited_for_not_duplicated(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
ReadyAfter = 3
|
||||
Set Attached = QPAttachOrStart(1)
|
||||
Require LaunchCalls = 0, "started duplicate during startup"
|
||||
Require SleepCalls > 0, "did not wait for registration"
|
||||
''')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('count', [1, 2])
|
||||
def test_unavailable_or_multiple_instances_do_not_launch(tmp_path, count):
|
||||
run_session(tmp_path, f'''
|
||||
ReadyAfter = 999
|
||||
On Error Resume Next
|
||||
Set Attached = QPAttachOrStart({count})
|
||||
Dim Failure, FailureSource
|
||||
Failure = Err.Number
|
||||
FailureSource = Err.Source
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure <> 0, "unsafe instance accepted"
|
||||
Require FailureSource = "QuickPartReplace.Session", "wrong failure source"
|
||||
Require LaunchCalls = 0, "started duplicate instance"
|
||||
''')
|
||||
|
||||
|
||||
def test_empty_session_opens_project_and_only_sheet(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
QPEnsureProject FakeApp, Target
|
||||
Require FakeApp.OpenCount = 1, "project not opened"
|
||||
Require FakeApp.ProjectPath = Target, "wrong project"
|
||||
Require FakeApp.Documents.OpenCount = 1, "sole sheet not opened"
|
||||
''')
|
||||
|
||||
|
||||
def test_matching_active_project_is_not_reopened(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
FakeApp.ProjectPath = Target
|
||||
Set FakeApp.ActiveView = FakeApp
|
||||
QPEnsureProject FakeApp, Target
|
||||
Require FakeApp.OpenCount = 0, "reopened user project"
|
||||
Require FakeApp.Documents.OpenCount = 0, "changed user page"
|
||||
''')
|
||||
|
||||
|
||||
def test_other_project_is_never_closed_or_replaced(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
FakeApp.ProjectPath = "C:\\unrelated.prj"
|
||||
On Error Resume Next
|
||||
QPEnsureProject FakeApp, Target
|
||||
Dim Failure
|
||||
Failure = Err.Source
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure = "QuickPartReplace.Session", "accepted wrong project"
|
||||
Require FakeApp.OpenCount = 0, "switched unrelated project"
|
||||
''')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('sheets', [0, 2])
|
||||
def test_missing_or_ambiguous_sheet_is_not_silently_selected(tmp_path, sheets):
|
||||
run_session(tmp_path, f'''
|
||||
FakeApp.Documents.SheetCount = {sheets}
|
||||
On Error Resume Next
|
||||
QPEnsureProject FakeApp, Target
|
||||
Dim Failure
|
||||
Failure = Err.Source
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure = "QuickPartReplace.Session", "invalid page set accepted"
|
||||
Require FakeApp.Documents.OpenCount = 0, "selected arbitrary page"
|
||||
''')
|
||||
|
||||
|
||||
def test_batch_opens_the_exact_confirmed_sheet_in_a_multisheet_project(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
QP_BatchMode = True
|
||||
QP_ExpectedJobId = "job"
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "command.tsv"), _
|
||||
"task_id" & vbTab & "job_id" & vbTab & "project_path" & vbTab & "schematic_name" & vbTab & "sheet_number" & vbTab & "old_part" & vbTab & "new_part" & vbTab & "value_mode" & vbCrLf & _
|
||||
"task" & vbTab & "job" & vbTab & Target & vbTab & "Main" & vbTab & "2" & vbTab & "OLD" & vbTab & "NEW" & vbTab & "preserve" & vbCrLf
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "sheets.tsv"), _
|
||||
"project_path" & vbTab & "schematic_name" & vbTab & "sheet_number" & vbCrLf & _
|
||||
Target & vbTab & "Main" & vbTab & "1" & vbCrLf & _
|
||||
Target & vbTab & "Main" & vbTab & "2" & vbCrLf
|
||||
FakeApp.Documents.SheetCount = 2
|
||||
FakeApp.ActualSheet = "2"
|
||||
Dim Confirmed
|
||||
Confirmed = QPConfirmedProjectPath()
|
||||
QPEnsureProject FakeApp, Confirmed
|
||||
Require FakeApp.Documents.OpenCount = 1, "confirmed sheet not opened exactly once"
|
||||
Require CStr(FakeApp.ActiveView.Block.SheetNum) = "2", "wrong confirmed sheet activated"
|
||||
''')
|
||||
|
||||
|
||||
def test_changed_sheet_set_stops_before_opening_a_page(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
QP_BatchMode = True
|
||||
QP_ExpectedJobId = "job"
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "command.tsv"), _
|
||||
"task_id" & vbTab & "job_id" & vbTab & "project_path" & vbTab & "schematic_name" & vbTab & "sheet_number" & vbTab & "old_part" & vbTab & "new_part" & vbTab & "value_mode" & vbCrLf & _
|
||||
"task" & vbTab & "job" & vbTab & Target & vbTab & "Main" & vbTab & "1" & vbTab & "OLD" & vbTab & "NEW" & vbTab & "preserve" & vbCrLf
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "sheets.tsv"), _
|
||||
"project_path" & vbTab & "schematic_name" & vbTab & "sheet_number" & vbCrLf & _
|
||||
Target & vbTab & "Main" & vbTab & "1" & vbCrLf
|
||||
FakeApp.Documents.SheetCount = 2
|
||||
Dim Confirmed, Failure
|
||||
Confirmed = QPConfirmedProjectPath()
|
||||
On Error Resume Next
|
||||
QPEnsureProject FakeApp, Confirmed
|
||||
Failure = Err.Description
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure = "project sheet set changed after discovery", "changed page set accepted"
|
||||
Require FakeApp.Documents.OpenCount = 0, "opened a page after manifest mismatch"
|
||||
''')
|
||||
|
||||
|
||||
def test_sheet_discovery_records_every_page_and_closes_without_saving(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
Set QP_App = FakeApp
|
||||
QP_BatchMode = True
|
||||
QP_DiscoveryMode = True
|
||||
QP_OwnedProject = True
|
||||
FakeApp.ProjectPath = Target
|
||||
FakeApp.Documents.SheetCount = 2
|
||||
QPDiscoverSheets
|
||||
Require FakeApp.CloseCount = 1, "discovery did not close its project"
|
||||
Require FakeApp.ProjectPath = "", "discovery left the project open"
|
||||
Require FakeApp.Documents.OpenCount = 0, "discovery opened a page"
|
||||
Dim Manifest
|
||||
Manifest = QPReadUtf8(QP_Fso.BuildPath(QP_Root, "sheets.tsv"))
|
||||
Require InStr(Manifest, Target & vbTab & "Main" & vbTab & "1") > 0, "sheet one missing"
|
||||
Require InStr(Manifest, Target & vbTab & "Main" & vbTab & "2") > 0, "sheet two missing"
|
||||
''')
|
||||
|
||||
|
||||
def test_sheet_discovery_writes_an_empty_inventory_for_an_absent_requested_part(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
Set QP_App = FakeApp
|
||||
QP_BatchMode = True
|
||||
QP_DiscoveryMode = True
|
||||
QP_OwnedProject = True
|
||||
FakeApp.ProjectPath = Target
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "inventory-request.tsv"), _
|
||||
"old_part" & vbCrLf & "MISSING" & vbCrLf
|
||||
QPDiscoverSheets
|
||||
Require FakeApp.Documents.OpenCount = 1, "inventory did not open the available sheet exactly once"
|
||||
Require FakeApp.SaveCount = 0, "read-only inventory saved the sheet"
|
||||
Dim Inventory
|
||||
Inventory = QPReadUtf8(QP_Fso.BuildPath(QP_Root, "inventory.tsv"))
|
||||
Require InStr(Inventory, "MISSING") = 0, "absent source part was reported as present"
|
||||
''')
|
||||
|
||||
|
||||
def test_replacement_summary_uses_the_confirmed_snapshot_refdes(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
Dim Records, Components, ComponentRecord, Plans, Candidate, Summary
|
||||
Set Records = CreateObject("Scripting.Dictionary")
|
||||
Set Components = CreateObject("Scripting.Dictionary")
|
||||
Set ComponentRecord = CreateObject("Scripting.Dictionary")
|
||||
ComponentRecord.Add "refdes", "C42"
|
||||
ComponentRecord.Add "uid", "$1I52"
|
||||
Components.Add "0", ComponentRecord
|
||||
Set ComponentRecord = CreateObject("Scripting.Dictionary")
|
||||
ComponentRecord.Add "refdes", ""
|
||||
ComponentRecord.Add "uid", "$1I60"
|
||||
Components.Add "1", ComponentRecord
|
||||
Records.Add "components", Components
|
||||
Set Plans = CreateObject("Scripting.Dictionary")
|
||||
Set Candidate = New SessionComponent
|
||||
Candidate.Refdes = ""
|
||||
Plans.Add "0", Candidate
|
||||
Set Candidate = New SessionComponent
|
||||
Candidate.Refdes = ""
|
||||
Plans.Add "1", Candidate
|
||||
Summary = QPReplacementSummary(Records, Plans, "OLD", "NEW")
|
||||
Require Summary = "C42 OLD -> NEW; UID=$1I60 OLD -> NEW", "replacement summary lost component identity"
|
||||
''')
|
||||
|
||||
|
||||
def test_open_failure_does_not_enumerate_or_open_sheets(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
FakeApp.OpenResult = False
|
||||
On Error Resume Next
|
||||
QPEnsureProject FakeApp, Target
|
||||
Dim Failure
|
||||
Failure = Err.Source
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure = "QuickPartReplace.Session", "failed OpenProject accepted"
|
||||
Require FakeApp.Documents.OpenCount = 0, "opened sheets after failure"
|
||||
''')
|
||||
|
||||
|
||||
def test_confirmed_job_selects_project_before_launch(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
QP_ExpectedJobId = "job-two"
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "command.tsv"), _
|
||||
"job_id" & vbTab & "project_path" & vbCrLf & _
|
||||
"job-one" & vbTab & "C:\\wrong.prj" & vbCrLf & _
|
||||
"job-two" & vbTab & Target & vbCrLf
|
||||
Require QPConfirmedProjectPath() = Target, "picked first row instead of confirmed job"
|
||||
ReadyAfter = 999
|
||||
QPBootstrapSession
|
||||
Require QP_App Is FakeApp, "bootstrap did not attach returned application"
|
||||
Require FakeApp.ProjectPath = Target, "bootstrap opened wrong target"
|
||||
Require QP_Stage = "session_ready", "bootstrap did not finish"
|
||||
Require LaunchCalls = 1, "bootstrap launch count"
|
||||
''')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('rows', ['missing', 'duplicate', 'missing_file'])
|
||||
def test_invalid_confirmed_job_never_launches_designer(tmp_path, rows):
|
||||
expression = {
|
||||
'missing': '"other" & vbTab & Target & vbCrLf',
|
||||
'duplicate': '"job" & vbTab & Target & vbCrLf & "job" & vbTab & Target & vbCrLf',
|
||||
'missing_file': '"job" & vbTab & Target & ".missing" & vbCrLf',
|
||||
}[rows]
|
||||
run_session(tmp_path, f'''
|
||||
QP_ExpectedJobId = "job"
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "command.tsv"), _
|
||||
"job_id" & vbTab & "project_path" & vbCrLf & {expression}
|
||||
On Error Resume Next
|
||||
QPBootstrapSession
|
||||
Dim Failure
|
||||
Failure = Err.Source
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure = "QuickPartReplace.Session", "bad confirmed job accepted"
|
||||
Require AttachCalls = 0, "attached before command validation"
|
||||
Require LaunchCalls = 0, "launched before command validation"
|
||||
''')
|
||||
|
||||
|
||||
def test_real_worker_rejects_missing_project_without_touching_com(tmp_path):
|
||||
(tmp_path / 'command.tsv').write_text('job_id\tproject_path\njob\tC:\\nonexistent-startup-test\\missing.prj\n', encoding='utf-8')
|
||||
status = tmp_path / 'status.tsv'
|
||||
status.write_text('job_id\tstate\tcode\tmessage\n', encoding='utf-8')
|
||||
before = status.read_bytes()
|
||||
result = subprocess.run(['C:\\Windows\\SysWOW64\\cscript.exe', '//nologo', str(SOURCE), str(tmp_path), '', '', 'job'],
|
||||
capture_output=True, timeout=15, creationflags=subprocess.CREATE_NO_WINDOW)
|
||||
assert result.returncode == 2
|
||||
assert b'confirmed project file does not exist' in result.stderr
|
||||
assert status.read_bytes() == before
|
||||
assert 'stage=session_startup' in (tmp_path / 'quick-part-replace.log').read_text(encoding='utf-8-sig')
|
||||
assert not list(tmp_path.glob('snapshot-*'))
|
||||
|
||||
|
||||
def test_opened_wrong_sheet_is_rejected(tmp_path):
|
||||
run_session(tmp_path, '''
|
||||
FakeApp.ActualSheet = "2"
|
||||
On Error Resume Next
|
||||
QPEnsureProject FakeApp, Target
|
||||
Dim Failure
|
||||
Failure = Err.Description
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Failure = "active sheet does not match the requested sheet", "wrong sheet was accepted"
|
||||
''')
|
||||
|
||||
|
||||
def test_sheet_identity_uses_members_from_installed_type_library():
|
||||
api = SOURCE.parents[2] / 'build/DxPartReplace-generated/viewdraw_api.py'
|
||||
if not api.is_file():
|
||||
pytest.skip('Local 7.9.5 generated type library is not available')
|
||||
classes = {node.name: node for node in ast.parse(api.read_text(encoding='utf-8-sig')).body if isinstance(node, ast.ClassDef)}
|
||||
|
||||
def properties(class_name):
|
||||
definition = next(node.value for node in classes[class_name].body if isinstance(node, ast.Assign)
|
||||
and any(isinstance(target, ast.Name) and target.id == '_prop_map_get_' for target in node.targets))
|
||||
return {key.value for key in definition.keys if isinstance(key, ast.Constant)}
|
||||
|
||||
assert 'Block' in properties('IVdView')
|
||||
assert 'SheetNumber' not in properties('IVdView')
|
||||
assert 'SheetNum' in properties('IVdBlock')
|
||||
source = SOURCE.read_text(encoding='ascii')
|
||||
assert 'View.SheetNumber' not in source
|
||||
assert 'CStr(View.Block.SheetNum) <> OnlySheet' in source
|
||||
Reference in new issue
Block a user