Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with Pillow 10 #36

Closed
musicinmybrain opened this issue Jul 30, 2023 · 2 comments
Closed

Incompatible with Pillow 10 #36

musicinmybrain opened this issue Jul 30, 2023 · 2 comments

Comments

@musicinmybrain
Copy link
Contributor

Pillow 10 has removed the ImageDraw.textsize() method. The intended replacement, ImageDraw.textbbox(), is available beginning with Pillow 8.0.0.

python3.11 -m venv _e
. _e/bin/activate
pip install .[tests]
pip install numpy
python -m pytest
=================================== FAILURES ===================================
____________________________ test_render_error_tile ____________________________

    def test_render_error_tile():
        """
        Test rendering of error tile.
        """
        tile_img._error_image.cache_clear()
>       img = tile_img._error_image(10, 10)

geotiler/tests/test_tile_img.py:66:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

width = 10, height = 10

    @functools.lru_cache(maxsize=4)
    def _error_image(width, height):
        """
        Create error tile image.

        The error tile image is PIL image object showing message that a map
        tile could not be downloaded.

        :param width: Width of tile image.
        :param height: Height of tile image.
        """
        img = PIL.Image.new('RGBA', (width, height))
        draw = PIL.ImageDraw.Draw(img)
        msg = 'Error downloading map tile.'
>       tw, th = draw.textsize(msg)
E       AttributeError: 'ImageDraw' object has no attribute 'textsize'

geotiler/tile/img.py:87: AttributeError
______________________________ test_render_image _______________________________

    def test_render_image():
        """
        Test rendering map image.
        """
        tile = PIL.Image.new('RGBA', (10, 10))
        map = mock.MagicMock()
        map.size = [30, 20]
        map.provider.tile_width = 10
        map.provider.tile_height = 10

        with mock.patch('geotiler.tile.img._tile_image') as tf, \
                mock.patch.object(PIL.Image, 'new') as img_new:

            tf.return_value = tile
            data = (tile, tile, tile, tile)
            offsets = ((0, 0), (10, 0), (20, 0), (0, 10))
            tiles = _tile_generator(offsets, data)
>           image = _run_render_image(map, tiles)

geotiler/tests/test_tile_img.py:108:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
geotiler/tests/test_tile_img.py:51: in _run_render_image
    image = loop.run_until_complete(task)
/usr/lib64/python3.11/asyncio/base_events.py:653: in run_until_complete
    return future.result()
geotiler/tile/img.py:65: in render_image
    error = _error_image(provider.tile_width, provider.tile_height)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

width = 10, height = 10

    @functools.lru_cache(maxsize=4)
    def _error_image(width, height):
        """
        Create error tile image.

        The error tile image is PIL image object showing message that a map
        tile could not be downloaded.

        :param width: Width of tile image.
        :param height: Height of tile image.
        """
        img = PIL.Image.new('RGBA', (width, height))
        draw = PIL.ImageDraw.Draw(img)
        msg = 'Error downloading map tile.'
>       tw, th = draw.textsize(msg)
E       ValueError: not enough values to unpack (expected 2, got 0)

geotiler/tile/img.py:87: ValueError
___________________________ test_render_image_error ____________________________

    def test_render_image_error():
        """
        Test rendering map image with error tile.
        """
        tile = PIL.Image.new('RGBA', (10, 10))
        map = mock.MagicMock()
        map.size = 30, 20
        map.provider.tile_width = 10
        map.provider.tile_height = 10

        with mock.patch('geotiler.tile.img._tile_image') as tf:
            tf.return_value = tile
            data = (tile, tile, None, tile, None, tile)
            offsets = ((0, 0), (10, 0), (20, 0), (0, 10), (10, 10), (20, 10))
            tiles = _tile_generator(offsets, data)
>           image = _run_render_image(map, tiles)

geotiler/tests/test_tile_img.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
geotiler/tests/test_tile_img.py:51: in _run_render_image
    image = loop.run_until_complete(task)
/usr/lib64/python3.11/asyncio/base_events.py:653: in run_until_complete
    return future.result()
geotiler/tile/img.py:65: in render_image
    error = _error_image(provider.tile_width, provider.tile_height)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

width = 10, height = 10

    @functools.lru_cache(maxsize=4)
    def _error_image(width, height):
        """
        Create error tile image.

        The error tile image is PIL image object showing message that a map
        tile could not be downloaded.

        :param width: Width of tile image.
        :param height: Height of tile image.
        """
        img = PIL.Image.new('RGBA', (width, height))
        draw = PIL.ImageDraw.Draw(img)
        msg = 'Error downloading map tile.'
>       tw, th = draw.textsize(msg)
E       AttributeError: 'ImageDraw' object has no attribute 'textsize'

geotiler/tile/img.py:87: AttributeError

[...]

=========================== short test summary info ============================
FAILED geotiler/tests/test_tile_img.py::test_render_error_tile - AttributeError: 'ImageDraw' object has no attribute 'textsize'
FAILED geotiler/tests/test_tile_img.py::test_render_image - ValueError: not enough values to unpack (expected 2, got 0)
FAILED geotiler/tests/test_tile_img.py::test_render_image_error - AttributeError: 'ImageDraw' object has no attribute 'textsize'
========================= 3 failed, 40 passed in 0.49s ========================
@wrobell
Copy link
Owner

wrobell commented Jul 31, 2023

Fixed in commit 5e0cfba.

@wrobell wrobell closed this as completed Jul 31, 2023
@musicinmybrain
Copy link
Contributor Author

Fixed in commit 5e0cfba.

Thank you! I backported that commit as a patch in Fedora Rawhide, where it seems to work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants