Abd756/StemSense
0
1import os2import sys3import pytest4 5# Add the project root to sys.path so we can import core modules6sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))7 8from core.analyzer import AudioAnalyzer9 10def test_audio_analysis():11 """12 Test the AudioAnalyzer on an existing audio file.13 Note: Ensure you have an audio file in data/downloads/ or update the path.14 """15 analyzer = AudioAnalyzer()16 17 # Path to a known test file in your project18 test_file = "e:/Projects/Spotify_Project/data/downloads/Ek Raat - Vilen.mp3"19 20 if not os.path.exists(test_file):21 pytest.skip(f"Test file not found at {test_file}. Please download a song first.")22 23 results = analyzer.analyze(test_file)24 25 # Assertions to ensure we got valid data26 assert results is not None27 assert "bpm" in results28 assert "key" in results29 assert "loudness_lufs" in results30 31 assert isinstance(results["bpm"], float)32 assert results["bpm"] > 033 assert isinstance(results["key"], str)34 assert isinstance(results["loudness_lufs"], float)35 36 print(f"\n--- Test Results for {os.path.basename(test_file)} ---")37 print(f"BPM: {results['bpm']}")38 print(f"Key: {results['key']}")39 print(f"Loudness: {results['loudness_lufs']} LUFS")40 41if __name__ == "__main__":42 # This allows running the test script directly43 test_audio_analysis()44 