コード例 #1
0
 def test_undefined(self):
     settings = get_settings(IMAGE_PROCESS=self.valid_transforms)
     html = '<img class="image-process-undefined" src="/tmp/test.jpg" />'
     c = Instance(html, settings)
     del images[:]
     with self.assertRaises(RuntimeError):
         harvest_images(c)
コード例 #2
0
    def test_image_generation(self):
        settings = get_settings(IMAGE_PROCESS=self.valid_transforms,
                                IMAGE_PROCESS_DIR='derivs')
        test_data = [
            ('<img class="image-process-thumb" src="/tmp/test.jpg" />',
             '<img class="image-process-thumb" src="/tmp/derivs/thumb/test.jpg"/>',
             ('tmp/test.jpg', 'thumb/test.jpg',
              ["crop 0 0 50% 50%", "scale_out 150 150", "crop 0 0 150 150"])),
            ('<img class="image-process-article-image" src="/tmp/test.jpg" />',
             '<img class="image-process-article-image" src="/tmp/derivs/article-image/test.jpg"/>',
             ('tmp/test.jpg', 'article-image/test.jpg', ["scale_in 300 300"]))
        ]

        for data in test_data:
            expected_source = os.path.join(settings['PATH'], data[2][0])
            output_path, _ = os.path.split(expected_source)
            base_path = os.path.join(output_path,
                                     settings['IMAGE_PROCESS_DIR'])
            expected_destination = os.path.join(base_path, data[2][1])

            c = Instance(data[0], settings)

            del images[:]
            harvest_images(c)

            expected_images = [(expected_source, expected_destination,
                                data[2][2])]

            self.assertEqual(c._content, data[1])
            self.assertEqual(images, expected_images)
コード例 #3
0
    def test_image_generation(self):
        settings = get_settings(IMAGE_PROCESS=self.valid_transforms, IMAGE_PROCESS_DIR='derivs')
        test_data = [
            ('<img class="image-process-thumb" src="/tmp/test.jpg" />',
             '<img class="image-process-thumb" src="/tmp/derivs/thumb/test.jpg"/>',
             ('tmp/test.jpg', 'thumb/test.jpg', ["crop 0 0 50% 50%", "scale_out 150 150", "crop 0 0 150 150"])
             ),
            ('<img class="image-process-article-image" src="/tmp/test.jpg" />',
             '<img class="image-process-article-image" src="/tmp/derivs/article-image/test.jpg"/>',
             ('tmp/test.jpg', 'article-image/test.jpg', ["scale_in 300 300"])
             )
           ]

        for data in test_data:
            expected_source = os.path.join(settings['PATH'], data[2][0])
            output_path, _ = os.path.split(expected_source)
            base_path = os.path.join(output_path, settings['IMAGE_PROCESS_DIR'])
            expected_destination = os.path.join(base_path, data[2][1])

            c = Instance(data[0], settings)

            del images[:]
            harvest_images(c)

            expected_images = [(expected_source, expected_destination, data[2][2])]

            self.assertEqual(c._content, data[1])
            self.assertEqual(images, expected_images)
コード例 #4
0
 def test_undefined(self):
     settings = get_settings(IMAGE_PROCESS = self.valid_transforms)
     html = '<img class="image-process-undefined" src="/tmp/test.jpg" />'
     c = Instance(html, settings)
     del images[:]
     with self.assertRaises(RuntimeError):
         harvest_images(c)
