def _prepare_engine(self, topic, callback): context = topic[0].to_context() self.engine = context.modules.engine self.test_data = topic trans = Transformer(context) trans.transform(callback)
def test_can_extract_cover(self): data = TestData(source_width=800, source_height=600, target_width=-800, target_height=-600, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None) ctx = data.to_context() ctx.request.filters = 'cover()' ctx.request.image = 'some.gif' ctx.request.extension = 'GIF' ctx.request.engine.extension = '.gif' ctx.config.USE_GIFSICLE_ENGINE = True engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(self.handle_extract_cover(engine)) expect(self.has_handled).to_be_true()
def test_can_fit_in(self): for item in FIT_IN_CROP_DATA: context = item[0].to_context() engine = context.modules.engine trans = Transformer(context) trans.transform(self.validate_fit_in(item, context, engine, trans))
def topic(self, callback): self.test_data = TestData( source_width=800, source_height=600, target_width=400, target_height=150, halign="center", valign="middle", focal_points=[], crop_left=0, crop_top=75, crop_right=800, crop_bottom=375 ) context = self.test_data.to_context(detectors=[MockErrorSyncDetector], ignore_detector_error=False) trans = Transformer(context) trans.transform(callback)
def test_can_resize_images_with_detection_error(self): test_data = TestData( source_width=800, source_height=600, target_width=400, target_height=150, halign="center", valign="middle", focal_points=[], crop_left=0, crop_top=75, crop_right=800, crop_bottom=375 ) context = test_data.to_context(detectors=[MockErrorSyncDetector], ignore_detector_error=True) trans = Transformer(context) trans.transform(self.validate_resize(test_data))
def assert_fit_in_resize(data): data, expectations = data trans = Transformer(data.to_context()) trans.transform() assert not data.engine.calls['crop'] assert data.engine.calls['resize'] assert len(data.engine.calls['resize']) == 1 assert data.engine.calls['resize'][0]['width'] == expectations[0] assert data.engine.calls['resize'][0]['height'] == expectations[1]
def topic(self): data = TestData( source_width=800, source_height=600, target_width=-800, target_height=-600, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None ) ctx = data.to_context() trans = Transformer(ctx) trans.transform() return ctx['engine']
def test_can_resize_images_with_detection_error_not_ignoring_it(self): test_data = TestData( source_width=800, source_height=600, target_width=400, target_height=150, halign="center", valign="middle", focal_points=[], crop_left=0, crop_top=75, crop_right=800, crop_bottom=375 ) context = test_data.to_context(detectors=[MockErrorSyncDetector], ignore_detector_error=False) trans = Transformer(context) with expect.error_to_happen(Exception, message='x'): trans.transform(None) expect(test_data.engine.calls['resize']).to_length(0)
def topic(self, callback): data = TestData( source_width=800, source_height=600, target_width=-800, target_height=-600, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None ) ctx = data.to_context() self.engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(callback)
def test_can_resize_images_with_detection_error_not_ignoring_it(self): test_data = TestData( source_width=800, source_height=600, target_width=400, target_height=150, halign="center", valign="middle", focal_points=[], crop_left=0, crop_top=75, crop_right=800, crop_bottom=375 ) context = test_data.to_context(detectors=[MockErrorSyncDetector], ignore_detector_error=False) trans = Transformer(context) trans.transform(lambda: None) expect(test_data.engine.calls['resize']).to_length(0)
def test_invalid_crop(self): data = TestData( source_width=800, source_height=600, target_width=800, target_height=600, halign="right", valign="top", focal_points=[], crop_left=200, crop_top=0, crop_right=100, crop_bottom=100 ) ctx = data.to_context() engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(self.handle_invalid_crop(engine)) expect(self.has_handled).to_be_true()
def test_get_target_dimensions(self): data = TestData( source_width=800, source_height=600, target_width=600, target_height=400, halign="right", valign="top", focal_points=[], crop_left=200, crop_top=0, crop_right=100, crop_bottom=100 ) ctx = data.to_context() trans = Transformer(ctx) dimensions = trans.get_target_dimensions() expect(dimensions).to_equal((600, 400)) trans.transform(lambda: 1) expect(dimensions).to_equal((600, 400))
def test_can_resize_with_stretch(): data = TestData( source_width=800, source_height=600, target_width=800, target_height=200, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None, stretch=True ) ctx = data.to_context() engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['resize']).to_equal([{'width': 800, 'height': 200}]) expect(engine.calls['crop']).to_be_empty()
def test_invalid_crop(self): data = TestData( source_width=800, source_height=600, target_width=800, target_height=600, halign="right", valign="top", focal_points=[], crop_left=200, crop_top=0, crop_right=100, crop_bottom=100 ) ctx = data.to_context() engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['crop']).to_be_empty()
def test_can_fit_in(self): for (test_data, (width, height, should_resize)) in FIT_IN_CROP_DATA: context = test_data.to_context() engine = context.modules.engine trans = Transformer(context) trans.transform(lambda: None) expect(engine.calls['crop']).to_be_empty() if should_resize: expect(engine.calls['resize']).to_length(1) expect(engine.calls['resize'][0]['width']).to_equal(width) expect(engine.calls['resize'][0]['height']).to_equal(height) else: expect(engine.calls['resize']).to_be_empty()
def test_can_transform_with_flip(self): data = TestData( source_width=800, source_height=600, target_width=-800, target_height=-600, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None ) ctx = data.to_context() engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['horizontal_flip']).to_equal(1) expect(engine.calls['vertical_flip']).to_equal(1)
def test_can_transform_meta_with_orientation(self): data = TestData( source_width=800, source_height=600, target_width=100, target_height=100, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None, meta=True ) ctx = data.to_context() ctx.config.RESPECT_ORIENTATION = True engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(self.handle_transform_with_meta(engine)) expect(self.has_handled).to_be_true()
def test_can_transform_meta_with_orientation(self): data = TestData( source_width=800, source_height=600, target_width=100, target_height=100, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None, meta=True ) ctx = data.to_context() ctx.config.RESPECT_ORIENTATION = True engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['reorientate']).to_equal(1)
def test_invalid_crop(self): data = TestData(source_width=800, source_height=600, target_width=800, target_height=600, halign="right", valign="top", focal_points=[], crop_left=200, crop_top=0, crop_right=100, crop_bottom=100) ctx = data.to_context() engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['crop']).to_be_empty()
def topic(self, callback): data = TestData( source_width=800, source_height=600, target_width=-800, target_height=-600, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None ) ctx = data.to_context() ctx.request.filters = 'cover()' ctx.request.image = 'some.gif' ctx.request.extension= 'GIF' ctx.request.engine.extension = '.gif' ctx.config.USE_GIFSICLE_ENGINE = True self.engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(callback)
def test_can_transform_with_flip(self): data = TestData(source_width=800, source_height=600, target_width=-800, target_height=-600, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None) ctx = data.to_context() engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['horizontal_flip']).to_equal(1) expect(engine.calls['vertical_flip']).to_equal(1)
def test_can_extract_cover(self): data = TestData( source_width=800, source_height=600, target_width=-800, target_height=-600, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None ) ctx = data.to_context() ctx.request.filters = 'cover()' ctx.request.image = 'some.gif' ctx.request.extension = 'GIF' ctx.request.engine.extension = '.gif' ctx.config.USE_GIFSICLE_ENGINE = True engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['cover']).to_equal(1)
def test_can_resize_with_stretch(): data = TestData(source_width=800, source_height=600, target_width=800, target_height=200, halign="right", valign="top", focal_points=[], crop_left=None, crop_top=None, crop_right=None, crop_bottom=None, stretch=True) ctx = data.to_context() engine = ctx.modules.engine trans = Transformer(ctx) trans.transform(lambda: None) expect(engine.calls['resize']).to_equal([{ 'width': 800, 'height': 200 }]) expect(engine.calls['crop']).to_be_empty()
def test_can_resize_images(self): for item in TESTITEMS: context = item.to_context() trans = Transformer(context) trans.transform(self.validate_resize(item))
def should_crop_properly(self, topic): context = topic.to_context() trans = Transformer(context) trans.transform() expect(topic).to_be_cropped()
def assert_proper_operations(data): trans = Transformer(data.to_context()) trans.transform() assert data.has_cropped_properly(), data.crop_error_message assert data.has_resized_properly(), data.resize_error_message
def test_can_resize_images(self): for item in TESTITEMS: context = item.to_context() trans = Transformer(context) trans.transform(lambda: None) self.validate_resize(item)
def topic(self, callback, topic): self.test_data = topic context = topic.to_context(detectors=[MockSyncDetector]) trans = Transformer(context) trans.transform(callback)
def _get_engine(self, topic): context = topic[0].to_context() trans = Transformer(context) trans.transform() return context['engine']
def test_can_resize_images_with_detectors(self): for item in TESTITEMS: context = item.to_context(detectors=[MockSyncDetector]) trans = Transformer(context) trans.transform(lambda: None) self.validate_resize(item)
def topic(self, callback, topic): self.test_data = topic context = topic.to_context() trans = Transformer(context) trans.transform(callback)
def test_can_resize_images_with_detectors(self): for item in TESTITEMS: context = item.to_context(detectors=[MockSyncDetector]) trans = Transformer(context) trans.transform(self.validate_resize(item))