import copy,json,unittest
from compare import ROOT,equal,expected,effects,verify
class Counterexamples(unittest.TestCase):
 @classmethod
 def setUpClass(cls):
  p=ROOT/'private-evidence'/'C';cls.rows={x['scenario']:x for x in map(json.loads,(p/'private-wire.jsonl').read_text().splitlines())};cls.cases={c['scenario']:c for f in p.glob('cases-*.json') for c in json.loads(f.read_text())};cls.s='PILOT_GP_READ_TERMINAL_GOODS_BASIC';cls.w=cls.rows[cls.s];cls.c=cls.cases[cls.s];cls.want=expected(cls.w,cls.c)
 def test_complete_acceptance(self):self.assertEqual(verify()['HTTP'],40)
 def test_types_missing_extra_array_shape(self):
  for change in ('id_string','money_number','missing','extra','empty_object'):
   x=copy.deepcopy(self.want);g=x['detail']
   if change=='id_string':g['goods_id']=str(g['goods_id'])
   if change=='money_number':g['goods_price_min']=0
   if change=='missing':del g['skuList']
   if change=='extra':g['not_from_source']=1
   if change=='empty_object':g['skuList'][0]['goods_props']={}
   with self.assertRaises(AssertionError):equal(x,self.want,change)
 def test_ordered_array_contract(self):
  with self.assertRaises(AssertionError):equal([1,2],[2,1])
 def test_own_scope_read_write_natural(self):
  for what in ('own_user','natural','read_dml','other_printer'):
   s='PILOT_GP_EDIT_TERMINAL_PRINTER_EDIT' if what=='other_printer' else self.s;w=copy.deepcopy(self.rows[s]);c=self.cases[s]
   if what=='own_user':w['original']['user'][0]['balance']=999
   if what=='natural':w['protect_after']['printer_natural_count']=1
   if what=='read_dml':w['operations'].append('update')
   if what=='other_printer':w['original']['printer'][0]['sort']=999
   with self.assertRaises(AssertionError):effects(w,c)
if __name__=='__main__':unittest.main()
