"""Synthetic image regressions: touching feet/tail must never buy a 3D job."""
import unittest,tempfile
from pathlib import Path
from PIL import Image,ImageDraw
from reference_gate import check
class ReferenceGate(unittest.TestCase):
 def image(self,root,problem=None):
  im=Image.new('RGB',(512,512),'white');d=ImageDraw.Draw(im)
  d.rectangle((100,160,345,250),fill='#555555');d.ellipse((55,125,145,225),fill='#555555')
  for x in (120,180,270,330):d.rectangle((x,250,x+20,400),fill='#555555')
  d.rectangle((340,170,470,193),fill='#555555')
  if problem=='feet':d.rectangle((130,290,190,400),fill='#555555')
  if problem=='tail':d.rectangle((360,190,440,400),fill='#555555')
  if problem=='cropped':d.rectangle((465,170,511,193),fill='#555555')
  if problem=='background':im=Image.new('RGB',(512,512),'black')
  path=root/'input.png';im.save(path);return check(path,root)
 def test_separate(self):
  with tempfile.TemporaryDirectory() as t:self.assertTrue(self.image(Path(t))['pass'])
 def test_reject(self):
  for p in ['feet','tail','cropped','background']:
   with self.subTest(problem=p),tempfile.TemporaryDirectory() as t:self.assertFalse(self.image(Path(t),p)['pass'])
if __name__=='__main__':unittest.main()
