コード例 #1
0
    def test_save_img_to_dir(self):
        test_image_path = os.path.join(os.path.dirname(__file__),
                                       '../data/image1.JPG')
        image = Image.open(test_image_path)

        res = save_img_to_dir(image, self.tempdir, SUB_DIR)

        self.assertIsNotNone(res)

        filename = res['path']

        self.assertTrue(filename.endswith('.png'))
コード例 #2
0
    def test_save_img_to_dir_dry(self):
        test_image_path = os.path.join(os.path.dirname(__file__),
                                       '../data/image1.JPG')
        image = Image.open(test_image_path)

        res = save_img_to_dir(image, self.tempdir, SUB_DIR, dry=True)

        self.assertIsNone(res)

        md5 = hashlib.md5(image.tobytes()).hexdigest()

        filepath = os.path.join(self.tempdir, '', md5[:2], md5 + '.png')

        self.assertFalse(os.path.exists(filepath))
コード例 #3
0
    def test_save_img_to_dir_already_exists(self, mock_exists):
        test_image_path = os.path.join(os.path.dirname(__file__),
                                       '../data/image1.JPG')
        image = Image.open(test_image_path)

        image.save = Mock()

        mock_exists.return_value = True

        res = save_img_to_dir(image, self.tempdir, SUB_DIR)

        self.assertIsNotNone(res)

        self.assertEqual(image.save.call_count, 0)