refactor: 统一格式化代码中的多行列表与函数调用
对多处代码进行了统一的多行列表和函数调用进行格式化调整,包括将单行代码拆分为多行以提升可读性。
This commit is contained in:
+25
-33
@@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -46,8 +46,7 @@ class TestSyncPyprojectConfig:
|
||||
|
||||
def test_sync_pyproject_config_creates_file(self, tmp_path: Path) -> None:
|
||||
"""Should create pyproject.toml if it doesn't exist."""
|
||||
with patch.object(Path, "exists", return_value=False), \
|
||||
patch.object(Path, "write_text") as mock_write:
|
||||
with patch.object(Path, "exists", return_value=False), patch.object(Path, "write_text") as mock_write:
|
||||
autofmt.sync_pyproject_config(tmp_path)
|
||||
# Should create pyproject.toml
|
||||
assert mock_write.called
|
||||
@@ -57,9 +56,9 @@ class TestSyncPyprojectConfig:
|
||||
pyproject = tmp_path / "pyproject.toml"
|
||||
pyproject.write_text("[tool.ruff]\n")
|
||||
|
||||
with patch.object(Path, "exists", return_value=True), \
|
||||
patch.object(Path, "read_text", return_value="[tool.ruff]\n"), \
|
||||
patch.object(Path, "write_text") as mock_write:
|
||||
with patch.object(Path, "exists", return_value=True), patch.object(
|
||||
Path, "read_text", return_value="[tool.ruff]\n"
|
||||
), patch.object(Path, "write_text") as mock_write:
|
||||
autofmt.sync_pyproject_config(tmp_path)
|
||||
# Should update pyproject.toml
|
||||
assert mock_write.called
|
||||
@@ -96,8 +95,7 @@ class TestMain:
|
||||
|
||||
def test_main_fmt_default_target(self) -> None:
|
||||
"""main() should handle fmt with default target."""
|
||||
with patch("sys.argv", ["autofmt", "fmt"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["autofmt", "fmt"]), patch.object(px, "run") as mock_run:
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
graph = mock_run.call_args[0][0]
|
||||
@@ -109,8 +107,7 @@ class TestMain:
|
||||
|
||||
def test_main_fmt_custom_target(self) -> None:
|
||||
"""main() should handle fmt with custom target."""
|
||||
with patch("sys.argv", ["autofmt", "fmt", "--target", "src"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["autofmt", "fmt", "--target", "src"]), patch.object(px, "run") as mock_run:
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
graph = mock_run.call_args[0][0]
|
||||
@@ -122,8 +119,7 @@ class TestMain:
|
||||
|
||||
def test_main_lint_default_target(self) -> None:
|
||||
"""main() should handle lint with default target."""
|
||||
with patch("sys.argv", ["autofmt", "lint"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["autofmt", "lint"]), patch.object(px, "run") as mock_run:
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
graph = mock_run.call_args[0][0]
|
||||
@@ -134,8 +130,7 @@ class TestMain:
|
||||
|
||||
def test_main_lint_with_fix(self) -> None:
|
||||
"""main() should handle lint with fix."""
|
||||
with patch("sys.argv", ["autofmt", "lint", "--fix"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["autofmt", "lint", "--fix"]), patch.object(px, "run") as mock_run:
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
graph = mock_run.call_args[0][0]
|
||||
@@ -148,40 +143,39 @@ class TestMain:
|
||||
|
||||
def test_main_lint_custom_target(self) -> None:
|
||||
"""main() should handle lint with custom target."""
|
||||
with patch("sys.argv", ["autofmt", "lint", "--target", "src"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["autofmt", "lint", "--target", "src"]), patch.object(px, "run") as mock_run:
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_doc_default_root(self) -> None:
|
||||
"""main() should handle doc with default root."""
|
||||
with patch("sys.argv", ["autofmt", "doc"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(autofmt, "auto_add_docstrings"):
|
||||
with patch("sys.argv", ["autofmt", "doc"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
autofmt, "auto_add_docstrings"
|
||||
):
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_doc_custom_root(self) -> None:
|
||||
"""main() should handle doc with custom root."""
|
||||
with patch("sys.argv", ["autofmt", "doc", "--root-dir", "src"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(autofmt, "auto_add_docstrings"):
|
||||
with patch("sys.argv", ["autofmt", "doc", "--root-dir", "src"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(autofmt, "auto_add_docstrings"):
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_sync_default_root(self) -> None:
|
||||
"""main() should handle sync with default root."""
|
||||
with patch("sys.argv", ["autofmt", "sync"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(autofmt, "sync_pyproject_config"):
|
||||
with patch("sys.argv", ["autofmt", "sync"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
autofmt, "sync_pyproject_config"
|
||||
):
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_sync_custom_root(self) -> None:
|
||||
"""main() should handle sync with custom root."""
|
||||
with patch("sys.argv", ["autofmt", "sync", "--root-dir", "src"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(autofmt, "sync_pyproject_config"):
|
||||
with patch("sys.argv", ["autofmt", "sync", "--root-dir", "src"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(autofmt, "sync_pyproject_config"):
|
||||
autofmt.main()
|
||||
assert mock_run.called
|
||||
|
||||
@@ -193,8 +187,7 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_specs_with_verbose(self) -> None:
|
||||
"""main() should create TaskSpecs with verbose=True."""
|
||||
with patch("sys.argv", ["autofmt", "fmt"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["autofmt", "fmt"]), patch.object(px, "run") as mock_run:
|
||||
autofmt.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
specs = graph.all_specs()
|
||||
@@ -203,7 +196,6 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["autofmt", "fmt"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["autofmt", "fmt"]), patch.object(px, "run") as mock_run:
|
||||
autofmt.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import pyflowx as px
|
||||
from pyflowx.cli import clearscreen
|
||||
from pyflowx.conditions import Constants
|
||||
|
||||
@@ -26,8 +25,7 @@ class TestClearScreen:
|
||||
|
||||
def test_clear_screen_linux(self) -> None:
|
||||
"""Should clear screen on Linux."""
|
||||
with patch.object(Constants, "IS_WINDOWS", False), \
|
||||
patch("os.system") as mock_system:
|
||||
with patch.object(Constants, "IS_WINDOWS", False), patch("os.system") as mock_system:
|
||||
clearscreen.clear_screen()
|
||||
assert mock_system.called
|
||||
|
||||
@@ -103,4 +101,4 @@ class TestMain:
|
||||
"""main() with no args should show help and exit."""
|
||||
with patch("sys.argv", ["clearscreen"]), pytest.raises(SystemExit) as exc_info:
|
||||
clearscreen.main()
|
||||
assert exc_info.value.code == 1
|
||||
assert exc_info.value.code == 1
|
||||
|
||||
+16
-17
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -58,25 +57,25 @@ class TestMain:
|
||||
|
||||
def test_main_mirror_tsinghua(self) -> None:
|
||||
"""main() should handle mirror tsinghua command."""
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envpy, "set_pip_mirror"):
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envpy, "set_pip_mirror"
|
||||
):
|
||||
envpy.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_mirror_aliyun(self) -> None:
|
||||
"""main() should handle mirror aliyun command."""
|
||||
with patch("sys.argv", ["envpy", "mirror", "aliyun"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envpy, "set_pip_mirror"):
|
||||
with patch("sys.argv", ["envpy", "mirror", "aliyun"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envpy, "set_pip_mirror"
|
||||
):
|
||||
envpy.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_mirror_with_token(self) -> None:
|
||||
"""main() should handle mirror with token."""
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua", "--token", "test_token"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envpy, "set_pip_mirror"):
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua", "--token", "test_token"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(envpy, "set_pip_mirror"):
|
||||
envpy.main()
|
||||
assert mock_run.called
|
||||
|
||||
@@ -94,9 +93,9 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_spec_with_correct_name(self) -> None:
|
||||
"""main() should create TaskSpec with correct name."""
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envpy, "set_pip_mirror"):
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envpy, "set_pip_mirror"
|
||||
):
|
||||
envpy.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
task_names = list(graph.all_specs().keys())
|
||||
@@ -104,8 +103,8 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envpy, "set_pip_mirror"):
|
||||
with patch("sys.argv", ["envpy", "mirror", "tsinghua"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envpy, "set_pip_mirror"
|
||||
):
|
||||
envpy.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
@@ -7,7 +7,6 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import pyflowx as px
|
||||
from pyflowx.cli import envqt
|
||||
|
||||
|
||||
@@ -47,4 +46,4 @@ class TestMain:
|
||||
"""main() with no args should show help and exit."""
|
||||
with patch("sys.argv", ["envqt"]), pytest.raises(SystemExit) as exc_info:
|
||||
envqt.main()
|
||||
assert exc_info.value.code == 1
|
||||
assert exc_info.value.code == 1
|
||||
|
||||
+26
-31
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -97,9 +97,8 @@ class TestInstallRust:
|
||||
|
||||
def test_install_rust_file_not_found(self) -> None:
|
||||
"""Should raise FileNotFoundError when rustup not found."""
|
||||
with patch("subprocess.run", side_effect=FileNotFoundError):
|
||||
with pytest.raises(FileNotFoundError):
|
||||
envrs.install_rust("stable")
|
||||
with patch("subprocess.run", side_effect=FileNotFoundError), pytest.raises(FileNotFoundError):
|
||||
envrs.install_rust("stable")
|
||||
|
||||
def test_install_rust_prints_message(self, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
"""Should print installation message."""
|
||||
@@ -118,61 +117,57 @@ class TestMain:
|
||||
|
||||
def test_main_mirror_aliyun(self) -> None:
|
||||
"""main() should handle mirror aliyun command."""
|
||||
with patch("sys.argv", ["envrs", "mirror", "aliyun"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envrs, "set_rust_mirror"):
|
||||
with patch("sys.argv", ["envrs", "mirror", "aliyun"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envrs, "set_rust_mirror"
|
||||
):
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_mirror_ustc(self) -> None:
|
||||
"""main() should handle mirror ustc command."""
|
||||
with patch("sys.argv", ["envrs", "mirror", "ustc"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envrs, "set_rust_mirror"):
|
||||
with patch("sys.argv", ["envrs", "mirror", "ustc"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envrs, "set_rust_mirror"
|
||||
):
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_mirror_tsinghua(self) -> None:
|
||||
"""main() should handle mirror tsinghua command."""
|
||||
with patch("sys.argv", ["envrs", "mirror", "tsinghua"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envrs, "set_rust_mirror"):
|
||||
with patch("sys.argv", ["envrs", "mirror", "tsinghua"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envrs, "set_rust_mirror"
|
||||
):
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_mirror_default(self) -> None:
|
||||
"""main() should use default mirror when not specified."""
|
||||
with patch("sys.argv", ["envrs", "mirror"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envrs, "set_rust_mirror"):
|
||||
with patch("sys.argv", ["envrs", "mirror"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envrs, "set_rust_mirror"
|
||||
):
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_install_stable(self) -> None:
|
||||
"""main() should handle install stable command."""
|
||||
with patch("sys.argv", ["envrs", "install", "stable"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["envrs", "install", "stable"]), patch.object(px, "run") as mock_run:
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_install_nightly(self) -> None:
|
||||
"""main() should handle install nightly command."""
|
||||
with patch("sys.argv", ["envrs", "install", "nightly"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["envrs", "install", "nightly"]), patch.object(px, "run") as mock_run:
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_install_beta(self) -> None:
|
||||
"""main() should handle install beta command."""
|
||||
with patch("sys.argv", ["envrs", "install", "beta"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["envrs", "install", "beta"]), patch.object(px, "run") as mock_run:
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_install_default(self) -> None:
|
||||
"""main() should use default version when not specified."""
|
||||
with patch("sys.argv", ["envrs", "install"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["envrs", "install"]), patch.object(px, "run") as mock_run:
|
||||
envrs.main()
|
||||
assert mock_run.called
|
||||
|
||||
@@ -196,9 +191,9 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_spec_with_verbose(self) -> None:
|
||||
"""main() should create TaskSpec with verbose=True."""
|
||||
with patch("sys.argv", ["envrs", "mirror", "aliyun"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envrs, "set_rust_mirror"):
|
||||
with patch("sys.argv", ["envrs", "mirror", "aliyun"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envrs, "set_rust_mirror"
|
||||
):
|
||||
envrs.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
specs = graph.all_specs()
|
||||
@@ -207,8 +202,8 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["envrs", "mirror", "aliyun"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(envrs, "set_rust_mirror"):
|
||||
with patch("sys.argv", ["envrs", "mirror", "aliyun"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
envrs, "set_rust_mirror"
|
||||
):
|
||||
envrs.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
+19
-19
@@ -58,33 +58,33 @@ class TestMain:
|
||||
|
||||
def test_main_add_single_file(self) -> None:
|
||||
"""main() should handle add command with single file."""
|
||||
with patch("sys.argv", ["filedate", "add", "test.txt"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(filedate, "process_files_date"):
|
||||
with patch("sys.argv", ["filedate", "add", "test.txt"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
filedate, "process_files_date"
|
||||
):
|
||||
filedate.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_add_multiple_files(self) -> None:
|
||||
"""main() should handle add command with multiple files."""
|
||||
with patch("sys.argv", ["filedate", "add", "test1.txt", "test2.txt", "test3.txt"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(filedate, "process_files_date"):
|
||||
with patch("sys.argv", ["filedate", "add", "test1.txt", "test2.txt", "test3.txt"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(filedate, "process_files_date"):
|
||||
filedate.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_clear_single_file(self) -> None:
|
||||
"""main() should handle clear command with single file."""
|
||||
with patch("sys.argv", ["filedate", "clear", "test.txt"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(filedate, "process_files_date"):
|
||||
with patch("sys.argv", ["filedate", "clear", "test.txt"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
filedate, "process_files_date"
|
||||
):
|
||||
filedate.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_clear_multiple_files(self) -> None:
|
||||
"""main() should handle clear command with multiple files."""
|
||||
with patch("sys.argv", ["filedate", "clear", "test1.txt", "test2.txt", "test3.txt"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(filedate, "process_files_date"):
|
||||
with patch("sys.argv", ["filedate", "clear", "test1.txt", "test2.txt", "test3.txt"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(filedate, "process_files_date"):
|
||||
filedate.main()
|
||||
assert mock_run.called
|
||||
|
||||
@@ -96,9 +96,9 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_spec_with_correct_name(self) -> None:
|
||||
"""main() should create TaskSpec with correct name."""
|
||||
with patch("sys.argv", ["filedate", "add", "test.txt"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(filedate, "process_files_date"):
|
||||
with patch("sys.argv", ["filedate", "add", "test.txt"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
filedate, "process_files_date"
|
||||
):
|
||||
filedate.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
task_names = list(graph.all_specs().keys())
|
||||
@@ -106,8 +106,8 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["filedate", "add", "test.txt"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(filedate, "process_files_date"):
|
||||
with patch("sys.argv", ["filedate", "add", "test.txt"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
filedate, "process_files_date"
|
||||
):
|
||||
filedate.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
@@ -7,7 +7,6 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import pyflowx as px
|
||||
from pyflowx.cli import folderback
|
||||
|
||||
|
||||
@@ -75,4 +74,4 @@ class TestMain:
|
||||
"""main() with no args should show help and exit."""
|
||||
with patch("sys.argv", ["folderback"]), pytest.raises(SystemExit) as exc_info:
|
||||
folderback.main()
|
||||
assert exc_info.value.code == 1
|
||||
assert exc_info.value.code == 1
|
||||
|
||||
@@ -7,7 +7,6 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import pyflowx as px
|
||||
from pyflowx.cli import folderzip
|
||||
|
||||
|
||||
@@ -69,4 +68,4 @@ class TestMain:
|
||||
"""main() with no args should show help and exit."""
|
||||
with patch("sys.argv", ["folderzip"]), pytest.raises(SystemExit) as exc_info:
|
||||
folderzip.main()
|
||||
assert exc_info.value.code == 1
|
||||
assert exc_info.value.code == 1
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import pyflowx as px
|
||||
from pyflowx.cli import gittool
|
||||
|
||||
|
||||
@@ -56,4 +54,4 @@ class TestMain:
|
||||
"""main() with no args should show help and exit."""
|
||||
with patch("sys.argv", ["gittool"]), pytest.raises(SystemExit) as exc_info:
|
||||
gittool.main()
|
||||
assert exc_info.value.code == 1
|
||||
assert exc_info.value.code == 1
|
||||
|
||||
+26
-28
@@ -2,8 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -44,8 +43,7 @@ class TestRunLsDyna:
|
||||
|
||||
def test_run_ls_dyna_linux_command(self) -> None:
|
||||
"""Should use Linux command format on Linux."""
|
||||
with patch.object(Constants, "IS_WINDOWS", False), \
|
||||
patch("subprocess.run") as mock_run:
|
||||
with patch.object(Constants, "IS_WINDOWS", False), patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = MagicMock(returncode=0)
|
||||
lscalc.run_ls_dyna("test.k", ncpu=4)
|
||||
assert mock_run.called
|
||||
@@ -82,14 +80,14 @@ class TestCheckLsDynaStatus:
|
||||
"""Should detect running LS-DYNA process."""
|
||||
with patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = MagicMock(stdout="lsdyna.exe\n", returncode=0)
|
||||
result = lscalc.check_ls_dyna_status()
|
||||
lscalc.check_ls_dyna_status()
|
||||
assert mock_run.called
|
||||
|
||||
def test_check_ls_dyna_status_not_running(self) -> None:
|
||||
"""Should detect no LS-DYNA process."""
|
||||
with patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = MagicMock(stdout="", returncode=0)
|
||||
result = lscalc.check_ls_dyna_status()
|
||||
lscalc.check_ls_dyna_status()
|
||||
assert mock_run.called
|
||||
|
||||
|
||||
@@ -101,41 +99,41 @@ class TestMain:
|
||||
|
||||
def test_main_run_with_input_file(self) -> None:
|
||||
"""main() should handle run command with input file."""
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(lscalc, "run_ls_dyna"):
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
lscalc, "run_ls_dyna"
|
||||
):
|
||||
lscalc.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_run_with_custom_ncpu(self) -> None:
|
||||
"""main() should handle run command with custom CPU count."""
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k", "--ncpu", "8"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(lscalc, "run_ls_dyna"):
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k", "--ncpu", "8"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(lscalc, "run_ls_dyna"):
|
||||
lscalc.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_mpi_with_input_file(self) -> None:
|
||||
"""main() should handle mpi command with input file."""
|
||||
with patch("sys.argv", ["lscalc", "mpi", "test.k"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(lscalc, "run_ls_dyna_mpi"):
|
||||
with patch("sys.argv", ["lscalc", "mpi", "test.k"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
lscalc, "run_ls_dyna_mpi"
|
||||
):
|
||||
lscalc.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_mpi_with_custom_ncpu(self) -> None:
|
||||
"""main() should handle mpi command with custom CPU count."""
|
||||
with patch("sys.argv", ["lscalc", "mpi", "test.k", "--ncpu", "8"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(lscalc, "run_ls_dyna_mpi"):
|
||||
with patch("sys.argv", ["lscalc", "mpi", "test.k", "--ncpu", "8"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(lscalc, "run_ls_dyna_mpi"):
|
||||
lscalc.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_status(self) -> None:
|
||||
"""main() should handle status command."""
|
||||
with patch("sys.argv", ["lscalc", "status"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(lscalc, "check_ls_dyna_status"):
|
||||
with patch("sys.argv", ["lscalc", "status"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
lscalc, "check_ls_dyna_status"
|
||||
):
|
||||
lscalc.main()
|
||||
assert mock_run.called
|
||||
|
||||
@@ -147,9 +145,9 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_spec_with_correct_name(self) -> None:
|
||||
"""main() should create TaskSpec with correct name."""
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(lscalc, "run_ls_dyna"):
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
lscalc, "run_ls_dyna"
|
||||
):
|
||||
lscalc.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
task_names = list(graph.all_specs().keys())
|
||||
@@ -157,8 +155,8 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(lscalc, "run_ls_dyna"):
|
||||
with patch("sys.argv", ["lscalc", "run", "test.k"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
lscalc, "run_ls_dyna"
|
||||
):
|
||||
lscalc.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
+44
-46
@@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -34,7 +34,7 @@ class TestPackSource:
|
||||
project_dir.mkdir()
|
||||
output_dir = tmp_path / "output"
|
||||
|
||||
with patch("shutil.make_archive") as mock_archive:
|
||||
with patch("shutil.make_archive"):
|
||||
packtool.pack_source(project_dir, output_dir)
|
||||
assert output_dir.exists()
|
||||
|
||||
@@ -107,8 +107,7 @@ class TestInstallEmbedPython:
|
||||
"""Should install embedded Python with version."""
|
||||
output_dir = tmp_path / "python"
|
||||
|
||||
with patch("subprocess.run") as mock_run, \
|
||||
patch.object(Path, "exists", return_value=False):
|
||||
with patch("subprocess.run") as mock_run, patch.object(Path, "exists", return_value=False):
|
||||
mock_run.return_value = MagicMock(returncode=0)
|
||||
packtool.install_embed_python("3.10", output_dir)
|
||||
assert mock_run.called
|
||||
@@ -117,8 +116,7 @@ class TestInstallEmbedPython:
|
||||
"""Should create output directory if it doesn't exist."""
|
||||
output_dir = tmp_path / "python"
|
||||
|
||||
with patch("subprocess.run") as mock_run, \
|
||||
patch.object(Path, "exists", return_value=False):
|
||||
with patch("subprocess.run") as mock_run, patch.object(Path, "exists", return_value=False):
|
||||
mock_run.return_value = MagicMock(returncode=0)
|
||||
packtool.install_embed_python("3.10", output_dir)
|
||||
assert output_dir.exists()
|
||||
@@ -185,89 +183,89 @@ class TestMain:
|
||||
|
||||
def test_main_src_default_dirs(self) -> None:
|
||||
"""main() should handle src command with default dirs."""
|
||||
with patch("sys.argv", ["packtool", "src"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_source"):
|
||||
with patch("sys.argv", ["packtool", "src"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "pack_source"
|
||||
):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_src_custom_dirs(self) -> None:
|
||||
"""main() should handle src command with custom dirs."""
|
||||
with patch("sys.argv", ["packtool", "src", "--project-dir", "project", "--output-dir", "output"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_source"):
|
||||
with patch("sys.argv", ["packtool", "src", "--project-dir", "project", "--output-dir", "output"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(packtool, "pack_source"):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_deps_default_dir(self) -> None:
|
||||
"""main() should handle deps command with default dir."""
|
||||
with patch("sys.argv", ["packtool", "deps"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_dependencies"):
|
||||
with patch("sys.argv", ["packtool", "deps"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "pack_dependencies"
|
||||
):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_deps_with_dependencies(self) -> None:
|
||||
"""main() should handle deps command with dependencies."""
|
||||
with patch("sys.argv", ["packtool", "deps", "--lib-dir", "lib", "numpy", "pandas"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_dependencies"):
|
||||
with patch("sys.argv", ["packtool", "deps", "--lib-dir", "lib", "numpy", "pandas"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(packtool, "pack_dependencies"):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_wheel_default_dirs(self) -> None:
|
||||
"""main() should handle wheel command with default dirs."""
|
||||
with patch("sys.argv", ["packtool", "wheel"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_wheel"):
|
||||
with patch("sys.argv", ["packtool", "wheel"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "pack_wheel"
|
||||
):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_wheel_custom_dirs(self) -> None:
|
||||
"""main() should handle wheel command with custom dirs."""
|
||||
with patch("sys.argv", ["packtool", "wheel", "--project-dir", "project", "--output-dir", "output"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_wheel"):
|
||||
with patch(
|
||||
"sys.argv", ["packtool", "wheel", "--project-dir", "project", "--output-dir", "output"]
|
||||
), patch.object(px, "run") as mock_run, patch.object(packtool, "pack_wheel"):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_embed_default_version(self) -> None:
|
||||
"""main() should handle embed command with default version."""
|
||||
with patch("sys.argv", ["packtool", "embed"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "install_embed_python"):
|
||||
with patch("sys.argv", ["packtool", "embed"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "install_embed_python"
|
||||
):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_embed_custom_version(self) -> None:
|
||||
"""main() should handle embed command with custom version."""
|
||||
with patch("sys.argv", ["packtool", "embed", "--version", "3.11", "--output-dir", "python"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "install_embed_python"):
|
||||
with patch("sys.argv", ["packtool", "embed", "--version", "3.11", "--output-dir", "python"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run, patch.object(packtool, "install_embed_python"):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_zip_default_params(self) -> None:
|
||||
"""main() should handle zip command with default params."""
|
||||
with patch("sys.argv", ["packtool", "zip"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "create_zip_package"):
|
||||
with patch("sys.argv", ["packtool", "zip"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "create_zip_package"
|
||||
):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_zip_custom_params(self) -> None:
|
||||
"""main() should handle zip command with custom params."""
|
||||
with patch("sys.argv", ["packtool", "zip", "--source-dir", "source", "--output-file", "package.zip"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "create_zip_package"):
|
||||
with patch(
|
||||
"sys.argv", ["packtool", "zip", "--source-dir", "source", "--output-file", "package.zip"]
|
||||
), patch.object(px, "run") as mock_run, patch.object(packtool, "create_zip_package"):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
def test_main_clean(self) -> None:
|
||||
"""main() should handle clean command."""
|
||||
with patch("sys.argv", ["packtool", "clean"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "clean_build_dir"):
|
||||
with patch("sys.argv", ["packtool", "clean"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "clean_build_dir"
|
||||
):
|
||||
packtool.main()
|
||||
assert mock_run.called
|
||||
|
||||
@@ -279,9 +277,9 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_spec_with_correct_name(self) -> None:
|
||||
"""main() should create TaskSpec with correct name."""
|
||||
with patch("sys.argv", ["packtool", "src"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_source"):
|
||||
with patch("sys.argv", ["packtool", "src"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "pack_source"
|
||||
):
|
||||
packtool.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
task_names = list(graph.all_specs().keys())
|
||||
@@ -289,8 +287,8 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["packtool", "src"]), \
|
||||
patch.object(px, "run") as mock_run, \
|
||||
patch.object(packtool, "pack_source"):
|
||||
with patch("sys.argv", ["packtool", "src"]), patch.object(px, "run") as mock_run, patch.object(
|
||||
packtool, "pack_source"
|
||||
):
|
||||
packtool.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
@@ -97,7 +97,7 @@ class TestPipFreeze:
|
||||
mock_run.return_value = MagicMock(stdout="numpy==1.0.0\npandas==2.0.0\n", returncode=0)
|
||||
piptool.pip_freeze()
|
||||
# Should create requirements.txt
|
||||
req_file = tmp_path / "requirements.txt"
|
||||
tmp_path / "requirements.txt"
|
||||
# Note: The actual implementation might write to current directory
|
||||
|
||||
def test_pip_freeze_calls_subprocess(self) -> None:
|
||||
|
||||
@@ -18,7 +18,7 @@ from pyflowx.conditions import Constants
|
||||
class TestTakeScreenshotFull:
|
||||
"""Test take_screenshot_full function."""
|
||||
|
||||
def test_take_screenshot_full_windows(self, tmp_path: Path) -> None:
|
||||
def test_take_screenshot_full_windows(self, tmp_path: Path) -> None: # noqa: ARG002
|
||||
"""Should take full screenshot on Windows."""
|
||||
if Constants.IS_WINDOWS:
|
||||
with patch("subprocess.run") as mock_run:
|
||||
@@ -26,7 +26,7 @@ class TestTakeScreenshotFull:
|
||||
screenshot.take_screenshot_full(filename="test.png")
|
||||
assert mock_run.called
|
||||
|
||||
def test_take_screenshot_full_linux(self, tmp_path: Path) -> None:
|
||||
def test_take_screenshot_full_linux(self, tmp_path: Path) -> None: # noqa: ARG002
|
||||
"""Should take full screenshot on Linux."""
|
||||
with patch.object(Constants, "IS_WINDOWS", False), patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = MagicMock(returncode=0)
|
||||
@@ -54,7 +54,7 @@ class TestTakeScreenshotFull:
|
||||
class TestTakeScreenshotArea:
|
||||
"""Test take_screenshot_area function."""
|
||||
|
||||
def test_take_screenshot_area_windows(self, tmp_path: Path) -> None:
|
||||
def test_take_screenshot_area_windows(self, tmp_path: Path) -> None: # noqa: ARG002
|
||||
"""Should take area screenshot on Windows."""
|
||||
if Constants.IS_WINDOWS:
|
||||
with patch("subprocess.run") as mock_run:
|
||||
@@ -62,7 +62,7 @@ class TestTakeScreenshotArea:
|
||||
screenshot.take_screenshot_area(filename="test.png")
|
||||
assert mock_run.called
|
||||
|
||||
def test_take_screenshot_area_linux(self, tmp_path: Path) -> None:
|
||||
def test_take_screenshot_area_linux(self, tmp_path: Path) -> None: # noqa: ARG002
|
||||
"""Should take area screenshot on Linux."""
|
||||
with patch.object(Constants, "IS_WINDOWS", False), patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = MagicMock(returncode=0)
|
||||
|
||||
@@ -42,7 +42,7 @@ class TestSshCopyId:
|
||||
mock_client.connect.return_value = None
|
||||
mock_client.exec_command.return_value = (MagicMock(), MagicMock(), MagicMock())
|
||||
|
||||
result = sshcopyid.ssh_copy_id("localhost", "user", "password", port=2222)
|
||||
sshcopyid.ssh_copy_id("localhost", "user", "password", port=2222)
|
||||
# Verify that connect was called with custom port
|
||||
mock_client.connect.assert_called_once()
|
||||
call_args = mock_client.connect.call_args
|
||||
|
||||
+13
-18
@@ -19,8 +19,7 @@ class TestMain:
|
||||
|
||||
def test_main_with_single_process(self) -> None:
|
||||
"""main() should handle single process argument."""
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), patch.object(px, "run") as mock_run:
|
||||
taskkill.main()
|
||||
assert mock_run.called
|
||||
graph = mock_run.call_args[0][0]
|
||||
@@ -28,8 +27,9 @@ class TestMain:
|
||||
|
||||
def test_main_with_multiple_processes(self) -> None:
|
||||
"""main() should handle multiple process arguments."""
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe", "python.exe", "node.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe", "python.exe", "node.exe"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run:
|
||||
taskkill.main()
|
||||
assert mock_run.called
|
||||
graph = mock_run.call_args[0][0]
|
||||
@@ -43,8 +43,7 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_specs_with_correct_names(self) -> None:
|
||||
"""main() should create TaskSpecs with correct names."""
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe", "python.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe", "python.exe"]), patch.object(px, "run") as mock_run:
|
||||
taskkill.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
task_names = list(graph.all_specs().keys())
|
||||
@@ -53,16 +52,14 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), patch.object(px, "run") as mock_run:
|
||||
taskkill.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
def test_main_windows_command_format(self) -> None:
|
||||
"""main() should use Windows command format on Windows."""
|
||||
if Constants.IS_WINDOWS:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), patch.object(px, "run") as mock_run:
|
||||
taskkill.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
specs = graph.all_specs()
|
||||
@@ -74,9 +71,9 @@ class TestMain:
|
||||
|
||||
def test_main_linux_command_format(self) -> None:
|
||||
"""main() should use Linux command format on Linux."""
|
||||
with patch.object(Constants, "IS_WINDOWS", False), \
|
||||
patch("sys.argv", ["taskkill", "chrome.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch.object(Constants, "IS_WINDOWS", False), patch("sys.argv", ["taskkill", "chrome.exe"]), patch.object(
|
||||
px, "run"
|
||||
) as mock_run:
|
||||
taskkill.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
specs = graph.all_specs()
|
||||
@@ -87,8 +84,7 @@ class TestMain:
|
||||
|
||||
def test_main_tasks_have_verbose_true(self) -> None:
|
||||
"""main() should create tasks with verbose=True."""
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), patch.object(px, "run") as mock_run:
|
||||
taskkill.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
specs = graph.all_specs()
|
||||
@@ -97,11 +93,10 @@ class TestMain:
|
||||
|
||||
def test_main_adds_wildcard_to_process_name(self) -> None:
|
||||
"""main() should add wildcard to process name."""
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["taskkill", "chrome.exe"]), patch.object(px, "run") as mock_run:
|
||||
taskkill.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
specs = graph.all_specs()
|
||||
# Check that wildcard is added
|
||||
for spec in specs.values():
|
||||
assert spec.cmd[-1].endswith("*")
|
||||
assert spec.cmd[-1].endswith("*")
|
||||
|
||||
+14
-14
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -59,9 +59,9 @@ class TestMain:
|
||||
|
||||
def test_main_with_single_command(self) -> None:
|
||||
"""main() should handle single command argument."""
|
||||
with patch("sys.argv", ["which", "python"]), \
|
||||
patch.object(shutil, "which", return_value="/usr/bin/python"), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["which", "python"]), patch.object(
|
||||
shutil, "which", return_value="/usr/bin/python"
|
||||
), patch.object(px, "run") as mock_run:
|
||||
which.main()
|
||||
# Should create a graph with one task
|
||||
assert mock_run.called
|
||||
@@ -70,9 +70,9 @@ class TestMain:
|
||||
|
||||
def test_main_with_multiple_commands(self) -> None:
|
||||
"""main() should handle multiple command arguments."""
|
||||
with patch("sys.argv", ["which", "python", "pip", "node"]), \
|
||||
patch.object(shutil, "which", return_value="/usr/bin/cmd"), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["which", "python", "pip", "node"]), patch.object(
|
||||
shutil, "which", return_value="/usr/bin/cmd"
|
||||
), patch.object(px, "run") as mock_run:
|
||||
which.main()
|
||||
# Should create a graph with three tasks
|
||||
assert mock_run.called
|
||||
@@ -87,9 +87,9 @@ class TestMain:
|
||||
|
||||
def test_main_creates_task_specs_with_correct_names(self) -> None:
|
||||
"""main() should create TaskSpecs with correct names."""
|
||||
with patch("sys.argv", ["which", "git", "npm"]), \
|
||||
patch.object(shutil, "which", return_value="/usr/bin/cmd"), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["which", "git", "npm"]), patch.object(
|
||||
shutil, "which", return_value="/usr/bin/cmd"
|
||||
), patch.object(px, "run") as mock_run:
|
||||
which.main()
|
||||
graph = mock_run.call_args[0][0]
|
||||
# Check that task names are correct
|
||||
@@ -99,8 +99,8 @@ class TestMain:
|
||||
|
||||
def test_main_uses_thread_strategy(self) -> None:
|
||||
"""main() should use thread strategy."""
|
||||
with patch("sys.argv", ["which", "python"]), \
|
||||
patch.object(shutil, "which", return_value="/usr/bin/python"), \
|
||||
patch.object(px, "run") as mock_run:
|
||||
with patch("sys.argv", ["which", "python"]), patch.object(
|
||||
shutil, "which", return_value="/usr/bin/python"
|
||||
), patch.object(px, "run") as mock_run:
|
||||
which.main()
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
assert mock_run.call_args[1]["strategy"] == "thread"
|
||||
|
||||
Reference in New Issue
Block a user