Skip to content

Commit 36f468d

Browse files
committed
Removed CLI direct entrypoint, added couple more unit tests for 100 coverage of CLI
1 parent 5631a71 commit 36f468d

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

audio_separator/utils/cli.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
import logging
44
from importlib import metadata
55

6-
def get_package_distribution(logger, package_name):
7-
try:
8-
return metadata.distribution(package_name)
9-
except metadata.PackageNotFoundError:
10-
logger.debug(f"Python package: {package_name} not installed")
11-
return None
126

137
def main():
148
logger = logging.getLogger(__name__)
@@ -24,7 +18,7 @@ def main():
2418

2519
parser.add_argument("audio_file", nargs="?", help="The audio file path to separate, in any common format.", default=argparse.SUPPRESS)
2620

27-
package_version = get_package_distribution(logger, "audio-separator").version
21+
package_version = metadata.distribution("audio-separator").version
2822
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {package_version}")
2923

3024
parser.add_argument(
@@ -155,7 +149,3 @@ def main():
155149
output_files = separator.separate(args.audio_file)
156150

157151
logger.info(f"Separation complete! Output file(s): {' '.join(output_files)}")
158-
159-
160-
if __name__ == "__main__":
161-
main()

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "audio-separator"
7-
version = "0.13.0"
7+
version = "0.13.1"
88
description = "Easy to use vocal separation, using MDX-Net models from UVR trained by @Anjok07"
99
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
1010
license = "MIT"

tests/unit/test_cli.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import logging
33
from audio_separator.utils.cli import main
4+
import subprocess
45
from unittest import mock
56
from unittest.mock import patch, MagicMock
67

@@ -26,13 +27,24 @@ def common_expected_args():
2627
}
2728

2829

30+
# Test the CLI with version argument using subprocess
31+
def test_cli_version_subprocess():
32+
# Run the CLI script with the '--version' argument
33+
result = subprocess.run(["poetry", "run", "audio-separator", "--version"], capture_output=True, text=True)
34+
assert result.returncode == 0
35+
assert "audio-separator" in result.stdout
36+
37+
# Test with the short version flag '-v'
38+
result = subprocess.run(["poetry", "run", "audio-separator", "-v"], capture_output=True, text=True)
39+
assert result.returncode == 0
40+
assert "audio-separator" in result.stdout
41+
42+
2943
# Test the CLI with no arguments
3044
def test_cli_no_args(capsys):
31-
with patch("sys.argv", ["cli.py"]), pytest.raises(SystemExit):
32-
# Call the main function in cli.py
33-
main()
34-
captured = capsys.readouterr()
35-
assert "usage:" in captured.out
45+
result = subprocess.run(["poetry", "run", "audio-separator"], capture_output=True, text=True)
46+
assert result.returncode == 1
47+
assert "usage:" in result.stdout
3648

3749

3850
# Test with multiple filename arguments

0 commit comments

Comments
 (0)