コード例 #5
0
    def test_picture_generation(self):
        settings = get_settings(IMAGE_PROCESS=self.valid_transforms,
                                IMAGE_PROCESS_DIR='derivs')
        test_data = [
            ('<picture><source class="source-1" src="/images/pelican-closeup.jpg"></source><img class="image-process-pict" src="/images/pelican.jpg"/></picture>',
             '<picture><source media="(min-width: 640px)" sizes="100vw" srcset="/images/derivs/pict/default/640w/pelican.jpg 640w, /images/derivs/pict/default/1024w/pelican.jpg 1024w, /images/derivs/pict/default/1600w/pelican.jpg 1600w"></source><source srcset="/images/derivs/pict/source-1/1x/pelican-closeup.jpg 1x, /images/derivs/pict/source-1/2x/pelican-closeup.jpg 2x"></source><img class="image-process-pict" src="/images/derivs/pict/default/640w/pelican.jpg"/></picture>',
             [('images/pelican.jpg', 'pict/default/640w/pelican.jpg',
               ["scale_in 640 480 True"]),
              ('images/pelican.jpg', 'pict/default/1024w/pelican.jpg',
               ["scale_in 1024 683 True"]),
              ('images/pelican.jpg', 'pict/default/1600w/pelican.jpg',
               ["scale_in 1600 1200 True"]),
              ('images/pelican-closeup.jpg',
               'pict/source-1/1x/pelican-closeup.jpg',
               ["crop 100 100 200 200"]),
              ('images/pelican-closeup.jpg',
               'pict/source-1/2x/pelican-closeup.jpg',
               ["crop 100 100 300 300"])]),
            ('<div class="figure"><img alt="Pelican" class="image-process-pict2" src="/images/pelican.jpg" /> <p class="caption">A nice pelican</p> <div class="legend"> <img alt="Other view of pelican" class="image-process source-2" src="/images/pelican-closeup.jpg" /> </div> </div>',
             '<div class="figure"><picture><source media="(min-width: 640px)" sizes="100vw" srcset="/images/derivs/pict2/default/640w/pelican.jpg 640w, /images/derivs/pict2/default/1024w/pelican.jpg 1024w, /images/derivs/pict2/default/1600w/pelican.jpg 1600w"></source><source srcset="/images/derivs/pict2/source-2/1x/pelican-closeup.jpg 1x, /images/derivs/pict2/source-2/2x/pelican-closeup.jpg 2x"></source><img alt="Pelican" class="image-process-pict2" src="/images/derivs/pict2/source-2/default/pelican-closeup.jpg"/></picture> <p class="caption">A nice pelican</p> <div class="legend">  </div> </div>',
             [('images/pelican.jpg', 'pict2/default/640w/pelican.jpg',
               ["scale_in 640 480 True"]),
              ('images/pelican.jpg', 'pict2/default/1024w/pelican.jpg',
               ["scale_in 1024 683 True"]),
              ('images/pelican.jpg', 'pict2/default/1600w/pelican.jpg',
               ["scale_in 1600 1200 True"]),
              ('images/pelican-closeup.jpg',
               'pict2/source-2/1x/pelican-closeup.jpg',
               ["crop 100 100 200 200"]),
              ('images/pelican-closeup.jpg',
               'pict2/source-2/2x/pelican-closeup.jpg',
               ["crop 100 100 300 300"]),
              ('images/pelican-closeup.jpg',
               'pict2/source-2/default/pelican-closeup.jpg',
               ["scale_in 800 600 True"])]),
        ]

        for data in test_data:
            c = Instance(data[0], settings)

            del images[:]
            harvest_images(c)

            expected_images = list()
            for t in data[2]:
                expected_source = os.path.join(settings['PATH'], t[0])
                output_path, _ = os.path.split(expected_source)
                base_path = os.path.join(output_path,
                                         settings['IMAGE_PROCESS_DIR'])
                expected_destination = os.path.join(base_path, t[1])
                expected_images.append(
                    (expected_source, expected_destination, t[2]))

            self.maxDiff = None
            self.assertEqual(c._content, data[1])
            for i in images:
                self.assertIn(i, expected_images)
            for i in expected_images:
                self.assertIn(i, images)
