예제 #1
0
    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)
예제 #2
0
    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()
예제 #3
0
    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)
예제 #4
0
    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))
예제 #5
0
    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))
예제 #6
0
 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)
예제 #7
0
 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))
예제 #8
0
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]
예제 #9
0
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]
예제 #10
0
        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']
예제 #11
0
    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)
예제 #12
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)
예제 #13
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)
예제 #14
0
    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)
예제 #15
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()
예제 #16
0
    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))
예제 #17
0
 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()
예제 #18
0
    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))
예제 #19
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(lambda: None)
        expect(engine.calls['crop']).to_be_empty()
예제 #20
0
    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()
예제 #21
0
    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)
예제 #22
0
    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()
예제 #23
0
    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()
예제 #24
0
    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)
예제 #25
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(lambda: None)
        expect(engine.calls['crop']).to_be_empty()
예제 #26
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()
            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)
예제 #27
0
    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)
예제 #28
0
    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)
예제 #29
0
 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()
예제 #30
0
 def test_can_resize_images(self):
     for item in TESTITEMS:
         context = item.to_context()
         trans = Transformer(context)
         trans.transform(self.validate_resize(item))
예제 #31
0
        def should_crop_properly(self, topic):
            context = topic.to_context()
            trans = Transformer(context)
            trans.transform()

            expect(topic).to_be_cropped()
예제 #32
0
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
예제 #33
0
 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)
예제 #34
0
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
예제 #35
0
 def topic(self, callback, topic):
     self.test_data = topic
     context = topic.to_context(detectors=[MockSyncDetector])
     trans = Transformer(context)
     trans.transform(callback)
예제 #36
0
    def _get_engine(self, topic):
        context = topic[0].to_context()
        trans = Transformer(context)
        trans.transform()

        return context['engine']
예제 #37
0
 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)
예제 #38
0
 def topic(self, callback, topic):
     self.test_data = topic
     context = topic.to_context()
     trans = Transformer(context)
     trans.transform(callback)
예제 #39
0
 def topic(self, callback, topic):
     self.test_data = topic
     context = topic.to_context()
     trans = Transformer(context)
     trans.transform(callback)
예제 #40
0
 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))