mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
@@ -5,6 +5,7 @@ import pytest
|
||||
|
||||
from textual._resolve import resolve, resolve_fraction_unit
|
||||
from textual.css.scalar import Scalar
|
||||
from textual.css.styles import Styles
|
||||
from textual.geometry import Size
|
||||
from textual.widget import Widget
|
||||
|
||||
@@ -125,6 +126,30 @@ def test_resolve_fraction_unit():
|
||||
) == Fraction(2)
|
||||
|
||||
|
||||
def test_resolve_fraction_unit_stress_test():
|
||||
"""Check for zero division errors."""
|
||||
# https://github.com/Textualize/textual/issues/2673
|
||||
widget = Widget()
|
||||
styles = widget.styles
|
||||
styles.width = "1fr"
|
||||
|
||||
# We're mainly checking for the absence of zero division errors,
|
||||
# which is a reoccurring theme for this code.
|
||||
for remaining_space in range(1, 101, 10):
|
||||
for max_width in range(1, remaining_space):
|
||||
styles.max_width = max_width
|
||||
|
||||
for width in range(1, remaining_space):
|
||||
resolved_unit = resolve_fraction_unit(
|
||||
[styles, styles, styles],
|
||||
Size(width, 24),
|
||||
Size(width, 24),
|
||||
Fraction(remaining_space),
|
||||
"width",
|
||||
)
|
||||
assert resolved_unit <= remaining_space
|
||||
|
||||
|
||||
def test_resolve_issue_2502():
|
||||
"""Test https://github.com/Textualize/textual/issues/2502"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user