def test_is_multiple_should_returns_false_if_gif_has_many_frames(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'animated-one-frame.gif'), 'r') as im: buffer = im.read() engine.load(buffer, '.gif') expect(engine.is_multiple()).to_be_false()
def test_is_multiple_should_returns_true_if_gif_has_many_frames(self): engine = Engine(self.context) with open(join(STORAGE_PATH, "animated.gif"), "rb") as image_file: buffer = image_file.read() engine.load(buffer, ".gif") expect(engine.is_multiple()).to_be_true()
def test_is_multiple_should_returns_true_if_gif_has_many_frames(self): engine = Engine(self.context) with open(join(STORAGE_PATH, "animated.gif"), "r") as im: buffer = im.read() engine.load(buffer, ".gif") expect(engine.is_multiple()).to_be_true()
def validate(self, body): conf = self.context.config mime = BaseEngine.get_mimetype(body) if mime == '.gif' and self.context.config.USE_GIFSICLE_ENGINE: engine = GifEngine(self.context) else: engine = self.context.modules.engine # Check if image is valid try: engine.load(body, None) except IOError: self._error(415, 'Unsupported Media Type') return False # Check weight constraints if (conf.UPLOAD_MAX_SIZE != 0 and len(self.request.body) > conf.UPLOAD_MAX_SIZE): self._error( 412, 'Image exceed max weight (Expected : %s, Actual : %s)' % (conf.UPLOAD_MAX_SIZE, len(self.request.body))) return False # Check size constraints size = engine.size if (conf.MIN_WIDTH > size[0] or conf.MIN_HEIGHT > size[1]): self._error( 412, 'Image is too small (Expected: %s/%s , Actual : %s/%s) % (conf.MIN_WIDTH, conf.MIN_HEIGHT, size[0], size[1])') return False return True
def test_errors_on_gifsicle_should_not_raises_errors_when_output(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'SmallFullColourGIF.gif'), 'rb') as im: buffer = im.read() engine.load(buffer, '.gif') result = engine.run_gifsicle('--some-invalid-opt') expect(result).Not.to_be_null()
def test_errors_on_gifsicle_should_not_raises_errors_when_output(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'SmallFullColourGIF.gif'), 'r') as im: buffer = im.read() engine.load(buffer, '.gif') result = engine.run_gifsicle('--some-invalid-opt') expect(result).Not.to_be_null()
def test_errors_on_gifsicle_should_not_raises_errors_when_output(self): engine = Engine(self.context) with open(join(STORAGE_PATH, "SmallFullColourGIF.gif"), "rb") as image_file: buffer = image_file.read() engine.load(buffer, ".gif") result = engine.run_gifsicle("--some-invalid-opt") expect(result).Not.to_be_null()
def test_errors_on_gifsicle_should_raises_errors(self): engine = Engine(self.context) with open(join(STORAGE_PATH, "animated.gif"), "r") as im: buffer = im.read() engine.load(buffer, ".gif") with expect.error_to_happen( GifSicleError, message="gifsicle command returned errorlevel 1 for command" ' "{0} --some-invalid-opt /foo/' 'bar.gif" (image maybe corrupted?)'.format(self.server.gifsicle_path), ): engine.run_gifsicle("--some-invalid-opt")
def test_convert_to_grayscale_should_update_image(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'animated.gif'), 'rb') as im: buffer = im.read() engine.load(buffer, '.gif') buffer = engine.read() engine.convert_to_grayscale() expect(buffer).not_to_equal(engine.read())
def test_convert_to_grayscale_should_update_image(self): engine = Engine(self.context) with open(join(STORAGE_PATH, "animated.gif"), "rb") as image_file: buffer = image_file.read() engine.load(buffer, ".gif") buffer = engine.read() engine.convert_to_grayscale() expect(buffer).not_to_equal(engine.read())
def topic(self): config = Config() server = ServerParameters( 8889, 'localhost', 'thumbor.conf', None, 'info', None ) context = Context(server, config, Importer(config)) context.server.gifsicle_path = which('gifsicle') context.request = RequestParameters() with open("%s/animated_image.gif" % FIXTURES_FOLDER, "rb") as f: buffer = f.read() engine = GifEngine(context=context) engine.load(buffer, '.gif') return engine.read()
def test_convert_to_grayscale_should_update_image(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'animated.gif'), 'r') as im: buffer = im.read() engine.load(buffer, '.gif') buffer = engine.read() engine.convert_to_grayscale() expect(buffer).not_to_equal(engine.read())
def test_errors_on_gifsicle_should_raises_errors(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'animated.gif'), 'r') as im: buffer = im.read() engine.load(buffer, '.gif') with expect.error_to_happen( GifSicleError, message='gifsicle command returned errorlevel 1 for command' ' "{0} --some-invalid-opt /foo/' 'bar.gif" (image maybe corrupted?)'.format( self.server.gifsicle_path)): engine.run_gifsicle('--some-invalid-opt')
def test_load_image(self): engine = Engine(self.context) with open(join(STORAGE_PATH, "animated.gif"), "rb") as image_file: buffer = image_file.read() image = engine.create_image(buffer) expect(image.format).to_equal("GIF")
def test_load_image(self): engine = Engine(self.context) with open(join(STORAGE_PATH, 'animated.gif'), 'r') as im: buffer = im.read() image = engine.create_image(buffer) expect(image.format).to_equal('GIF')
def test_create_engine(self): engine = Engine(self.context) expect(engine).to_be_instance_of(Engine)