mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed zero division error https://github.com/Textualize/textual/issues/2673
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- `work` decorator accepts `description` parameter to add debug string https://github.com/Textualize/textual/issues/2597
|
- `work` decorator accepts `description` parameter to add debug string https://github.com/Textualize/textual/issues/2597
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ def resolve_fraction_unit(
|
|||||||
if not remaining_space or not widget_styles:
|
if not remaining_space or not widget_styles:
|
||||||
return Fraction(1)
|
return Fraction(1)
|
||||||
|
|
||||||
|
initial_space = remaining_space
|
||||||
|
|
||||||
def resolve_scalar(
|
def resolve_scalar(
|
||||||
scalar: Scalar | None, fraction_unit: Fraction = Fraction(1)
|
scalar: Scalar | None, fraction_unit: Fraction = Fraction(1)
|
||||||
) -> Fraction | None:
|
) -> Fraction | None:
|
||||||
@@ -166,8 +168,8 @@ def resolve_fraction_unit(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
Fraction(remaining_space, remaining_fraction)
|
Fraction(remaining_space, remaining_fraction)
|
||||||
if remaining_space > 0
|
if remaining_fraction > 0
|
||||||
else Fraction(1)
|
else initial_space
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import pytest
|
|||||||
|
|
||||||
from textual._resolve import resolve, resolve_fraction_unit
|
from textual._resolve import resolve, resolve_fraction_unit
|
||||||
from textual.css.scalar import Scalar
|
from textual.css.scalar import Scalar
|
||||||
|
from textual.css.styles import Styles
|
||||||
from textual.geometry import Size
|
from textual.geometry import Size
|
||||||
from textual.widget import Widget
|
from textual.widget import Widget
|
||||||
|
|
||||||
@@ -125,6 +126,30 @@ def test_resolve_fraction_unit():
|
|||||||
) == Fraction(2)
|
) == 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():
|
def test_resolve_issue_2502():
|
||||||
"""Test https://github.com/Textualize/textual/issues/2502"""
|
"""Test https://github.com/Textualize/textual/issues/2502"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user