refactor: 统一格式化代码中的多行列表与函数调用
对多处代码进行了统一的多行列表和函数调用进行格式化调整,包括将单行代码拆分为多行以提升可读性。
This commit is contained in:
@@ -261,24 +261,20 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "fmt":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("ruff_format", cmd=["ruff", "format", args.target], verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs([px.TaskSpec("ruff_format", cmd=["ruff", "format", args.target], verbose=True)])
|
||||
elif args.command == "lint":
|
||||
cmd = ["ruff", "check", args.target]
|
||||
if args.fix:
|
||||
cmd.extend(["--fix", "--unsafe-fixes"])
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("ruff_check", cmd=cmd, verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs([px.TaskSpec("ruff_check", cmd=cmd, verbose=True)])
|
||||
elif args.command == "doc":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("auto_docstring", fn=auto_add_docstrings, args=(Path(args.root_dir),), verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("auto_docstring", fn=auto_add_docstrings, args=(Path(args.root_dir),), verbose=True)]
|
||||
)
|
||||
elif args.command == "sync":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("sync_config", fn=sync_pyproject_config, args=(Path(args.root_dir),), verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("sync_config", fn=sync_pyproject_config, args=(Path(args.root_dir),), verbose=True)]
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
@@ -112,9 +112,9 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "mirror":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("set_pip_mirror", fn=set_pip_mirror, args=(args.name,), kwargs={"token": args.token})
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("set_pip_mirror", fn=set_pip_mirror, args=(args.name,), kwargs={"token": args.token})]
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
@@ -136,13 +136,13 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "mirror":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("set_rust_mirror", fn=set_rust_mirror, args=(args.name,), verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("set_rust_mirror", fn=set_rust_mirror, args=(args.name,), verbose=True)]
|
||||
)
|
||||
elif args.command == "install":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("install_rust", cmd=["rustup", "toolchain", "install", args.version], verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("install_rust", cmd=["rustup", "toolchain", "install", args.version], verbose=True)]
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
+20
-16
@@ -113,23 +113,27 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "add":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"process_files_date",
|
||||
fn=process_files_date,
|
||||
args=([Path(f) for f in args.files],),
|
||||
kwargs={"clear": False},
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"process_files_date",
|
||||
fn=process_files_date,
|
||||
args=([Path(f) for f in args.files],),
|
||||
kwargs={"clear": False},
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "clear":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"process_files_date",
|
||||
fn=process_files_date,
|
||||
args=([Path(f) for f in args.files],),
|
||||
kwargs={"clear": True},
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"process_files_date",
|
||||
fn=process_files_date,
|
||||
args=([Path(f) for f in args.files],),
|
||||
kwargs={"clear": True},
|
||||
)
|
||||
]
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
@@ -126,9 +126,13 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "set":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("process_files_level", fn=process_files_level, args=([Path(f) for f in args.files], args.level))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"process_files_level", fn=process_files_level, args=([Path(f) for f in args.files], args.level)
|
||||
)
|
||||
]
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
@@ -158,13 +158,13 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "run":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("run_ls_dyna", fn=run_ls_dyna, args=(args.input_file,), kwargs={"ncpu": args.ncpu})
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("run_ls_dyna", fn=run_ls_dyna, args=(args.input_file,), kwargs={"ncpu": args.ncpu})]
|
||||
)
|
||||
elif args.command == "mpi":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("run_ls_dyna_mpi", fn=run_ls_dyna_mpi, args=(args.input_file,), kwargs={"ncpu": args.ncpu})
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("run_ls_dyna_mpi", fn=run_ls_dyna_mpi, args=(args.input_file,), kwargs={"ncpu": args.ncpu})]
|
||||
)
|
||||
elif args.command == "status":
|
||||
graph = px.Graph.from_specs([px.TaskSpec("check_ls_dyna_status", fn=check_ls_dyna_status)])
|
||||
else:
|
||||
|
||||
+45
-35
@@ -291,45 +291,55 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "src":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"pack_source",
|
||||
fn=pack_source,
|
||||
args=(Path(args.project_dir), Path(args.output_dir)),
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pack_source",
|
||||
fn=pack_source,
|
||||
args=(Path(args.project_dir), Path(args.output_dir)),
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "deps":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"pack_deps",
|
||||
fn=pack_dependencies,
|
||||
args=(Path(args.lib_dir), args.dependencies),
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pack_deps",
|
||||
fn=pack_dependencies,
|
||||
args=(Path(args.lib_dir), args.dependencies),
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "wheel":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"pack_wheel",
|
||||
fn=pack_wheel,
|
||||
args=(Path(args.project_dir), Path(args.output_dir)),
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pack_wheel",
|
||||
fn=pack_wheel,
|
||||
args=(Path(args.project_dir), Path(args.output_dir)),
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "embed":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"install_embed",
|
||||
fn=install_embed_python,
|
||||
args=(args.version, Path(args.output_dir)),
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"install_embed",
|
||||
fn=install_embed_python,
|
||||
args=(args.version, Path(args.output_dir)),
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "zip":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"create_zip",
|
||||
fn=create_zip_package,
|
||||
args=(Path(args.source_dir), Path(args.output_file)),
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"create_zip",
|
||||
fn=create_zip_package,
|
||||
args=(Path(args.source_dir), Path(args.output_file)),
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "clean":
|
||||
graph = px.Graph.from_specs([px.TaskSpec("clean_build", fn=clean_build_dir, args=(Path(DEFAULT_BUILD_DIR),))])
|
||||
else:
|
||||
|
||||
+68
-60
@@ -346,7 +346,7 @@ def pdf_repair(input_path: Path, output_path: Path) -> None:
|
||||
# ============================================================================
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def main() -> None: # noqa: PLR0912
|
||||
"""PDF 工具主函数."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="PDFTool - PDF 文件工具集",
|
||||
@@ -436,79 +436,87 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "m":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_merge", fn=pdf_merge, args=([Path(p) for p in args.inputs], Path(args.output)))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_merge", fn=pdf_merge, args=([Path(p) for p in args.inputs], Path(args.output)))]
|
||||
)
|
||||
elif args.command == "s":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_split", fn=pdf_split, args=(Path(args.input), Path(args.output_dir)))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_split", fn=pdf_split, args=(Path(args.input), Path(args.output_dir)))]
|
||||
)
|
||||
elif args.command == "c":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_compress", fn=pdf_compress, args=(Path(args.input), Path(args.output)))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_compress", fn=pdf_compress, args=(Path(args.input), Path(args.output)))]
|
||||
)
|
||||
elif args.command == "e":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_encrypt", fn=pdf_encrypt, args=(Path(args.input), Path(args.output), args.password))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_encrypt", fn=pdf_encrypt, args=(Path(args.input), Path(args.output), args.password))]
|
||||
)
|
||||
elif args.command == "d":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_decrypt", fn=pdf_decrypt, args=(Path(args.input), Path(args.output), args.password))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_decrypt", fn=pdf_decrypt, args=(Path(args.input), Path(args.output), args.password))]
|
||||
)
|
||||
elif args.command == "xt":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_extract_text", fn=pdf_extract_text, args=(Path(args.input), Path(args.output)))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_extract_text", fn=pdf_extract_text, args=(Path(args.input), Path(args.output)))]
|
||||
)
|
||||
elif args.command == "xi":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_extract_images", fn=pdf_extract_images, args=(Path(args.input), Path(args.output_dir)))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_extract_images", fn=pdf_extract_images, args=(Path(args.input), Path(args.output_dir)))]
|
||||
)
|
||||
elif args.command == "w":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"pdf_watermark",
|
||||
fn=pdf_add_watermark,
|
||||
args=(Path(args.input), Path(args.output)),
|
||||
kwargs={"text": args.text},
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pdf_watermark",
|
||||
fn=pdf_add_watermark,
|
||||
args=(Path(args.input), Path(args.output)),
|
||||
kwargs={"text": args.text},
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "r":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"pdf_rotate",
|
||||
fn=pdf_rotate,
|
||||
args=(Path(args.input), Path(args.output)),
|
||||
kwargs={"rotation": args.rotation},
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pdf_rotate",
|
||||
fn=pdf_rotate,
|
||||
args=(Path(args.input), Path(args.output)),
|
||||
kwargs={"rotation": args.rotation},
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "crop":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"pdf_crop",
|
||||
fn=pdf_crop,
|
||||
args=(Path(args.input), Path(args.output)),
|
||||
kwargs={"margins": (args.left, args.top, args.right, args.bottom)},
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pdf_crop",
|
||||
fn=pdf_crop,
|
||||
args=(Path(args.input), Path(args.output)),
|
||||
kwargs={"margins": (args.left, args.top, args.right, args.bottom)},
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "i":
|
||||
graph = px.Graph.from_specs([px.TaskSpec("pdf_info", fn=pdf_info, args=(Path(args.input),))])
|
||||
elif args.command == "ocr":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_ocr", fn=pdf_ocr, args=(Path(args.input), Path(args.output)), kwargs={"lang": args.lang})
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_ocr", fn=pdf_ocr, args=(Path(args.input), Path(args.output)), kwargs={"lang": args.lang})]
|
||||
)
|
||||
elif args.command == "img":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"pdf_to_images",
|
||||
fn=pdf_to_images,
|
||||
args=(Path(args.input), Path(args.output_dir)),
|
||||
kwargs={"dpi": args.dpi},
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pdf_to_images",
|
||||
fn=pdf_to_images,
|
||||
args=(Path(args.input), Path(args.output_dir)),
|
||||
kwargs={"dpi": args.dpi},
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "repair":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pdf_repair", fn=pdf_repair, args=(Path(args.input), Path(args.output)))
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pdf_repair", fn=pdf_repair, args=(Path(args.input), Path(args.output)))]
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
+36
-22
@@ -21,10 +21,12 @@ PACKAGE_DIR = "packages"
|
||||
REQUIREMENTS_FILE = "requirements.txt"
|
||||
|
||||
# 受保护的包名集合
|
||||
_PROTECTED_PACKAGES: frozenset[str] = frozenset({
|
||||
"pyflowx",
|
||||
"bitool",
|
||||
})
|
||||
_PROTECTED_PACKAGES: frozenset[str] = frozenset(
|
||||
{
|
||||
"pyflowx",
|
||||
"bitool",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -157,29 +159,41 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "i":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pip_install", cmd=["pip", "install", *args.packages], verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs([px.TaskSpec("pip_install", cmd=["pip", "install", *args.packages], verbose=True)])
|
||||
elif args.command == "u":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pip_uninstall", fn=pip_uninstall, args=(args.packages,), verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pip_uninstall", fn=pip_uninstall, args=(args.packages,), verbose=True)]
|
||||
)
|
||||
elif args.command == "r":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pip_reinstall", fn=pip_reinstall, args=(args.packages,), kwargs={"offline": args.offline}, verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pip_reinstall",
|
||||
fn=pip_reinstall,
|
||||
args=(args.packages,),
|
||||
kwargs={"offline": args.offline},
|
||||
verbose=True,
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "d":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pip_download", fn=pip_download, args=(args.packages,), kwargs={"offline": args.offline}, verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"pip_download",
|
||||
fn=pip_download,
|
||||
args=(args.packages,),
|
||||
kwargs={"offline": args.offline},
|
||||
verbose=True,
|
||||
)
|
||||
]
|
||||
)
|
||||
elif args.command == "up":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pip_upgrade", cmd=["python", "-m", "pip", "install", "--upgrade", "pip"], verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("pip_upgrade", cmd=["python", "-m", "pip", "install", "--upgrade", "pip"], verbose=True)]
|
||||
)
|
||||
elif args.command == "f":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("pip_freeze", fn=pip_freeze, verbose=True)
|
||||
])
|
||||
graph = px.Graph.from_specs([px.TaskSpec("pip_freeze", fn=pip_freeze, verbose=True)])
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -148,13 +149,13 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "full":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("screenshot_full", fn=take_screenshot_full, kwargs={"filename": args.filename})
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("screenshot_full", fn=take_screenshot_full, kwargs={"filename": args.filename})]
|
||||
)
|
||||
elif args.command == "area":
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec("screenshot_area", fn=take_screenshot_area, kwargs={"filename": args.filename})
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[px.TaskSpec("screenshot_area", fn=take_screenshot_area, kwargs={"filename": args.filename})]
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -108,12 +109,14 @@ def main() -> None:
|
||||
parser.add_argument("--timeout", type=int, default=30, help="SSH 操作超时秒数 (默认: 30)")
|
||||
args = parser.parse_args()
|
||||
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(
|
||||
"ssh_deploy",
|
||||
fn=ssh_copy_id,
|
||||
args=(args.hostname, args.username, args.password),
|
||||
kwargs={"port": args.port, "keypath": args.keypath, "timeout": args.timeout},
|
||||
)
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(
|
||||
"ssh_deploy",
|
||||
fn=ssh_copy_id,
|
||||
args=(args.hostname, args.username, args.password),
|
||||
kwargs={"port": args.port, "keypath": args.keypath, "timeout": args.timeout},
|
||||
)
|
||||
]
|
||||
)
|
||||
px.run(graph, strategy="thread")
|
||||
|
||||
@@ -31,7 +31,10 @@ def main() -> None:
|
||||
else:
|
||||
cmd = ["pkill", "-f"]
|
||||
|
||||
graph = px.Graph.from_specs([
|
||||
px.TaskSpec(f"kill_{proc_name}", cmd=[*cmd, f"{proc_name}*"], verbose=True) for proc_name in args.process_names
|
||||
])
|
||||
graph = px.Graph.from_specs(
|
||||
[
|
||||
px.TaskSpec(f"kill_{proc_name}", cmd=[*cmd, f"{proc_name}*"], verbose=True)
|
||||
for proc_name in args.process_names
|
||||
]
|
||||
)
|
||||
px.run(graph, strategy="thread")
|
||||
|
||||
+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