def pattern_open(self, image): if isinstance(image, Pattern): return image elif isinstance(image, basestring): image_path = base.search_image(image, self.image_path) if image_path is None: raise IOError('image file not found: {}'.format(image)) return Pattern(image_path) elif 'numpy' in str(type(image)): return Pattern(image) else: raise TypeError("Not supported image type: {}".format(type(image)))
def pattern_open(self, image): if self.__screensize is None: self.__screensize = self.display if isinstance(image, Pattern): if image._image is None: image_path = self._search_image(image._name) image._image = imutils.open(image_path) return image elif isinstance(image, basestring): image_path = base.search_image(image, self.image_path) if image_path is None: raise IOError('image file not found: {}'.format(image)) return Pattern(image_path, image=imutils.open(image_path)) elif 'numpy' in str(type(image)): return Pattern('unknown', image=image) else: raise TypeError("Not supported image type: {}".format(type(image)))
def _search_image(self, name, raise_error=True): image_path = base.search_image(name, self.image_path) if raise_error and image_path is None: raise IOError('image file not found: {}'.format(name)) return image_path
def test_search_image(): imgpath = base.search_image('haima', path=['media']) assert imgpath is not None assert 'haima.png' in imgpath assert 'media' in imgpath
def test_search_image(): imgpath = base.search_image('haima', path=['media']) assert imgpath is not None assert strutils.encode('haima.png') in imgpath assert strutils.encode('media') in imgpath