Spaces:
No application file
No application file
| """Tests for the Gradio web interface.""" | |
| import pytest | |
| import stemsplitter.web as web_mod | |
| from stemsplitter.web import create_app, separate_audio | |
| def _reset_splitter_singleton(): | |
| """Reset the module-level splitter before each test.""" | |
| web_mod._splitter = None | |
| yield | |
| web_mod._splitter = None | |
| class TestWebApp: | |
| def test_app_creation(self): | |
| """create_app() should return a Gradio Blocks instance.""" | |
| import gradio as gr | |
| app = create_app() | |
| assert isinstance(app, gr.Blocks) | |
| def test_separate_audio_2stem( | |
| self, mock_separator, test_audio_path, env_settings | |
| ): | |
| """Handler should return 4 values (2 real + 2 None) for 2-stem.""" | |
| outputs = separate_audio( | |
| audio_path=str(test_audio_path), | |
| mode="2stem", | |
| output_format="WAV", | |
| ) | |
| assert len(outputs) == 4 | |
| assert outputs[0] is not None | |
| assert outputs[1] is not None | |
| assert outputs[2] is None | |
| assert outputs[3] is None | |
| def test_separate_audio_4stem( | |
| self, mock_separator_4stem, test_audio_path, env_settings | |
| ): | |
| """Handler should return 4 non-None values for 4-stem.""" | |
| outputs = separate_audio( | |
| audio_path=str(test_audio_path), | |
| mode="4stem", | |
| output_format="WAV", | |
| ) | |
| assert len(outputs) == 4 | |
| assert all(o is not None for o in outputs) | |
| def test_separate_audio_no_file(self, env_settings): | |
| """Handler should raise gr.Error when no file uploaded.""" | |
| import gradio as gr | |
| with pytest.raises(gr.Error): | |
| separate_audio( | |
| audio_path="", | |
| mode="2stem", | |
| output_format="WAV", | |
| ) | |
| def test_separate_audio_format_passed( | |
| self, mock_separator, test_audio_path, env_settings | |
| ): | |
| """The output format choice should be forwarded to the splitter.""" | |
| outputs = separate_audio( | |
| audio_path=str(test_audio_path), | |
| mode="2stem", | |
| output_format="FLAC", | |
| ) | |
| assert len(outputs) == 4 | |