diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:20:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:20:58 +0000 |
commit | 5bb0bb4be543fd5eca41673696a62ed80d493591 (patch) | |
tree | ad2c464f140e86c7f178a6276d7ea4a93e3e6c92 /tests/test_util_images.py | |
parent | Adding upstream version 7.2.6. (diff) | |
download | sphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.tar.xz sphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.zip |
Adding upstream version 7.3.7.upstream/7.3.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_util_images.py')
-rw-r--r-- | tests/test_util_images.py | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/tests/test_util_images.py b/tests/test_util_images.py deleted file mode 100644 index 15853c7..0000000 --- a/tests/test_util_images.py +++ /dev/null @@ -1,74 +0,0 @@ -"""Test images util.""" - -import pytest - -from sphinx.util.images import ( - get_image_extension, - get_image_size, - guess_mimetype, - parse_data_uri, -) - -GIF_FILENAME = 'img.gif' -PNG_FILENAME = 'img.png' -PDF_FILENAME = 'img.pdf' -TXT_FILENAME = 'index.txt' - - -def test_get_image_size(rootdir): - assert get_image_size(rootdir / 'test-root' / GIF_FILENAME) == (200, 181) - assert get_image_size(rootdir / 'test-root' / PNG_FILENAME) == (200, 181) - assert get_image_size(rootdir / 'test-root' / PDF_FILENAME) is None - assert get_image_size(rootdir / 'test-root' / TXT_FILENAME) is None - - -@pytest.mark.filterwarnings('ignore:The content argument') -def test_guess_mimetype(): - # guess by filename - assert guess_mimetype('img.png') == 'image/png' - assert guess_mimetype('img.jpg') == 'image/jpeg' - assert guess_mimetype('img.txt') is None - assert guess_mimetype('img.txt', default='text/plain') == 'text/plain' - assert guess_mimetype('no_extension') is None - assert guess_mimetype('IMG.PNG') == 'image/png' - - # default parameter is used when no extension - assert guess_mimetype('img.png', 'text/plain') == 'image/png' - assert guess_mimetype('no_extension', 'text/plain') == 'text/plain' - - -def test_get_image_extension(): - assert get_image_extension('image/png') == '.png' - assert get_image_extension('image/jpeg') == '.jpg' - assert get_image_extension('image/svg+xml') == '.svg' - assert get_image_extension('text/plain') is None - - -def test_parse_data_uri(): - # standard case - uri = ("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" - "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==") - image = parse_data_uri(uri) - assert image is not None - assert image.mimetype == 'image/png' - assert image.charset == 'US-ASCII' - - # no mimetype - uri = ("data:charset=utf-8,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElE" - "QVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==") - image = parse_data_uri(uri) - assert image is not None - assert image.mimetype == 'text/plain' - assert image.charset == 'utf-8' - - # non data URI - uri = ("image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" - "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==") - image = parse_data_uri(uri) - assert image is None - - # invalid data URI (no properties) - uri = ("data:iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" - "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==") - with pytest.raises(ValueError, match=r'not enough values to unpack \(expected 2, got 1\)'): - parse_data_uri(uri) |