コード例 #6
0
    def test_responsive_image_generation(self):
        settings = get_settings(IMAGE_PROCESS=self.valid_transforms,
                                IMAGE_PROCESS_DIR='derivs')
        test_data = [
            ('<img class="image-process-crisp" src="/tmp/test.jpg" />',
             '<img class="image-process-crisp" src="/tmp/derivs/crisp/1x/test.jpg" srcset="/tmp/derivs/crisp/1x/test.jpg 1x, /tmp/derivs/crisp/2x/test.jpg 2x, /tmp/derivs/crisp/4x/test.jpg 4x"/>',
             [
                 ('tmp/test.jpg', 'crisp/1x/test.jpg',
                  ["scale_in 800 600 True"]),
                 ('tmp/test.jpg', 'crisp/2x/test.jpg',
                  ["scale_in 1600 1200 True"]),
                 ('tmp/test.jpg', 'crisp/4x/test.jpg',
                  ["scale_in 3200 2400 True"]),
             ]),
            ('<img class="image-process-crisp2" src="/tmp/test.jpg" />',
             '<img class="image-process-crisp2" src="/tmp/derivs/crisp2/default/test.jpg" srcset="/tmp/derivs/crisp2/1x/test.jpg 1x, /tmp/derivs/crisp2/2x/test.jpg 2x, /tmp/derivs/crisp2/4x/test.jpg 4x"/>',
             [('tmp/test.jpg', 'crisp2/1x/test.jpg', ["scale_in 800 600 True"
                                                      ]),
              ('tmp/test.jpg', 'crisp2/2x/test.jpg',
               ["scale_in 1600 1200 True"]),
              ('tmp/test.jpg', 'crisp2/4x/test.jpg',
               ["scale_in 3200 2400 True"]),
              ('tmp/test.jpg', 'crisp2/default/test.jpg',
               ["scale_in 400 300 True"])]),
            ('<img class="image-process-large-photo" src="/tmp/test.jpg" />',
             '<img class="image-process-large-photo" sizes="(min-width: 1200px) 800px, (min-width: 992px) 650px, (min-width: 768px) 718px, 100vw" src="/tmp/derivs/large-photo/800w/test.jpg" srcset="/tmp/derivs/large-photo/600w/test.jpg 600w, /tmp/derivs/large-photo/800w/test.jpg 800w, /tmp/derivs/large-photo/1600w/test.jpg 1600w"/>',
             [
                 ('tmp/test.jpg', 'large-photo/600w/test.jpg',
                  ["scale_in 600 450 True"]),
                 ('tmp/test.jpg', 'large-photo/800w/test.jpg',
                  ["scale_in 800 600 True"]),
                 ('tmp/test.jpg', 'large-photo/1600w/test.jpg',
                  ["scale_in 1600 1200 True"]),
             ]),
        ]

        for data in test_data:
            c = Instance(data[0], settings)

            del images[:]
            harvest_images(c)

            expected_images = list()
            for t in data[2]:
                expected_source = os.path.join(settings['PATH'], t[0])
                output_path, _ = os.path.split(expected_source)
                base_path = os.path.join(output_path,
                                         settings['IMAGE_PROCESS_DIR'])
                expected_destination = os.path.join(base_path, t[1])
                expected_images.append(
                    (expected_source, expected_destination, t[2]))

            self.maxDiff = None
            self.assertEqual(c._content, data[1])
            for i in images:
                self.assertIn(i, expected_images)
            for i in expected_images:
                self.assertIn(i, images)
