Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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]
Exemplo n.º 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]
Exemplo n.º 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']
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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))
Exemplo n.º 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()
Exemplo n.º 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))
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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))
Exemplo n.º 31
0
        def should_crop_properly(self, topic):
            context = topic.to_context()
            trans = Transformer(context)
            trans.transform()

            expect(topic).to_be_cropped()
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 35
0
 def topic(self, callback, topic):
     self.test_data = topic
     context = topic.to_context(detectors=[MockSyncDetector])
     trans = Transformer(context)
     trans.transform(callback)
Exemplo n.º 36
0
    def _get_engine(self, topic):
        context = topic[0].to_context()
        trans = Transformer(context)
        trans.transform()

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