Skip to content

Commit c24a217

Browse files
WEIFENG2333claudehappy-otter
committed
Fix cross-platform test failures
- test_context_manager_init: use tempfile instead of hardcoded /tmp - test_get_python_path_unix: use os.path.join for path separators - test_rpc_load_model_already_loaded: mock funasr import Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
1 parent c237d29 commit c24a217

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

tests/test_client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ def test_connection_error():
156156

157157

158158
def test_context_manager_init():
159-
c = FunASR(runtime_dir="/tmp/test_funasr")
160-
assert c.runtime_dir == Path("/tmp/test_funasr")
161-
assert c.port == 0
162-
assert c.host == "127.0.0.1"
159+
with tempfile.TemporaryDirectory() as tmpdir:
160+
test_dir = Path(tmpdir) / "test_funasr"
161+
c = FunASR(runtime_dir=str(test_dir))
162+
assert c.runtime_dir == test_dir.resolve()
163+
assert c.port == 0
164+
assert c.host == "127.0.0.1"
163165

164166

165167
def test_is_running_no_process():

tests/test_installer.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ def test_get_uv_path_not_found():
5050

5151

5252
def test_get_python_path_unix():
53-
with patch("platform.system", return_value="Linux"):
54-
installer = Installer("/opt/funasr")
55-
path = installer.get_python_path()
56-
assert path.endswith("bin/python")
57-
assert "/opt/funasr/" in path or "funasr" in path
53+
with tempfile.TemporaryDirectory() as tmpdir:
54+
with patch("platform.system", return_value="Linux"):
55+
installer = Installer(tmpdir)
56+
path = installer.get_python_path()
57+
assert path.endswith(os.path.join("bin", "python"))
5858

5959

6060
def test_get_python_path_windows():
61-
with patch("platform.system", return_value="Windows"):
62-
installer = Installer("C:\\funasr")
63-
path = installer.get_python_path()
64-
assert "Scripts" in path
65-
assert path.endswith("python.exe")
61+
with tempfile.TemporaryDirectory() as tmpdir:
62+
with patch("platform.system", return_value="Windows"):
63+
installer = Installer(tmpdir)
64+
path = installer.get_python_path()
65+
assert path.endswith(os.path.join("Scripts", "python.exe"))
6666

6767

6868
def test_create_runtime_dir():

tests/test_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def test_rpc_load_model_already_loaded():
8787
server._models["m1"] = mock_model
8888
server._model_kwargs["m1"] = {"model": "test"}
8989

90-
result = server.rpc_load_model({"model": "test", "name": "m1"})
90+
with patch.dict("sys.modules", {"funasr": MagicMock()}):
91+
result = server.rpc_load_model({"model": "test", "name": "m1"})
9192
assert result["status"] == "already_loaded"
9293

9394

0 commit comments

Comments
 (0)