feat: classify verification checks with explicit evidence and coverage
This commit is contained in:
1 parent
4da211d5d2
commit
de486a9c6b
3 files changed
+241
-5
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import copy
|
||||
import pytest
|
||||
from dx_productivity.trial_task_center.verification.contracts import default_plan
|
||||
|
||||
|
||||
def export():
|
||||
components={}
|
||||
for uid,ref,pins in [('a','R12',{'loop':('1',['LOOP']),'GND':('2',['GND'])}),
|
||||
('b','U1',{'out':('3',['LOOP'])}),('c','C5',{'gnd':('2',['GND'])})]:
|
||||
components[uid]={'refdes':ref,'attributes':{'Ref Designator':ref,'Part Number':'OLD','Value':'10K'},
|
||||
'pins':{k:{'number':num,'nets':nets} for k,(num,nets) in pins.items()}}
|
||||
return {'status':'success','complete':True,'graph':{'components':components,'nets':[
|
||||
{'name':'LOOP','endpoints':[['a','loop'],['b','out']]},{'name':'GND','endpoints':[['a','GND'],['c','gnd']]}]}}
|
||||
|
||||
|
||||
def evaluate(left,right,**kwargs):
|
||||
from dx_productivity.trial_task_center.verification.rules import evaluate
|
||||
return evaluate(left,right,expectations=kwargs.pop('expectations',None),check_plan=kwargs.pop('check_plan',default_plan()),**kwargs)
|
||||
|
||||
|
||||
def test_equal_graph_and_uid_change_preserve_refdes_identity():
|
||||
a=export();b=copy.deepcopy(a)
|
||||
b['graph']['components']['new']=b['graph']['components'].pop('a')
|
||||
for net in b['graph']['nets']:
|
||||
for endpoint in net['endpoints']:
|
||||
if endpoint[0]=='a':endpoint[0]='new'
|
||||
assert evaluate(a,b)['verdict']=='CONSISTENT'
|
||||
|
||||
|
||||
def test_swap_physical_pin_connections_is_hard_error():
|
||||
a=export();b=copy.deepcopy(a)
|
||||
b['graph']['components']['a']['pins']['loop']['number']='2'
|
||||
b['graph']['components']['a']['pins']['GND']['number']='1'
|
||||
result=evaluate(a,b)
|
||||
assert result['verdict']=='DIFFERENT'
|
||||
assert any(i['check_id']=='connections' and i.get('pin_number')=='1' for i in result['issues'])
|
||||
|
||||
|
||||
def test_pin_rename_is_warning_without_connection_error():
|
||||
a=export();b=copy.deepcopy(a)
|
||||
b['graph']['components']['a']['pins']['outloop']=b['graph']['components']['a']['pins'].pop('loop')
|
||||
b['graph']['nets'][0]['endpoints'][0][1]='outloop'
|
||||
result=evaluate(a,b)
|
||||
assert result['verdict']=='WARNING'
|
||||
assert any(i['check_id']=='pin_text' for i in result['issues'])
|
||||
assert not any(i['check_id']=='connections' for i in result['issues'])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('change',['disconnect','short','refdes','number','netname'])
|
||||
def test_structural_changes_are_errors(change):
|
||||
a=export();b=copy.deepcopy(a)
|
||||
if change=='disconnect':
|
||||
b['graph']['nets'][0]['endpoints'].pop(0);b['graph']['components']['a']['pins']['loop']['nets']=[]
|
||||
if change=='short':
|
||||
b['graph']['nets'][0]['endpoints']+=b['graph']['nets'][1]['endpoints'];b['graph']['nets'].pop()
|
||||
for component in b['graph']['components'].values():
|
||||
for pin in component['pins'].values():pin['nets']=['LOOP']
|
||||
if change=='refdes':b['graph']['components']['a']['refdes']='R13';b['graph']['components']['a']['attributes']['Ref Designator']='R13'
|
||||
if change=='number':b['graph']['components']['a']['pins']['loop']['number']='9'
|
||||
if change=='netname':
|
||||
b['graph']['nets'][0]['name']='RENAMED'
|
||||
for uid,pin in [('a','loop'),('b','out')]:b['graph']['components'][uid]['pins'][pin]['nets']=['RENAMED']
|
||||
assert evaluate(a,b)['verdict']=='DIFFERENT'
|
||||
|
||||
|
||||
def test_declared_values_exact_and_undeclared_changes_warn():
|
||||
a=export();b=copy.deepcopy(a);b['graph']['components']['a']['attributes']['Value']='NEW'
|
||||
assert evaluate(a,b)['verdict']=='WARNING'
|
||||
assert evaluate(a,b,expectations={'changes':{'a':{'Value':'NEW'}}})['verdict']=='CONSISTENT'
|
||||
assert evaluate(a,b,expectations={'changes':{'a':{'Value':'WRONG'}}})['verdict']=='DIFFERENT'
|
||||
assert evaluate(a,b,expectations={'changes':{}})['verdict']=='DIFFERENT'
|
||||
|
||||
|
||||
def test_missing_required_mapping_never_passes_and_duplicate_ref_is_unknown():
|
||||
a=export();plan=default_plan();plan['excluded_checks']=[];plan['required_checks'].append('footprint_mapping')
|
||||
assert evaluate(a,a,check_plan=plan)['verdict']=='INCOMPLETE'
|
||||
b=copy.deepcopy(a);b['graph']['components']['c']['refdes']='R12'
|
||||
assert evaluate(a,b)['verdict']=='INCOMPLETE'
|
||||
|
||||
|
||||
def test_missing_pin_number_cannot_prove_equal_and_error_beats_unknown():
|
||||
a=export();b=copy.deepcopy(a);b['graph']['components']['a']['pins']['loop']['number']=''
|
||||
assert evaluate(a,b)['verdict']=='INCOMPLETE'
|
||||
b['graph']['components']['b']['attributes']['Value']='WRONG'
|
||||
result=evaluate(a,b,expectations={'changes':{}})
|
||||
assert result['verdict']=='DIFFERENT' and result['unknown_checks']
|
||||
Reference in new issue
Block a user