mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
geometry tests
This commit is contained in:
@@ -127,11 +127,6 @@ class Size(NamedTuple):
|
|||||||
return Region(0, 0, width, height)
|
return Region(0, 0, width, height)
|
||||||
|
|
||||||
def __add__(self, other: object) -> Size:
|
def __add__(self, other: object) -> Size:
|
||||||
if isinstance(other, Spacing):
|
|
||||||
width, height = self
|
|
||||||
other_width, other_height = other.totals
|
|
||||||
return Size(width + other_width, height + other_height)
|
|
||||||
|
|
||||||
if isinstance(other, tuple):
|
if isinstance(other, tuple):
|
||||||
width, height = self
|
width, height = self
|
||||||
width2, height2 = other
|
width2, height2 = other
|
||||||
@@ -617,6 +612,7 @@ class Spacing(NamedTuple):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def totals(self) -> tuple[int, int]:
|
def totals(self) -> tuple[int, int]:
|
||||||
|
"""Total spacing for horizontal and vertical spacing."""
|
||||||
top, right, bottom, left = self
|
top, right, bottom, left = self
|
||||||
return (left + right, top + bottom)
|
return (left + right, top + bottom)
|
||||||
|
|
||||||
|
|||||||
@@ -251,6 +251,10 @@ def test_region_y_range():
|
|||||||
assert Region(5, 10, 20, 30).y_range == range(10, 40)
|
assert Region(5, 10, 20, 30).y_range == range(10, 40)
|
||||||
|
|
||||||
|
|
||||||
|
def test_region_reset_origin():
|
||||||
|
assert Region(5, 10, 20, 30).reset_origin == Region(0, 0, 20, 30)
|
||||||
|
|
||||||
|
|
||||||
def test_region_expand():
|
def test_region_expand():
|
||||||
assert Region(50, 10, 10, 5).expand((2, 3)) == Region(48, 7, 14, 11)
|
assert Region(50, 10, 10, 5).expand((2, 3)) == Region(48, 7, 14, 11)
|
||||||
|
|
||||||
@@ -280,6 +284,10 @@ def test_spacing_bottom_right():
|
|||||||
assert Spacing(2, 3, 4, 5).bottom_right == (3, 4)
|
assert Spacing(2, 3, 4, 5).bottom_right == (3, 4)
|
||||||
|
|
||||||
|
|
||||||
|
def test_spacing_totals():
|
||||||
|
assert Spacing(2, 3, 4, 5).totals == (8, 6)
|
||||||
|
|
||||||
|
|
||||||
def test_spacing_css():
|
def test_spacing_css():
|
||||||
assert Spacing(1, 1, 1, 1).css == "1"
|
assert Spacing(1, 1, 1, 1).css == "1"
|
||||||
assert Spacing(1, 2, 1, 2).css == "1 2"
|
assert Spacing(1, 2, 1, 2).css == "1 2"
|
||||||
|
|||||||
Reference in New Issue
Block a user