2020-08-08 10:47:10 +00:00
|
|
|
from rich.text import Text
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from rich.errors import NotRenderableError
|
|
|
|
from rich.console import Console
|
2020-10-08 08:12:01 +00:00
|
|
|
from rich.measure import Measurement, measure_renderables
|
2020-08-08 10:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_span():
|
|
|
|
measurement = Measurement(10, 100)
|
|
|
|
assert measurement.span == 90
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_renderable():
|
|
|
|
console = Console()
|
|
|
|
text = Text()
|
|
|
|
|
|
|
|
with pytest.raises(NotRenderableError):
|
2021-03-25 21:08:36 +00:00
|
|
|
Measurement.get(console, console.options, None)
|
2020-10-08 07:59:56 +00:00
|
|
|
|
|
|
|
|
2020-10-08 08:12:01 +00:00
|
|
|
def test_measure_renderables():
|
2021-03-25 21:08:36 +00:00
|
|
|
console = Console()
|
|
|
|
assert measure_renderables(console, console.options, "") == Measurement(0, 0)
|
|
|
|
assert measure_renderables(
|
|
|
|
console, console.options.update_width(0), "hello"
|
|
|
|
) == Measurement(0, 0)
|
2020-10-17 16:10:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_clamp():
|
|
|
|
measurement = Measurement(20, 100)
|
|
|
|
assert measurement.clamp(10, 50) == Measurement(20, 50)
|
|
|
|
assert measurement.clamp(30, 50) == Measurement(30, 50)
|
|
|
|
assert measurement.clamp(None, 50) == Measurement(20, 50)
|
2020-10-17 16:25:13 +00:00
|
|
|
assert measurement.clamp(30, None) == Measurement(30, 100)
|
|
|
|
assert measurement.clamp(None, None) == Measurement(20, 100)
|