示例#1
0
    def assert_resize_image(self,
                            filename,
                            width,
                            height,
                            mode,
                            expected_width=None,
                            expected_height=None):
        if expected_width == None: expected_width = width
        if expected_height == None: expected_height = height

        filename = self.get_test_image_path(filename)
        ext = get_ext(filename)
        dst_filename = os.path.join(tempfile.gettempdir(),
                                    'resized_image.%s' % ext)

        resize_image(filename, dst_filename, width, height, mode)

        self.assertTrue(os.path.isfile(dst_filename), 'file exists')
        self.assertTrue(is_image(dst_filename), 'is image file')

        # check image size
        size = get_image_size(dst_filename)
        self.assertEqual(
            size[0], expected_width,
            'expected image width of %d, but was %d.' %
            (expected_width, size[0]))
        self.assertEqual(
            size[1], expected_height,
            'expected image height of %d, but was %d.' %
            (expected_height, size[1]))
示例#2
0
 def test_should_return_false_if_extension_is_pdf(self):
     self.assertFalse(is_image(self.get_test_image_path('test.pdf')))
示例#3
0
 def test_should_return_false_for_non_images(self):
     self.assertFalse(is_image(self.get_test_image_path('test.txt')))
示例#4
0
 def test_should_return_true_for_images(self):
     for image in TEST_IMAGES:
         self.assertTrue(is_image(self.get_test_image_path(image.filename)))