Example #1
0
    def test_invalid_path(self, image_fetcher: ImageFetcher) -> None:
        resolution = ResolutionName.HIGH

        with pytest.raises(InvalidPathError) as error:
            image_fetcher.resize_image(self.path, self.resized_path,
                                       resolution)

        assert error.value.message == f"Invalid image path: '{self.path}'"
Example #2
0
    def test_invalid_resolution(self, image_fetcher: ImageFetcher) -> None:
        resolution = "test"

        with TemporaryImageFile(self.path):
            with pytest.raises(InvalidResolutionError) as error:
                image_fetcher.resize_image(self.path, self.resized_path,
                                           resolution)

        assert error.value.message == f"Invalid resolution: '{resolution}'"
Example #3
0
    def test_resize(self, image_fetcher: ImageFetcher) -> None:
        resolution = ResolutionName.LOW
        max_dimension = getattr(ResolutionMaxDimension, resolution)
        raw_dimensions = (1000, 1000)

        with TemporaryImageFile(self.path, raw_dimensions):
            image = image_fetcher.resize_image(self.path, self.resized_path,
                                               resolution)

        assert isinstance(image, Image.Image)
        assert image.size == (max_dimension, max_dimension)
        assert os.path.exists(self.resized_path)
Example #4
0
    def test_resolution_greater_than_raw(self,
                                         image_fetcher: ImageFetcher) -> None:
        resolution = ResolutionName.LOW
        reduced_dimensions = (1, 1)

        with TemporaryImageFile(self.path, reduced_dimensions):
            image = image_fetcher.resize_image(self.path, self.resized_path,
                                               resolution)

        assert isinstance(image, Image.Image)
        assert image.size == reduced_dimensions
        assert not os.path.exists(self.resized_path)