| """Tests for animation module""" |
|
|
| import pytest |
| import time |
| import sys |
| from pathlib import Path |
|
|
| sys.path.insert(0, str(Path(__file__).parent.parent / "src")) |
|
|
| from animations import ( |
| Spinner, |
| ProgressBar, |
| ParticleBurst, |
| TypingEffect, |
| AnimationConfig, |
| ) |
|
|
|
|
| class TestAnimationConfig: |
| """Test AnimationConfig class""" |
|
|
| def test_default_config(self): |
| config = AnimationConfig() |
| assert config.speed == 0.05 |
| assert config.color_enabled == True |
|
|
| def test_custom_config(self): |
| config = AnimationConfig(speed=0.1, color_enabled=False) |
| assert config.speed == 0.1 |
| assert config.color_enabled == False |
|
|
| def test_spinner_frames_exist(self): |
| assert len(AnimationConfig.SPINNER_FRAMES) > 0 |
|
|
|
|
| class TestSpinner: |
| """Test Spinner class""" |
|
|
| def test_spinner_creation(self): |
| spinner = Spinner("Loading") |
| assert spinner.message == "Loading" |
| assert spinner.running == False |
|
|
| def test_spinner_start_stop(self): |
| spinner = Spinner("Test") |
| spinner.start() |
| assert spinner.running == True |
| spinner.stop() |
| assert spinner.running == False |
|
|
| def test_spinner_context(self): |
| with Spinner("Context") as s: |
| assert s.running == True |
| assert s.running == False |
|
|
|
|
| class TestProgressBar: |
| """Test ProgressBar class""" |
|
|
| def test_progress_bar_creation(self): |
| progress = ProgressBar(total=100) |
| assert progress.total == 100 |
| assert progress.current == 0 |
|
|
| def test_progress_bar_iteration(self): |
| items = list(range(10)) |
| progress = ProgressBar(iterable=items) |
| results = list(progress) |
| assert len(results) == 10 |
|
|
| def test_progress_update(self): |
| progress = ProgressBar(total=100) |
| progress.update(50) |
| assert progress.current == 50 |
|
|
| def test_progress_percent(self): |
| progress = ProgressBar(total=100) |
| progress.update(75) |
| assert progress.percent == 0.75 |
|
|
|
|
| class TestTypingEffect: |
| """Test TypingEffect class""" |
|
|
| def test_typing_effect_creation(self): |
| effect = TypingEffect("Test text") |
| assert effect.text == "Test text" |
|
|
| def test_typing_effect_animate(self, capsys): |
| effect = TypingEffect("Hi", delay=0.01) |
| result = effect.animate() |
| assert result == "Hi" |
|
|
|
|
| class TestParticleBurst: |
| """Test ParticleBurst class""" |
|
|
| def test_particle_burst_creation(self): |
| burst = ParticleBurst(count=50) |
| assert burst.count == 50 |
|
|
| def test_particle_burst_center(self): |
| burst = ParticleBurst(center_x=60, center_y=15) |
| assert burst.center_x == 60 |
| assert burst.center_y == 15 |
|
|
|
|
| if __name__ == "__main__": |
| pytest.main([__file__, "-v"]) |
|
|