File: test_page_format.py

package info (click to toggle)
fpdf2 2.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 53,860 kB
  • sloc: python: 39,487; sh: 133; makefile: 12
file content (31 lines) | stat: -rw-r--r-- 980 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
import pytest

from fpdf.errors import FPDFPageFormatException
from fpdf.fpdf import get_page_format


def test_page_format_ok():
    assert get_page_format("a4") == (595.28, 841.89)
    assert get_page_format("letter") == (612, 792)
    assert get_page_format((297, 210), k=2) == (594, 420)


def test_page_format_error():
    with pytest.raises(FPDFPageFormatException) as error:
        get_page_format("letter1")

    assert "FPDFPageFormatException" in str(error.value)
    assert "Unknown page format" in str(error.value)
    assert "letter1" in str(error.value)

    with pytest.raises(FPDFPageFormatException) as error:
        get_page_format(3)

    assert "FPDFPageFormatException" in str(error.value)
    assert "Only one argument given" in str(error.value)

    with pytest.raises(FPDFPageFormatException) as error:
        get_page_format(4, "a")

    assert "FPDFPageFormatException" in str(error.value)
    assert "Arguments must be numbers: " in str(error.value)