File: test_geometry.py

package info (click to toggle)
textual-image 0.8.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,468 kB
  • sloc: python: 1,851; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,794 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
from pytest import raises

from tests.data import CELL_SIZE
from textual_image._geometry import ImageSize


def test_image_size_validation() -> None:
    ImageSize(256, 256, None, None).validate()
    ImageSize(256, 256, 128, 128).validate()
    ImageSize(256, 256, "10%", "10%").validate()
    ImageSize(256, 256, "auto", "auto").validate()

    with raises(ValueError):
        ImageSize(256, 256, "-10%", "-10%").validate()

    with raises(ValueError):
        ImageSize(256, 256, "10", "10").validate()

    with raises(ValueError):
        ImageSize(256, 256, "xx%", "xx%").validate()


def test_image_size_cell_size_calculation() -> None:
    assert ImageSize(0, 0, None, None).get_cell_size(100, 100, CELL_SIZE) == (0, 0)
    assert ImageSize(256, 256, None, None).get_cell_size(100, 100, CELL_SIZE) == (26, 13)
    assert ImageSize(256, 256, "50%", "50%").get_cell_size(100, 100, CELL_SIZE) == (50, 50)
    assert ImageSize(256, 256, "auto", "auto").get_cell_size(100, 100, CELL_SIZE) == (100, 50)
    assert ImageSize(256, 256, "50%", "auto").get_cell_size(100, 100, CELL_SIZE) == (50, 25)
    assert ImageSize(256, 256, 50, "auto").get_cell_size(100, 100, CELL_SIZE) == (50, 25)
    assert ImageSize(256, 256, "auto", "50%").get_cell_size(100, 100, CELL_SIZE) == (100, 50)
    assert ImageSize(256, 256, "auto", 50).get_cell_size(100, 100, CELL_SIZE) == (100, 50)
    assert ImageSize(256, 256, "auto", None).get_cell_size(32, 32, CELL_SIZE) == (32, 13)
    assert ImageSize(256, 256, None, "auto").get_cell_size(32, 32, CELL_SIZE) == (26, 32)
    assert ImageSize(12, 512, "auto", "auto").get_cell_size(32, 32, CELL_SIZE) == (2, 32)


def test_image_size_pixel_size_calculation() -> None:
    assert ImageSize(256, 256, None, None).get_pixel_size(100, 100, CELL_SIZE) == (260, 260)