Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def test_load_config_returns_defaults_when_no_file(tmp_path):
def test_save_and_load_config(tmp_path):
config_file = tmp_path / "config.yaml"
config_dir = tmp_path
with patch("narrator_ai.config.CONFIG_FILE", config_file), \
patch("narrator_ai.config.CONFIG_DIR", config_dir):
with patch("narrator_ai.config.CONFIG_FILE", config_file), patch("narrator_ai.config.CONFIG_DIR", config_dir):
save_config({"server": "https://test.example.com", "app_key": "test-key"})
cfg = load_config()
assert cfg["server"] == "https://test.example.com"
Expand All @@ -52,8 +51,7 @@ def test_get_server_strips_trailing_slash():


def test_get_server_raises_when_not_configured(tmp_path):
with patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"), \
patch.dict(os.environ, {}, clear=True):
with patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"), patch.dict(os.environ, {}, clear=True):
# DEFAULT_CONFIG has server set, so this won't raise
server = get_server()
assert server == DEFAULT_CONFIG["server"].rstrip("/")
Comment on lines 53 to 57
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_get_server_raises_when_not_configured does not exercise the raising path: get_server() cannot raise here because DEFAULT_CONFIG["server"] is non-empty and load_config() falls back to it when the config file is missing. This makes the test name/intent misleading. Consider either renaming the test to reflect that it asserts the default server is returned, or change the setup to actually cover the SystemExit branch (e.g., patch DEFAULT_CONFIG / load_config() so server is empty and then assert pytest.raises(SystemExit)).

Copilot uses AI. Check for mistakes.
Expand All @@ -65,10 +63,12 @@ def test_get_app_key_from_env():


def test_get_app_key_raises_when_not_configured(tmp_path):
with patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"), \
patch.dict(os.environ, {}, clear=True):
with pytest.raises(SystemExit):
get_app_key()
with (
patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"),
patch.dict(os.environ, {}, clear=True),
pytest.raises(SystemExit),
):
get_app_key()


def test_get_timeout_from_env():
Expand All @@ -77,6 +77,5 @@ def test_get_timeout_from_env():


def test_get_timeout_default():
with patch.dict(os.environ, {}, clear=True), \
patch("narrator_ai.config.CONFIG_FILE", Path("/nonexistent")):
with patch.dict(os.environ, {}, clear=True), patch("narrator_ai.config.CONFIG_FILE", Path("/nonexistent")):
assert get_timeout() == 30
7 changes: 2 additions & 5 deletions tests/test_dubbing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for narrator_ai.commands.dubbing — voice list filtering logic."""

import json

from typer.testing import CliRunner

from narrator_ai.commands.dubbing import DUBBING_LIST, app
Expand All @@ -22,7 +24,6 @@ def test_dubbing_list_has_required_fields():
def test_dubbing_list_json_output():
result = runner.invoke(app, ["list", "--json"])
assert result.exit_code == 0
import json
data = json.loads(result.output)
assert isinstance(data, list)
assert len(data) > 0
Expand All @@ -31,23 +32,20 @@ def test_dubbing_list_json_output():
def test_dubbing_list_filter_by_lang():
result = runner.invoke(app, ["list", "--lang", "英语", "--json"])
assert result.exit_code == 0
import json
data = json.loads(result.output)
assert all(v["type"] == "英语" for v in data)


def test_dubbing_list_filter_by_tag():
result = runner.invoke(app, ["list", "--tag", "通用男声", "--json"])
assert result.exit_code == 0
import json
data = json.loads(result.output)
assert all(v["tag"] == "通用男声" for v in data)


def test_dubbing_languages_json():
result = runner.invoke(app, ["languages", "--json"])
assert result.exit_code == 0
import json
data = json.loads(result.output)
assert isinstance(data, list)
assert any(item["language"] == "普通话" for item in data)
Expand All @@ -56,7 +54,6 @@ def test_dubbing_languages_json():
def test_dubbing_tags_json():
result = runner.invoke(app, ["tags", "--json"])
assert result.exit_code == 0
import json
data = json.loads(result.output)
assert isinstance(data, list)
assert len(data) > 0
4 changes: 1 addition & 3 deletions tests/test_output.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""Tests for narrator_ai.output module."""

import json
from io import StringIO
from unittest.mock import patch

from narrator_ai.output import print_json, print_error, print_success, print_info
from narrator_ai.output import print_error, print_info, print_json, print_success


def test_print_json_dict(capsys):
Expand Down
Loading