Spaces:
Sleeping
Sleeping
Download tests/test_base_tool.py from KeyBow/MediaMaster-v2: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/KeyBow/MediaMaster-v2/resolve/main/tests/test_base_tool.py
- Command line
-
hf download hf://spaces/KeyBow/MediaMaster-v2/tests/test_base_tool.py
-
curl -L -o test_base_tool.py https://huggingface.co/spaces/KeyBow/MediaMaster-v2/resolve/main/tests/test_base_tool.py
2.59 kB
| """ | |
| test_base_tool.py | |
| base_tool.py のユニットテスト | |
| """ | |
| import os | |
| import zipfile | |
| import pytest | |
| from tools.base_tool import get_session_paths, zip_output, BASE_TEMP_DIR | |
| # ------------------------------------------------------------------ # | |
| # get_session_paths | |
| # ------------------------------------------------------------------ # | |
| def test_get_session_paths_returns_three_values(): | |
| """3つのパスを返すことを確認""" | |
| session, input_p, output_p = get_session_paths("test-task-001") | |
| assert session is not None | |
| assert input_p is not None | |
| assert output_p is not None | |
| def test_get_session_paths_structure(tmp_path, monkeypatch): | |
| """パスの構造が正しいことを確認""" | |
| monkeypatch.setattr("tools.base_tool.BASE_TEMP_DIR", str(tmp_path)) | |
| task_id = "test-task-abc" | |
| session, input_p, output_p = get_session_paths(task_id) | |
| assert session == str(tmp_path / task_id) | |
| assert input_p == str(tmp_path / task_id / "input") | |
| assert output_p == str(tmp_path / task_id / "output") | |
| def test_get_session_paths_creates_output_dir(tmp_path, monkeypatch): | |
| """output ディレクトリが自動作成されることを確認""" | |
| monkeypatch.setattr("tools.base_tool.BASE_TEMP_DIR", str(tmp_path)) | |
| _, _, output_p = get_session_paths("test-task-xyz") | |
| assert os.path.isdir(output_p) | |
| # ------------------------------------------------------------------ # | |
| # zip_output | |
| # ------------------------------------------------------------------ # | |
| def test_zip_output_creates_zip(tmp_path): | |
| """result.zip が作成されることを確認""" | |
| session_path = tmp_path / "session" | |
| output_path = tmp_path / "session" / "output" | |
| session_path.mkdir() | |
| output_path.mkdir() | |
| # ダミーファイルを出力ディレクトリに作成 | |
| (output_path / "file1.txt").write_text("hello") | |
| (output_path / "file2.txt").write_text("world") | |
| zip_path = zip_output(str(session_path), str(output_path)) | |
| assert os.path.isfile(zip_path) | |
| assert zip_path.endswith("result.zip") | |
| def test_zip_output_contains_files(tmp_path): | |
| """ZIP の中身が正しいことを確認""" | |
| session_path = tmp_path / "session" | |
| output_path = tmp_path / "session" / "output" | |
| session_path.mkdir() | |
| output_path.mkdir() | |
| (output_path / "a.txt").write_text("aaa") | |
| (output_path / "b.txt").write_text("bbb") | |
| zip_path = zip_output(str(session_path), str(output_path)) | |
| with zipfile.ZipFile(zip_path, "r") as z: | |
| names = z.namelist() | |
| assert "a.txt" in names | |
| assert "b.txt" in names | |