def test_locate_returns_None_if_no_internal_templates_found_in_scene(self): # setup a template and scene that should be guaranteed not to be matched black_template = _generic_image(height=5, width=10) black_template.fill(0) white_scene = _generic_image(height=20, width=20) white_scene.fill(255) tf = TemplateFinder(black_template) p = tf.locate_in(white_scene) self.assertIsNone(p)
def test_locate_returns_result_immediately_when_immediate_passes(self): top_spec, left_spec, bottom_spec, right_spec = 2, 3, 22, 33 height_spec = bottom_spec - top_spec width_spec = right_spec - left_spec black_template = _generic_image(height=height_spec, width=width_spec) black_template.fill(0) white_scene = _generic_image(height=height_spec * 3, width=width_spec * 3) white_scene.fill(255) # set a black square to match the template white_scene[top_spec:bottom_spec, left_spec:right_spec] = 0 # setup thresholds to exercise the spec impossible = -1 always = 2 tf = TemplateFinder(black_template, acceptable_threshold=impossible, immediate_threshold=always) # confirm the result borders = tf.locate_in(white_scene) self.assertEqual(borders, (top_spec, left_spec, bottom_spec, right_spec))