|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from manim import Circle, FadeIn |
| 6 | +from manim.animation.updaters.mobject_update_utils import turn_animation_into_updater |
| 7 | + |
| 8 | + |
| 9 | +def test_turn_animation_into_updater_zero_run_time(): |
| 10 | + """Test that turn_animation_into_updater handles zero run_time correctly.""" |
| 11 | + # Create a simple mobject and animation |
| 12 | + mobject = Circle() |
| 13 | + animation = FadeIn(mobject, run_time=0) |
| 14 | + |
| 15 | + # Track updater calls |
| 16 | + update_calls = [] |
| 17 | + original_updaters = mobject.updaters.copy() |
| 18 | + |
| 19 | + # Call turn_animation_into_updater |
| 20 | + result = turn_animation_into_updater(animation) |
| 21 | + |
| 22 | + # Verify mobject is returned |
| 23 | + assert result is mobject |
| 24 | + |
| 25 | + # Get the updater that was added |
| 26 | + assert len(mobject.updaters) == len(original_updaters) + 1 |
| 27 | + updater = mobject.updaters[-1] |
| 28 | + |
| 29 | + # Simulate calling the updater |
| 30 | + updater(mobject, dt=0.1) |
| 31 | + |
| 32 | + # The updater should have finished and removed itself |
| 33 | + assert len(mobject.updaters) == len(original_updaters) |
| 34 | + assert updater not in mobject.updaters |
| 35 | + |
| 36 | + # Animation should be in finished state |
| 37 | + assert animation.total_time >= 0 |
| 38 | + |
| 39 | + |
| 40 | +def test_turn_animation_into_updater_negative_run_time(): |
| 41 | + """Test that turn_animation_into_updater handles negative run_time correctly.""" |
| 42 | + mobject = Circle() |
| 43 | + animation = FadeIn(mobject, run_time=-1) |
| 44 | + |
| 45 | + original_updaters = mobject.updaters.copy() |
| 46 | + |
| 47 | + # Call turn_animation_into_updater |
| 48 | + result = turn_animation_into_updater(animation) |
| 49 | + |
| 50 | + # Get the updater that was added |
| 51 | + updater = mobject.updaters[-1] |
| 52 | + |
| 53 | + # Simulate calling the updater |
| 54 | + updater(mobject, dt=0.1) |
| 55 | + |
| 56 | + # The updater should have finished and removed itself |
| 57 | + assert len(mobject.updaters) == len(original_updaters) |
| 58 | + assert updater not in mobject.updaters |
| 59 | + |
| 60 | + |
| 61 | +def test_turn_animation_into_updater_positive_run_time_persists(): |
| 62 | + """Test that updater persists with positive run_time.""" |
| 63 | + mobject = Circle() |
| 64 | + animation = FadeIn(mobject, run_time=1.0) |
| 65 | + |
| 66 | + original_updaters = mobject.updaters.copy() |
| 67 | + |
| 68 | + # Call turn_animation_into_updater |
| 69 | + result = turn_animation_into_updater(animation) |
| 70 | + |
| 71 | + # Get the updater that was added |
| 72 | + updater = mobject.updaters[-1] |
| 73 | + |
| 74 | + # Simulate calling the updater (partial progress) |
| 75 | + updater(mobject, dt=0.1) |
| 76 | + |
| 77 | + # The updater should still be present (not finished) |
| 78 | + assert len(mobject.updaters) == len(original_updaters) + 1 |
| 79 | + assert updater in mobject.updaters |
0 commit comments