Skip to content

Commit f85483f

Browse files
committed
Fixed CLI syntax error and tests
1 parent e02f958 commit f85483f

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

audio_separator/utils/cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def main():
4242
download_model_only_help = "Download a single model file only, without performing separation."
4343

4444
io_params = parser.add_argument_group("Separation I/O Params")
45-
io_params.add_argument("-m", "--model_filename", default="model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt", help=model_filename_help)
45+
io_params.add_argument("-m", "--model_filename", default="model_bs_roformer_ep_317_sdr_12.9755.yaml", help=model_filename_help)
4646
io_params.add_argument("--output_format", default="FLAC", help=output_format_help)
4747
io_params.add_argument("--output_bitrate", default=None, help=output_bitrate_help)
4848
io_params.add_argument("--output_dir", default=None, help=output_dir_help)
@@ -151,7 +151,7 @@ def main():
151151
parser.print_help()
152152
sys.exit(1)
153153

154-
logger.info(f"Separator version {package_version} beginning with input file(s): {", ".join(args.audio_files)}")
154+
logger.info(f"Separator version {package_version} beginning with input file(s): {', '.join(args.audio_files)}")
155155

156156
separator = Separator(
157157
log_formatter=log_formatter,

tests/unit/test_cli.py

+28-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from audio_separator.utils.cli import main
44
import subprocess
55
from unittest import mock
6-
from unittest.mock import patch, MagicMock
6+
from unittest.mock import patch, MagicMock, mock_open
77

88

99
# Common fixture for expected arguments
@@ -51,16 +51,33 @@ def test_cli_no_args(capsys):
5151

5252

5353
# Test with multiple filename arguments
54-
def test_cli_multiple_filenames(capsys):
54+
def test_cli_multiple_filenames():
5555
test_args = ["cli.py", "test1.mp3", "test2.mp3"]
56-
with patch("sys.argv", test_args):
57-
# Expecting the application to raise a SystemExit due to unrecognized arguments
58-
with pytest.raises(SystemExit):
59-
main()
60-
captured = capsys.readouterr()
6156

62-
# Check if the correct error message is displayed
63-
assert "unrecognized arguments" in captured.err
57+
# Mock the open function to prevent actual file operations
58+
mock_file = mock_open()
59+
60+
# Create a mock logger
61+
mock_logger = MagicMock()
62+
63+
# Patch multiple functions to prevent actual file operations and separations
64+
with patch("sys.argv", test_args), patch("builtins.open", mock_file), patch("audio_separator.separator.Separator.separate") as mock_separate, patch(
65+
"audio_separator.separator.Separator.load_model"
66+
), patch("logging.getLogger", return_value=mock_logger):
67+
68+
# Mock the separate method to return some dummy output
69+
mock_separate.return_value = ["output_file1.mp3", "output_file2.mp3"]
70+
71+
# Call the main function
72+
main()
73+
74+
# Check if separate was called twice (once for each input file)
75+
assert mock_separate.call_count == 2
76+
77+
# Check if the logger captured information about both files
78+
log_messages = [call[0][0] for call in mock_logger.info.call_args_list]
79+
assert any("test1.mp3" in msg and "test2.mp3" in msg for msg in log_messages)
80+
assert any("Separation complete" in msg for msg in log_messages)
6481

6582

6683
# Test the CLI with a specific audio file
@@ -156,6 +173,7 @@ def test_cli_normalization_threshold_argument(common_expected_args):
156173
# Assertions
157174
mock_separator.assert_called_once_with(**expected_args)
158175

176+
159177
# Test using normalization_threshold argument
160178
def test_cli_amplification_threshold_argument(common_expected_args):
161179
test_args = ["cli.py", "test_audio.mp3", "--amplification=0.75"]
@@ -172,6 +190,7 @@ def test_cli_amplification_threshold_argument(common_expected_args):
172190
# Assertions
173191
mock_separator.assert_called_once_with(**expected_args)
174192

193+
175194
# Test using single stem argument
176195
def test_cli_single_stem_argument(common_expected_args):
177196
test_args = ["cli.py", "test_audio.mp3", "--single_stem=instrumental"]

0 commit comments

Comments
 (0)