From a77dbf4beefc2d0279729af28084c3b77c77fec5 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 9 May 2023 10:38:09 +0100 Subject: [PATCH] Tentative fix for resolve_fraction_unit ZeroDivision error I'll admit to not really following what the code does, so will really need someone with a better understanding of the aim of this code to look over the proposed fix; but based on a bunch of runs and hand-debugging, this seems to do the job. This passes all existing tests and also removes the reported error. On the other hand I'm not confident that I'm *not* just masking an underlying issue with this function. --- src/textual/_resolve.py | 4 ++-- tests/test_resolve.py | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/textual/_resolve.py b/src/textual/_resolve.py index ddbdd1d5c..1ee40af9e 100644 --- a/src/textual/_resolve.py +++ b/src/textual/_resolve.py @@ -143,7 +143,7 @@ def resolve_fraction_unit( resolved: list[Fraction | None] = [None] * len(resolve) remaining_fraction = Fraction(sum(scalar.value for scalar, _, _ in resolve)) - while True: + while remaining_fraction: remaining_space_changed = False resolve_fraction = Fraction(remaining_space, remaining_fraction) for index, (scalar, min_value, max_value) in enumerate(resolve): @@ -166,7 +166,7 @@ def resolve_fraction_unit( return ( Fraction(remaining_space, remaining_fraction) - if remaining_space + if remaining_space > 0 else Fraction(1) ) diff --git a/tests/test_resolve.py b/tests/test_resolve.py index c7cdd485e..b73db6c55 100644 --- a/tests/test_resolve.py +++ b/tests/test_resolve.py @@ -125,9 +125,6 @@ def test_resolve_fraction_unit(): ) == Fraction(2) -@pytest.mark.xfail( - strict=True, reason="https://github.com/Textualize/textual/issues/2502" -) def test_resolve_issue_2502(): """Test https://github.com/Textualize/textual/issues/2502"""