def load_module(self, module_name): if _debug(): print "SikuliLoader.load_module", module_name, self.path module_name = _stripPackagePrefix(module_name) p = ImageLocator.addImagePath(self.path) if not p: return None Sikuli.addModPath(p) return self._load_module(module_name)
def assertThat(self, text): self.validate() self.logger.info("Asserting [%s]" % text) baselinePath = self.config.imageBaseline + "/assert/" + str(Env.getOS()).lower() + "/" + text + ".png" baseline = Pattern(baselinePath) # TODO: Refactor to allow for using RegionFinder class so PNG attributes can be used try: ImageLocator().locate( baselinePath ) result = self.region.find(baseline) self.logger.info('%%s matched %%s', self.logger.getFormatter()(result), self.logger.getFormatter()(baseline)) except FindFailed, e: self.logger.error('%%s does not match %%s', self.logger.getFormatter()(self.region), self.logger.getFormatter()(baseline)) raise Exception("Assertion failure")
def getBundlePath(): return ImageLocator.getBundlePath()
def setBundlePath(path): ImageLocator.setBundlePath(path)
def resetImagePath(path): ImageLocator.resetImagePath(path)
def removeImagePath(path): ImageLocator.removeImagePath(path)
def getImagePath(): return [e for e in ImageLocator.getImagePath() if e]
def addImagePath(path): ImageLocator.addImagePath(path)
def findBaselines(self): # If this is set we've already found stuff if self.collectionType: return for filename, nameType in ( \ (self.entity.getCanonicalName(ancestorEntities=False, topLevel=False) + '/' + self.entity.getCanonicalName(),self.NAME_TYPE_FULL), \ (self.entity.getCanonicalName(ancestorEntities=False, topLevel=False) + '/' + self.entity.getCanonicalName(ancestorEntities=1), self.NAME_TYPE_GENERIC), \ (self.entity.getCanonicalName(ancestorEntities=False, topLevel=False) + '/' + self.entity.getClassName() + self.entity.getCanonicalName(rootEntity=False, ancestorEntities=False), self.NAME_TYPE_CLASS_ENTITY), \ (self.entity.getCanonicalName(ancestorEntities=False, topLevel=False) + '/' + self.entity.getClassName(), self.NAME_TYPE_CLASS), \ (self.entity.getClassName() + self.entity.getCanonicalName(rootEntity=False, ancestorEntities=False), self.NAME_TYPE_CLASS_ENTITY), \ (self.entity.getClassName(), self.NAME_TYPE_CLASS) ): # single try: self.path = ImageLocator().locate( filename + self.state + self.config.imageSuffix )[:-4] + ".png" # get full path, minus .png extension except: pass # file doesn't exist else: self.filename = filename self.nameType = nameType self.collectionType = self.COL_TYPE_SINGLE self.seriesRange = [ 0, ] self.__logFound() return # sequence try: self.path = ImageLocator().locate( filename + '-0' + self.state + self.config.imageSuffix )[:-4] + ".png" # get full path, minus .png extension except: pass # file doesn't exist else: self.filename = filename self.nameType = nameType self.collectionType = self.COL_TYPE_SEQUENCE self.seriesRange = [ 0, ] self.__logFound() return # series seq = 0 while True: try: self.path = ImageLocator().locate( filename + '[' + str(seq) + ']' + self.state + self.config.imageSuffix )[:-4] + ".png" # get full path, minus .png extension except: break # end of series else: seq += 1 if seq > 0: self.filename = filename self.nameType = nameType self.collectionType = self.COL_TYPE_SERIES self.seriesRange = range(0, seq) self.__logFound() return # sequence + series seq = 0 while True: try: self.path = ImageLocator().locate( filename + '[' + str(seq) + ']-0' + self.state + self.config.imageSuffix )[:-4] + ".png" # get full path, minus .png extension except: break # end of sequence else: seq += 1 if seq > 0: self.filename = filename self.nameType = nameType self.collectionType = self.COL_TYPE_SERIES_SEQUENCE self.seriesRange = range(0, seq) self.__logFound() return self.logger.trace( "failed to find image on disk [\"%s%s\"] nameType=%s" % (filename, self.state, nameType)) raise ImageMissingException( "cannot find image on disk [\"%s%s\"]" % (filename, self.state) ) # if we don't have single image or sequence, file cannot be found