File: test_storage.py

package info (click to toggle)
mopidy-local 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 448 kB
  • sloc: python: 3,153; sql: 544; sh: 15; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pytest

from mopidy_local import storage


def test_get_image_type_from_header_png():
    data_bytes = b"\x89PNG\r\n\x1A\nffe000104a464"
    assert storage.get_image_type_from_header(data_bytes) == "png"


@pytest.mark.parametrize(
    "data",
    [
        pytest.param("474946383761ffe000104a46", id="GIF87a"),
        pytest.param("474946383961ffe000104a46", id="GIF89a"),
    ],
)
def test_get_image_type_from_header_gif(data):
    data_bytes = bytes.fromhex(data)
    assert storage.get_image_type_from_header(data_bytes) == "gif"


@pytest.mark.parametrize(
    "data",
    [
        pytest.param("ffd8ffe000104a46494600", id="JFIF"),
        pytest.param("ffd8ffe100184578696600", id="Exif"),
        pytest.param("ffd8ffe1095068747470", id="XMP"),
    ],
)
def test_get_image_type_from_header_jpeg(data):
    data_bytes = bytes.fromhex(data)
    assert storage.get_image_type_from_header(data_bytes) == "jpeg"


def test_get_image_type_from_header_unknown_header():
    data_bytes = b"PIF81affe000104a464"
    with pytest.raises(ValueError):
        storage.get_image_type_from_header(data_bytes)


def test_get_image_type_from_header_too_short_header():
    data_bytes = b"\xFF"
    with pytest.raises(ValueError):
        storage.get_image_type_from_header(data_bytes)