summaryrefslogtreecommitdiff
path: root/scripts/verify_playlist_integration.py
blob: 1306782663b23d2344b1b45471923ec5346fb4aa (plain) (blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"""Verification script for playlist membership integration.

Checks that all components are properly integrated into MainWindow.
"""

import sys
from pathlib import Path

# Add project root to path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))


def _check_import(module_path: str, component_name: str, check_num: int) -> tuple[int, int]:
    """Check if a component can be imported.

    Args:
        module_path: The module path to import from
        component_name: The component name to import
        check_num: The check number for display

    Returns:
        tuple[int, int]: (passed, failed) counts
    """
    try:
        __import__(module_path, fromlist=[component_name])
    except ImportError as e:
        print(f"❌ Check {check_num}: {component_name} import failed: {e}")
        return (0, 1)
    else:
        print(f"✅ Check {check_num}: {component_name} importable")
        return (1, 0)


def _run_all_import_checks() -> tuple[int, int]:
    """Run all import checks.

    Returns:
        tuple[int, int]: (passed, failed) counts
    """
    checks = [
        ("tidal_dl_ng.gui.playlist_membership_mixin", "PlaylistMembershipMixin", 1),
        ("tidal_dl_ng.gui.playlist_membership", "PlaylistContextLoader", 2),
        ("tidal_dl_ng.gui.playlist_membership", "ThreadSafePlaylistCache", 3),
        ("tidal_dl_ng.gui.playlist_membership", "PlaylistColumnDelegate", 4),
        ("tidal_dl_ng.ui.dialog_playlist_manager", "PlaylistManagerDialog", 5),
    ]

    total_passed = 0
    total_failed = 0

    for module_path, component_name, check_num in checks:
        passed, failed = _check_import(module_path, component_name, check_num)
        total_passed += passed
        total_failed += failed

    return total_passed, total_failed


def _check_mainwindow_inheritance() -> tuple[int, int]:
    """Check if MainWindow inherits from PlaylistMembershipMixin.

    Returns:
        tuple[int, int]: (passed, failed) counts
    """
    try:
        from tidal_dl_ng.gui.main_window import MainWindow
        from tidal_dl_ng.gui.playlist_membership_mixin import PlaylistMembershipMixin

        if issubclass(MainWindow, PlaylistMembershipMixin):
            print("✅ Check 6: MainWindow has PlaylistMembershipMixin")
            return (1, 0)
    except Exception as e:
        print(f"❌ Check 6: MainWindow inheritance check failed: {e}")
        return (0, 1)
    else:
        print("❌ Check 6: MainWindow does not inherit PlaylistMembershipMixin")
        return (0, 1)


def _check_method_exists() -> tuple[int, int]:
    """Check if init_playlist_membership_manager method exists.

    Returns:
        tuple[int, int]: (passed, failed) counts
    """
    try:
        from tidal_dl_ng.gui.main_window import MainWindow

        if hasattr(MainWindow, "init_playlist_membership_manager"):
            print("✅ Check 7: init_playlist_membership_manager method exists")
            return (1, 0)
    except Exception as e:
        print(f"❌ Check 7: Method check failed: {e}")
        return (0, 1)
    else:
        print("❌ Check 7: init_playlist_membership_manager method not found")
        return (0, 1)


def _check_file_content(
    file_path: Path, search_str: str, check_num: int, success_msg: str, fail_msg: str
) -> tuple[int, int]:
    """Check if a file contains a specific string.

    Args:
        file_path: Path to the file to check
        search_str: String to search for
        check_num: Check number for display
        success_msg: Message to display on success
        fail_msg: Message to display on failure

    Returns:
        tuple[int, int]: (passed, failed) counts
    """
    try:
        with open(file_path) as f:
            content = f.read()
            if search_str in content:
                print(f"✅ Check {check_num}: {success_msg}")
                return (1, 0)
            print(f"❌ Check {check_num}: {fail_msg}")
            return (0, 1)
    except Exception as e:
        print(f"❌ Check {check_num}: File check failed: {e}")
        return (0, 1)


def check_integration() -> int:
    """Verify all components are integrated.

    Returns:
        int: 0 if all checks pass, 1 otherwise
    """
    checks_passed = 0
    checks_failed = 0

    print("🔍 Vérification de l'intégration du Playlist Membership Manager\n")
    print("=" * 70)

    # Run all import checks
    passed, failed = _run_all_import_checks()
    checks_passed += passed
    checks_failed += failed

    # Check 6: MainWindow has PlaylistMembershipMixin
    passed, failed = _check_mainwindow_inheritance()
    checks_passed += passed
    checks_failed += failed

    # Check 7: init_playlist_membership_manager method exists
    passed, failed = _check_method_exists()
    checks_passed += passed
    checks_failed += failed

    # Check 8: TreesResultsMixin has playlists column
    passed, failed = _check_file_content(
        project_root / "tidal_dl_ng" / "gui" / "trees_results.py",
        "child_playlists",
        8,
        "child_playlists column added to TreesResultsMixin",
        "child_playlists column NOT found in TreesResultsMixin",
    )
    checks_passed += passed
    checks_failed += failed

    # Check 9: tidal_session.py calls init_playlist_membership_manager
    passed, failed = _check_file_content(
        project_root / "tidal_dl_ng" / "gui" / "tidal_session.py",
        "init_playlist_membership_manager",
        9,
        "init_playlist_membership_manager called in init_tidal",
        "init_playlist_membership_manager NOT called in init_tidal",
    )
    checks_passed += passed
    checks_failed += failed

    # Check 10: PlaylistMembershipMixin imports PlaylistCellState
    passed, failed = _check_file_content(
        project_root / "tidal_dl_ng" / "gui" / "playlist_membership_mixin.py",
        "PlaylistCellState",
        10,
        "PlaylistCellState imported in mixin",
        "PlaylistCellState NOT imported in mixin",
    )
    checks_passed += passed
    checks_failed += failed

    # Print summary
    print("\n" + "=" * 70)
    print(f"\n📊 Résultat: {checks_passed} ✅  /  {checks_failed} ❌\n")

    if checks_failed == 0:
        print("🎉 INTÉGRATION COMPLÈTE - Tous les checks sont passés!")
        return 0

    print(f"⚠️  {checks_failed} problème(s) détecté(s)")
    return 1


if __name__ == "__main__":
    exit_code = check_integration()
    sys.exit(exit_code)