Fix tests in animation/test_updaters.py

This commit is contained in:
Francisco Manríquez Novoa 2026-02-13 10:58:52 -03:00
commit 97d3f3e774
2 changed files with 18 additions and 16 deletions

View file

@ -167,20 +167,20 @@ def turn_animation_into_updater(
m.remove_updater(update)
return
time_ratio = animation.total_time / run_time
time_ratio = total_time / run_time
if cycle:
alpha = time_ratio % 1
else:
alpha = np.clip(time_ratio, 0, 1)
if alpha >= 1:
animation.finish()
m.remove_updater(update) # type: ignore
m.remove_updater(update)
return
animation.interpolate(alpha)
animation.update_mobjects(dt)
total_time += dt
mobject.add_updater(update) # type: ignore
mobject.add_updater(update)
return mobject

View file

@ -8,11 +8,11 @@ def test_turn_animation_into_updater_zero_run_time():
"""Test that turn_animation_into_updater handles zero run_time correctly."""
# Create a simple mobject and animation
mobject = Circle()
animation = FadeIn(mobject, run_time=0)
animation = FadeIn(mobject, run_time=0.0)
# Track updater calls
update_calls = []
original_updaters = mobject.updaters.copy()
original_updaters = mobject.get_updaters().copy()
# Call turn_animation_into_updater
result = turn_animation_into_updater(animation)
@ -21,18 +21,17 @@ def test_turn_animation_into_updater_zero_run_time():
assert result is mobject
# Get the updater that was added
assert len(mobject.updaters) == len(original_updaters) + 1
updater = mobject.updaters[-1]
current_updaters = mobject.get_updaters()
assert len(current_updaters) == len(original_updaters) + 1
updater = current_updaters[-1]
# Simulate calling the updater
updater(mobject, dt=0.1)
# The updater should have finished and removed itself
assert len(mobject.updaters) == len(original_updaters)
assert updater not in mobject.updaters
# Animation should be in finished state
assert animation.total_time >= 0
current_updaters = mobject.get_updaters()
assert len(current_updaters) == len(original_updaters)
assert updater not in current_updaters
def test_turn_animation_into_updater_positive_run_time_persists():
@ -40,17 +39,20 @@ def test_turn_animation_into_updater_positive_run_time_persists():
mobject = Circle()
animation = FadeIn(mobject, run_time=1.0)
original_updaters = mobject.updaters.copy()
original_updaters = mobject.get_updaters().copy()
# Call turn_animation_into_updater
result = turn_animation_into_updater(animation)
# Get the updater that was added
updater = mobject.updaters[-1]
current_updaters = mobject.get_updaters()
assert len(current_updaters) == len(original_updaters) + 1
updater = current_updaters[-1]
# Simulate calling the updater (partial progress)
updater(mobject, dt=0.1)
# The updater should still be present (not finished)
assert len(mobject.updaters) == len(original_updaters) + 1
assert updater in mobject.updaters
current_updaters = mobject.get_updaters()
assert len(current_updaters) == len(original_updaters) + 1
assert updater in current_updaters