コード例 #7
0
    def test_responsive_image_generation(self):
        settings = get_settings(IMAGE_PROCESS=self.valid_transforms, IMAGE_PROCESS_DIR='derivs')
        test_data = [
            ('<img class="image-process-crisp" src="/tmp/test.jpg" />',
             '<img class="image-process-crisp" src="/tmp/derivs/crisp/1x/test.jpg" srcset="/tmp/derivs/crisp/1x/test.jpg 1x, /tmp/derivs/crisp/2x/test.jpg 2x, /tmp/derivs/crisp/4x/test.jpg 4x"/>',
             [('tmp/test.jpg', 'crisp/1x/test.jpg', ["scale_in 800 600 True"]),
              ('tmp/test.jpg', 'crisp/2x/test.jpg', ["scale_in 1600 1200 True"]),
              ('tmp/test.jpg', 'crisp/4x/test.jpg', ["scale_in 3200 2400 True"]),
              ]),

            ('<img class="image-process-crisp2" src="/tmp/test.jpg" />',
             '<img class="image-process-crisp2" src="/tmp/derivs/crisp2/default/test.jpg" srcset="/tmp/derivs/crisp2/1x/test.jpg 1x, /tmp/derivs/crisp2/2x/test.jpg 2x, /tmp/derivs/crisp2/4x/test.jpg 4x"/>',
             [('tmp/test.jpg', 'crisp2/1x/test.jpg', ["scale_in 800 600 True"]),
              ('tmp/test.jpg', 'crisp2/2x/test.jpg', ["scale_in 1600 1200 True"]),
              ('tmp/test.jpg', 'crisp2/4x/test.jpg', ["scale_in 3200 2400 True"]),
              ('tmp/test.jpg', 'crisp2/default/test.jpg', ["scale_in 400 300 True"])
              ]),

            ('<img class="image-process-large-photo" src="/tmp/test.jpg" />',
             '<img class="image-process-large-photo" sizes="(min-width: 1200px) 800px, (min-width: 992px) 650px, (min-width: 768px) 718px, 100vw" src="/tmp/derivs/large-photo/800w/test.jpg" srcset="/tmp/derivs/large-photo/600w/test.jpg 600w, /tmp/derivs/large-photo/800w/test.jpg 800w, /tmp/derivs/large-photo/1600w/test.jpg 1600w"/>',
             [('tmp/test.jpg', 'large-photo/600w/test.jpg', ["scale_in 600 450 True"]),
              ('tmp/test.jpg', 'large-photo/800w/test.jpg', ["scale_in 800 600 True"]),
              ('tmp/test.jpg', 'large-photo/1600w/test.jpg', ["scale_in 1600 1200 True"]),
              ]),
           ]

        for data in test_data:
            c = Instance(data[0], settings)

            del images[:]
            harvest_images(c)

            expected_images = list()
            for t in data[2]:
                expected_source = os.path.join(settings['PATH'], t[0])
                output_path, _ = os.path.split(expected_source)
                base_path = os.path.join(output_path, settings['IMAGE_PROCESS_DIR'])
                expected_destination = os.path.join(base_path, t[1])
                expected_images.append((expected_source, expected_destination, t[2]))

            self.maxDiff = None
            self.assertEqual(c._content, data[1])
            for i in images:
                self.assertIn(i, expected_images)
            for i in expected_images:
                self.assertIn(i, images)
コード例 #8
0
    def test_extraction(self):
        settings = get_settings(IMAGE_PROCESS = self.transforms)
        html = '<img class="test image-process image-process-crop test2" src="/tmp/test.jpg" />'
        c = Instance(html, settings)

        del images[:]
        harvest_images(c)

        expected_content = '<img class="test image-process image-process-crop test2" src="/tmp/derivatives/crop/test.jpg"/>'

        expected_source = os.path.join(settings['PATH'], 'tmp/test.jpg')
        output_path, _ = os.path.split(expected_source)
        base_path = os.path.join(output_path, settings['IMAGE_PROCESS_DIR'], 'crop')
        expected_destination = os.path.join(base_path, 'test.jpg')
        expected_images = [(expected_source, expected_destination, [u'crop 10 20 100 200'])]

        self.assertEqual(c._content, expected_content)
        self.assertEqual(images, expected_images)
