File size: 2,171 Bytes
1824ea0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Tests for the Gradio web interface."""

import pytest

import stemsplitter.web as web_mod
from stemsplitter.web import create_app, separate_audio


@pytest.fixture(autouse=True)
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