|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Test script to verify WAV conversion feature without breaking existing functionality. |
| 4 | +This validates the implementation at the code level without requiring API calls. |
| 5 | +""" |
| 6 | + |
| 7 | +import asyncio |
| 8 | +import inspect |
| 9 | +from suno_client import SunoClient, SunoAPIError |
| 10 | + |
| 11 | + |
| 12 | +def test_client_methods(): |
| 13 | + """Test that SunoClient has all expected methods.""" |
| 14 | + print("Testing SunoClient methods...") |
| 15 | + |
| 16 | + # Expected methods (existing + new) |
| 17 | + expected_methods = [ |
| 18 | + 'close', |
| 19 | + 'convert_to_wav', |
| 20 | + 'generate_music', |
| 21 | + 'get_credits', |
| 22 | + 'get_music_info', |
| 23 | + 'get_task_status', |
| 24 | + 'get_wav_conversion_status' |
| 25 | + ] |
| 26 | + |
| 27 | + actual_methods = [ |
| 28 | + m for m in dir(SunoClient) |
| 29 | + if not m.startswith('_') and callable(getattr(SunoClient, m)) |
| 30 | + ] |
| 31 | + |
| 32 | + for method in expected_methods: |
| 33 | + if method in actual_methods: |
| 34 | + print(f" ✓ {method} exists") |
| 35 | + else: |
| 36 | + print(f" ✗ {method} MISSING") |
| 37 | + return False |
| 38 | + |
| 39 | + print(f" Total methods: {len(actual_methods)}") |
| 40 | + return True |
| 41 | + |
| 42 | + |
| 43 | +def test_method_signatures(): |
| 44 | + """Test that method signatures are correct.""" |
| 45 | + print("\nTesting method signatures...") |
| 46 | + |
| 47 | + # Test convert_to_wav signature |
| 48 | + sig = inspect.signature(SunoClient.convert_to_wav) |
| 49 | + params = list(sig.parameters.keys()) |
| 50 | + expected_params = ['self', 'audio_id', 'callback_url'] |
| 51 | + |
| 52 | + if params == expected_params: |
| 53 | + print(f" ✓ convert_to_wav signature correct: {params}") |
| 54 | + else: |
| 55 | + print(f" ✗ convert_to_wav signature incorrect. Expected {expected_params}, got {params}") |
| 56 | + return False |
| 57 | + |
| 58 | + # Test get_wav_conversion_status signature |
| 59 | + sig = inspect.signature(SunoClient.get_wav_conversion_status) |
| 60 | + params = list(sig.parameters.keys()) |
| 61 | + expected_params = ['self', 'task_id'] |
| 62 | + |
| 63 | + if params == expected_params: |
| 64 | + print(f" ✓ get_wav_conversion_status signature correct: {params}") |
| 65 | + else: |
| 66 | + print(f" ✗ get_wav_conversion_status signature incorrect. Expected {expected_params}, got {params}") |
| 67 | + return False |
| 68 | + |
| 69 | + return True |
| 70 | + |
| 71 | + |
| 72 | +def test_docstrings(): |
| 73 | + """Test that new methods have proper docstrings.""" |
| 74 | + print("\nTesting docstrings...") |
| 75 | + |
| 76 | + convert_doc = SunoClient.convert_to_wav.__doc__ |
| 77 | + if convert_doc and len(convert_doc.strip()) > 50: |
| 78 | + print(f" ✓ convert_to_wav has comprehensive docstring ({len(convert_doc)} chars)") |
| 79 | + else: |
| 80 | + print(f" ✗ convert_to_wav docstring missing or too short") |
| 81 | + return False |
| 82 | + |
| 83 | + status_doc = SunoClient.get_wav_conversion_status.__doc__ |
| 84 | + if status_doc and len(status_doc.strip()) > 50: |
| 85 | + print(f" ✓ get_wav_conversion_status has comprehensive docstring ({len(status_doc)} chars)") |
| 86 | + else: |
| 87 | + print(f" ✗ get_wav_conversion_status docstring missing or too short") |
| 88 | + return False |
| 89 | + |
| 90 | + return True |
| 91 | + |
| 92 | + |
| 93 | +def test_existing_methods_unchanged(): |
| 94 | + """Test that existing methods still have their original signatures.""" |
| 95 | + print("\nTesting existing methods are unchanged...") |
| 96 | + |
| 97 | + # Check generate_music (most complex method) |
| 98 | + sig = inspect.signature(SunoClient.generate_music) |
| 99 | + params = list(sig.parameters.keys()) |
| 100 | + |
| 101 | + # Must have at least these parameters |
| 102 | + required_params = ['self', 'prompt', 'make_instrumental', 'model_version', 'wait_audio'] |
| 103 | + for param in required_params: |
| 104 | + if param in params: |
| 105 | + print(f" ✓ generate_music has parameter: {param}") |
| 106 | + else: |
| 107 | + print(f" ✗ generate_music missing parameter: {param}") |
| 108 | + return False |
| 109 | + |
| 110 | + # Check get_task_status |
| 111 | + sig = inspect.signature(SunoClient.get_task_status) |
| 112 | + params = list(sig.parameters.keys()) |
| 113 | + expected = ['self', 'task_id'] |
| 114 | + |
| 115 | + if params == expected: |
| 116 | + print(f" ✓ get_task_status unchanged: {params}") |
| 117 | + else: |
| 118 | + print(f" ✗ get_task_status changed. Expected {expected}, got {params}") |
| 119 | + return False |
| 120 | + |
| 121 | + # Check get_music_info |
| 122 | + sig = inspect.signature(SunoClient.get_music_info) |
| 123 | + params = list(sig.parameters.keys()) |
| 124 | + expected = ['self', 'ids'] |
| 125 | + |
| 126 | + if params == expected: |
| 127 | + print(f" ✓ get_music_info unchanged: {params}") |
| 128 | + else: |
| 129 | + print(f" ✗ get_music_info changed. Expected {expected}, got {params}") |
| 130 | + return False |
| 131 | + |
| 132 | + # Check get_credits |
| 133 | + sig = inspect.signature(SunoClient.get_credits) |
| 134 | + params = list(sig.parameters.keys()) |
| 135 | + expected = ['self'] |
| 136 | + |
| 137 | + if params == expected: |
| 138 | + print(f" ✓ get_credits unchanged: {params}") |
| 139 | + else: |
| 140 | + print(f" ✗ get_credits changed. Expected {expected}, got {params}") |
| 141 | + return False |
| 142 | + |
| 143 | + return True |
| 144 | + |
| 145 | + |
| 146 | +def test_error_handling(): |
| 147 | + """Test that error handling is implemented.""" |
| 148 | + print("\nTesting error handling...") |
| 149 | + |
| 150 | + # Check that methods raise appropriate errors for missing params |
| 151 | + async def test_validation(): |
| 152 | + # Mock client with fake API key (won't actually call API) |
| 153 | + import os |
| 154 | + os.environ['SUNO_API_KEY'] = 'test_key_validation' |
| 155 | + client = SunoClient() |
| 156 | + |
| 157 | + try: |
| 158 | + # Test convert_to_wav validation |
| 159 | + try: |
| 160 | + await client.convert_to_wav("", "") |
| 161 | + except ValueError as e: |
| 162 | + print(f" ✓ convert_to_wav validates audio_id: {str(e)}") |
| 163 | + |
| 164 | + try: |
| 165 | + await client.convert_to_wav("test_id", "") |
| 166 | + except ValueError as e: |
| 167 | + print(f" ✓ convert_to_wav validates callback_url: {str(e)}") |
| 168 | + |
| 169 | + # Test get_wav_conversion_status validation |
| 170 | + try: |
| 171 | + await client.get_wav_conversion_status("") |
| 172 | + except ValueError as e: |
| 173 | + print(f" ✓ get_wav_conversion_status validates task_id: {str(e)}") |
| 174 | + |
| 175 | + finally: |
| 176 | + await client.close() |
| 177 | + |
| 178 | + return True |
| 179 | + |
| 180 | + return asyncio.run(test_validation()) |
| 181 | + |
| 182 | + |
| 183 | +def main(): |
| 184 | + """Run all tests.""" |
| 185 | + print("=" * 60) |
| 186 | + print("WAV Conversion Feature - Validation Tests") |
| 187 | + print("=" * 60) |
| 188 | + |
| 189 | + results = [] |
| 190 | + |
| 191 | + # Run tests |
| 192 | + results.append(("Client Methods", test_client_methods())) |
| 193 | + results.append(("Method Signatures", test_method_signatures())) |
| 194 | + results.append(("Docstrings", test_docstrings())) |
| 195 | + results.append(("Existing Methods", test_existing_methods_unchanged())) |
| 196 | + results.append(("Error Handling", test_error_handling())) |
| 197 | + |
| 198 | + # Summary |
| 199 | + print("\n" + "=" * 60) |
| 200 | + print("Test Results Summary") |
| 201 | + print("=" * 60) |
| 202 | + |
| 203 | + passed = sum(1 for _, result in results if result) |
| 204 | + total = len(results) |
| 205 | + |
| 206 | + for test_name, result in results: |
| 207 | + status = "PASS" if result else "FAIL" |
| 208 | + symbol = "✓" if result else "✗" |
| 209 | + print(f"{symbol} {test_name}: {status}") |
| 210 | + |
| 211 | + print(f"\nTotal: {passed}/{total} tests passed") |
| 212 | + |
| 213 | + if passed == total: |
| 214 | + print("\n✓ All tests passed! WAV conversion feature is ready.") |
| 215 | + return 0 |
| 216 | + else: |
| 217 | + print(f"\n✗ {total - passed} test(s) failed!") |
| 218 | + return 1 |
| 219 | + |
| 220 | + |
| 221 | +if __name__ == "__main__": |
| 222 | + exit(main()) |
0 commit comments