File size: 3,958 Bytes
d884829
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test to verify that the _create_progress_html bug has been fixed.
This tests that None values are handled gracefully.
"""

import time
from yomitalk.app import PaperPodcastApp


class TestCreateProgressHtmlFix:
    """Test cases to verify the fix for _create_progress_html with None values."""

    def setup_method(self):
        """Set up test fixtures."""
        self.app = PaperPodcastApp()

    def test_create_progress_html_with_none_total_parts_fixed(self):
        """
        Test that _create_progress_html handles None total_parts gracefully after the fix.
        """
        # This should no longer raise a TypeError
        result = self.app._create_progress_html(
            current_part=5,
            total_parts=None,  # None should be handled gracefully
            status_message="Test status",
            is_completed=False,
            start_time=time.time(),
        )

        # Verify we get a valid HTML string
        assert isinstance(result, str)
        assert len(result) > 0
        assert "Test status" in result
        assert "🎵" in result  # Should show the progress emoji

    def test_create_progress_html_with_none_current_part(self):
        """
        Test that _create_progress_html handles None current_part gracefully.
        """
        result = self.app._create_progress_html(
            current_part=None,  # None should be handled gracefully
            total_parts=10,
            status_message="Test with None current_part",
            is_completed=False,
            start_time=time.time(),
        )

        assert isinstance(result, str)
        assert "Test with None current_part" in result

    def test_create_progress_html_with_both_none(self):
        """
        Test that _create_progress_html handles both None values gracefully.
        """
        result = self.app._create_progress_html(current_part=None, total_parts=None, status_message="Both None", is_completed=False, start_time=time.time())

        assert isinstance(result, str)
        assert "Both None" in result

    def test_create_progress_html_completed_with_none_values(self):
        """
        Test that completed status works even with None values.
        """
        result = self.app._create_progress_html(
            current_part=None,
            total_parts=None,
            status_message="Completed test",
            is_completed=True,  # Completed should bypass progress calculation
            start_time=time.time(),
        )

        assert isinstance(result, str)
        assert "Completed test" in result
        assert "✅" in result  # Should show completion emoji

    def test_normal_operation_still_works(self):
        """
        Test that normal operation with valid integers still works correctly.
        """
        result = self.app._create_progress_html(current_part=3, total_parts=10, status_message="Normal operation", is_completed=False, start_time=time.time())

        assert isinstance(result, str)
        assert "Normal operation" in result
        # Should calculate 30% progress (but capped at 95%)
        assert "🎵" in result

    def test_progress_percentage_calculation_with_valid_values(self):
        """
        Test that progress percentage is calculated correctly with valid values.
        """
        result = self.app._create_progress_html(current_part=2, total_parts=4, status_message="Half done", is_completed=False)

        # 2/4 = 50% progress
        assert "50%" in result or "50 %" in result

    def test_zero_division_protection(self):
        """
        Test that zero total_parts doesn't cause division by zero.
        """
        result = self.app._create_progress_html(
            current_part=5,
            total_parts=0,  # This should be handled without division error
            status_message="Zero total",
            is_completed=False,
        )

        assert isinstance(result, str)
        assert "Zero total" in result