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):
|
|
|
|
Measurement.get(console, None, console.width)
|
2020-10-08 07:59:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_null_get():
|
|
|
|
# Test negative console.width passed into get method
|
|
|
|
assert Measurement.get(Console(width=-1), None) == Measurement(0, 0)
|
|
|
|
# Test negative max_width passed into get method
|
|
|
|
assert Measurement.get(Console(), None, -1) == Measurement(0, 0)
|
|
|
|
|
|
|
|
|
2020-10-08 08:12:01 +00:00
|
|
|
def test_measure_renderables():
|
|
|
|
# Test measure_renderables returning a null Measurement object
|
|
|
|
assert measure_renderables(Console(), None, None) == Measurement(0, 0)
|
|
|
|
# Test measure_renderables returning a valid Measurement object
|
|
|
|
assert measure_renderables(Console(width=1), ["test"], 1) == Measurement(1, 1)
|