Skip to content

Commit 8688f81

Browse files
KYBvWHxWtbag999claude
authored
fix: resolve ruff lint errors in new test files (#25)
- Remove unused imports (F401) - Fix import sorting (I001) - Combine with statements (SIM117) - Move inline imports to top level Co-authored-by: gss <tbag9199@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 130bb92 commit 8688f81

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

tests/test_config.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def test_load_config_returns_defaults_when_no_file(tmp_path):
3232
def test_save_and_load_config(tmp_path):
3333
config_file = tmp_path / "config.yaml"
3434
config_dir = tmp_path
35-
with patch("narrator_ai.config.CONFIG_FILE", config_file), \
36-
patch("narrator_ai.config.CONFIG_DIR", config_dir):
35+
with patch("narrator_ai.config.CONFIG_FILE", config_file), patch("narrator_ai.config.CONFIG_DIR", config_dir):
3736
save_config({"server": "https://test.example.com", "app_key": "test-key"})
3837
cfg = load_config()
3938
assert cfg["server"] == "https://test.example.com"
@@ -52,8 +51,7 @@ def test_get_server_strips_trailing_slash():
5251

5352

5453
def test_get_server_raises_when_not_configured(tmp_path):
55-
with patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"), \
56-
patch.dict(os.environ, {}, clear=True):
54+
with patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"), patch.dict(os.environ, {}, clear=True):
5755
# DEFAULT_CONFIG has server set, so this won't raise
5856
server = get_server()
5957
assert server == DEFAULT_CONFIG["server"].rstrip("/")
@@ -65,10 +63,12 @@ def test_get_app_key_from_env():
6563

6664

6765
def test_get_app_key_raises_when_not_configured(tmp_path):
68-
with patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"), \
69-
patch.dict(os.environ, {}, clear=True):
70-
with pytest.raises(SystemExit):
71-
get_app_key()
66+
with (
67+
patch("narrator_ai.config.CONFIG_FILE", tmp_path / "nonexistent.yaml"),
68+
patch.dict(os.environ, {}, clear=True),
69+
pytest.raises(SystemExit),
70+
):
71+
get_app_key()
7272

7373

7474
def test_get_timeout_from_env():
@@ -77,6 +77,5 @@ def test_get_timeout_from_env():
7777

7878

7979
def test_get_timeout_default():
80-
with patch.dict(os.environ, {}, clear=True), \
81-
patch("narrator_ai.config.CONFIG_FILE", Path("/nonexistent")):
80+
with patch.dict(os.environ, {}, clear=True), patch("narrator_ai.config.CONFIG_FILE", Path("/nonexistent")):
8281
assert get_timeout() == 30

tests/test_dubbing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests for narrator_ai.commands.dubbing — voice list filtering logic."""
22

3+
import json
4+
35
from typer.testing import CliRunner
46

57
from narrator_ai.commands.dubbing import DUBBING_LIST, app
@@ -22,7 +24,6 @@ def test_dubbing_list_has_required_fields():
2224
def test_dubbing_list_json_output():
2325
result = runner.invoke(app, ["list", "--json"])
2426
assert result.exit_code == 0
25-
import json
2627
data = json.loads(result.output)
2728
assert isinstance(data, list)
2829
assert len(data) > 0
@@ -31,23 +32,20 @@ def test_dubbing_list_json_output():
3132
def test_dubbing_list_filter_by_lang():
3233
result = runner.invoke(app, ["list", "--lang", "英语", "--json"])
3334
assert result.exit_code == 0
34-
import json
3535
data = json.loads(result.output)
3636
assert all(v["type"] == "英语" for v in data)
3737

3838

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

4645

4746
def test_dubbing_languages_json():
4847
result = runner.invoke(app, ["languages", "--json"])
4948
assert result.exit_code == 0
50-
import json
5149
data = json.loads(result.output)
5250
assert isinstance(data, list)
5351
assert any(item["language"] == "普通话" for item in data)
@@ -56,7 +54,6 @@ def test_dubbing_languages_json():
5654
def test_dubbing_tags_json():
5755
result = runner.invoke(app, ["tags", "--json"])
5856
assert result.exit_code == 0
59-
import json
6057
data = json.loads(result.output)
6158
assert isinstance(data, list)
6259
assert len(data) > 0

tests/test_output.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""Tests for narrator_ai.output module."""
22

33
import json
4-
from io import StringIO
5-
from unittest.mock import patch
64

7-
from narrator_ai.output import print_json, print_error, print_success, print_info
5+
from narrator_ai.output import print_error, print_info, print_json, print_success
86

97

108
def test_print_json_dict(capsys):

0 commit comments

Comments
 (0)