File: test_file_mpeg.py

package info (click to toggle)
pillow 12.1.1-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 72,640 kB
  • sloc: python: 49,768; ansic: 38,750; makefile: 302; sh: 169; javascript: 85
file content (39 lines) | stat: -rw-r--r-- 787 bytes parent folder | download | duplicates (2)
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
from __future__ import annotations

from io import BytesIO

import pytest

from PIL import Image, MpegImagePlugin


def test_identify() -> None:
    # Arrange
    b = BytesIO(b"\x00\x00\x01\xb3\x01\x00\x01")

    # Act
    with Image.open(b) as im:
        # Assert
        assert im.format == "MPEG"

        assert im.mode == "RGB"
        assert im.size == (16, 1)


def test_invalid_file() -> None:
    # Arrange
    invalid_file = "Tests/images/flower.jpg"

    # Act / Assert
    with pytest.raises(SyntaxError):
        MpegImagePlugin.MpegImageFile(invalid_file)


def test_load() -> None:
    # Arrange
    b = BytesIO(b"\x00\x00\x01\xb3\x01\x00\x01")

    with Image.open(b) as im:
        # Act / Assert: cannot load
        with pytest.raises(OSError):
            im.load()