コード例 #9
0
    def test_picture_generation(self):
        settings = get_settings(IMAGE_PROCESS=self.valid_transforms, IMAGE_PROCESS_DIR='derivs')
        test_data = [
            ('<picture><source class="source-1" src="/images/pelican-closeup.jpg"></source><img class="image-process-pict" src="/images/pelican.jpg"/></picture>',
             '<picture><source media="(min-width: 640px)" sizes="100vw" srcset="/images/derivs/pict/default/640w/pelican.jpg 640w, /images/derivs/pict/default/1024w/pelican.jpg 1024w, /images/derivs/pict/default/1600w/pelican.jpg 1600w"></source><source srcset="/images/derivs/pict/source-1/1x/pelican-closeup.jpg 1x, /images/derivs/pict/source-1/2x/pelican-closeup.jpg 2x"></source><img class="image-process-pict" src="/images/derivs/pict/default/640w/pelican.jpg"/></picture>',
             [('images/pelican.jpg', 'pict/default/640w/pelican.jpg', ["scale_in 640 480 True"]),
              ('images/pelican.jpg', 'pict/default/1024w/pelican.jpg', ["scale_in 1024 683 True"]),
              ('images/pelican.jpg', 'pict/default/1600w/pelican.jpg', ["scale_in 1600 1200 True"]),
              ('images/pelican-closeup.jpg', 'pict/source-1/1x/pelican-closeup.jpg', ["crop 100 100 200 200"]),
              ('images/pelican-closeup.jpg', 'pict/source-1/2x/pelican-closeup.jpg', ["crop 100 100 300 300"])
              ]),

            ('<div class="figure"><img alt="Pelican" class="image-process-pict2" src="/images/pelican.jpg" /> <p class="caption">A nice pelican</p> <div class="legend"> <img alt="Other view of pelican" class="image-process source-2" src="/images/pelican-closeup.jpg" /> </div> </div>',
             '<div class="figure"><picture><source media="(min-width: 640px)" sizes="100vw" srcset="/images/derivs/pict2/default/640w/pelican.jpg 640w, /images/derivs/pict2/default/1024w/pelican.jpg 1024w, /images/derivs/pict2/default/1600w/pelican.jpg 1600w"></source><source srcset="/images/derivs/pict2/source-2/1x/pelican-closeup.jpg 1x, /images/derivs/pict2/source-2/2x/pelican-closeup.jpg 2x"></source><img alt="Pelican" class="image-process-pict2" src="/images/derivs/pict2/source-2/default/pelican-closeup.jpg"/></picture> <p class="caption">A nice pelican</p> <div class="legend">  </div> </div>',
             [('images/pelican.jpg', 'pict2/default/640w/pelican.jpg', ["scale_in 640 480 True"]),
              ('images/pelican.jpg', 'pict2/default/1024w/pelican.jpg', ["scale_in 1024 683 True"]),
              ('images/pelican.jpg', 'pict2/default/1600w/pelican.jpg', ["scale_in 1600 1200 True"]),
              ('images/pelican-closeup.jpg', 'pict2/source-2/1x/pelican-closeup.jpg', ["crop 100 100 200 200"]),
              ('images/pelican-closeup.jpg', 'pict2/source-2/2x/pelican-closeup.jpg', ["crop 100 100 300 300"]),
              ('images/pelican-closeup.jpg', 'pict2/source-2/default/pelican-closeup.jpg', ["scale_in 800 600 True"])
              ]),
           ]

        for data in test_data:
            c = Instance(data[0], settings)

            del images[:]
            harvest_images(c)

            expected_images = list()
            for t in data[2]:
                expected_source = os.path.join(settings['PATH'], t[0])
                output_path, _ = os.path.split(expected_source)
                base_path = os.path.join(output_path, settings['IMAGE_PROCESS_DIR'])
                expected_destination = os.path.join(base_path, t[1])
                expected_images.append((expected_source, expected_destination, t[2]))

            self.maxDiff = None
            self.assertEqual(c._content, data[1])
            for i in images:
                self.assertIn(i, expected_images)
            for i in expected_images:
                self.assertIn(i, images)
コード例 #10
0
    def test_extraction(self):
        settings = get_settings(IMAGE_PROCESS=self.transforms)
        html = '<img class="test image-process image-process-crop test2" src="/tmp/test.jpg" />'
        c = Instance(html, settings)

        del images[:]
        harvest_images(c)

        expected_content = '<img class="test image-process image-process-crop test2" src="/tmp/derivatives/crop/test.jpg"/>'

        expected_source = os.path.join(settings['PATH'], 'tmp/test.jpg')
        output_path, _ = os.path.split(expected_source)
        base_path = os.path.join(output_path, settings['IMAGE_PROCESS_DIR'],
                                 'crop')
        expected_destination = os.path.join(base_path, 'test.jpg')
        expected_images = [(expected_source, expected_destination,
                            [u'crop 10 20 100 200'])]

        self.assertEqual(c._content, expected_content)
        self.assertEqual(images, expected_images)