perf(execution): reuse component UID within each snapshot read

This commit is contained in:
阿白叔 committed 2026-10-19 10:36:06 +08:00
1 parent 13b9ff48dd
commit 5b625b076e
2 files changed
+75 -13

No files matched your search

+59
View File
@@ -372,6 +372,65 @@ WScript.Echo CStr(CBool(InStr(Text,"net1|GND")>0))
assert output.splitlines() == ['2', 'True']
@pytest.mark.parametrize(('reader', 'pin_count', 'expected_reads'), [
('QPUntouchedFullState', 0, 1),
('QPUntouchedFullState', 2, 5),
('QPSnapshotComponent', 2, 5),
('QPConnectionSignature', 2, 5),
])
def test_component_capture_reads_its_uid_once_and_keeps_live_pin_owner_checks(
tmp_path, reader, pin_count, expected_reads):
fake = FULL_FAKE.replace('Public UID, Refdes, X, Y, Orientation, Scale, Attributes, Selected, RaiseOnFind',
'Private StoredUid\n Public UidReads\n Public Refdes, X, Y, Orientation, Scale, Attributes, Selected, RaiseOnFind')
fake = fake.replace(' Function FindAttribute(ByVal Name)\n', '''
Public Property Let UID(ByVal Value)
StoredUid=Value
End Property
Public Property Get UID
UidReads=UidReads+1
UID=StoredUid
End Property
Function FindAttribute(ByVal Name)
''', 1)
output = run_vbs(tmp_path, UNTOUCHED_ROUTINES + ['QPSnapshotComponent'], '''
Dim Comp, Attr, Pin, Text, Item
Set QP_App=New FakeApp
Set Comp=New FullComponent: Comp.UID="u2": Comp.Refdes="R2"
For Item=1 To 6
Set Attr=New FullAttribute: Attr.Name="Field" & CStr(Item)
Comp.Attributes.Add Attr,True
Next
For Item=1 To ''' + str(pin_count) + '''
Set Pin=New FakePin: Set Pin.Component=Comp
Pin.Number=CStr(Item): Pin.X=Item: Pin.Y=0: Set Pin.Connection=Nothing
QP_App.ActiveView.Pins.Add Pin,True
Next
Comp.UidReads=0
Text=''' + reader + '''(Comp)
WScript.Echo Comp.UidReads
WScript.Echo CStr(Len(Text)>0)
''', LOG_STUB + fake)
assert output.splitlines() == [str(expected_reads), 'True']
def test_pin_owner_is_rechecked_when_reusing_the_index(tmp_path):
output = run_vbs(tmp_path, UNTOUCHED_ROUTINES, '''
Dim Comp, Other, Pin, Text
Set QP_App=New FakeApp
Set Comp=New FullComponent: Comp.UID="u2": Comp.Refdes="R2"
Set Other=New FullComponent: Other.UID="other": Other.Refdes="R3"
Set Pin=New FakePin: Set Pin.Component=Comp
Pin.Number="1": Pin.X=10: Pin.Y=0: Set Pin.Connection=Nothing
QP_App.ActiveView.Pins.Add Pin,True
Text=QPConnectionSignature(Comp)
Set Pin.Component=Other
On Error Resume Next
Text=QPConnectionSignature(Comp)
WScript.Echo CStr(Err.Number=vbObjectError+819)
''', LOG_STUB + FULL_FAKE)
assert output == 'True'
@pytest.mark.parametrize(('mutation', 'expected'), [
('Comp.X = 20', 'True'), ('Comp.Orientation = 90', 'True'),
('Comp.Scale = 2', 'True'), ('Attr.Color = 99', 'True'),