File size: 2,790 Bytes
a7d7463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""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"])