From 843e9369fe6a4866b892db211e80515290bf72d3 Mon Sep 17 00:00:00 2001 From: gooker_young Date: Mon, 22 Jun 2026 11:45:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E8=A1=8C=E5=88=97=E8=A1=A8=E4=B8=8E=E5=87=BD=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对多处代码进行了统一的多行列表和函数调用进行格式化调整,包括将单行代码拆分为多行以提升可读性。 --- src/pyflowx/cli/autofmt.py | 20 +++--- src/pyflowx/cli/envpy.py | 6 +- src/pyflowx/cli/envrs.py | 12 ++-- src/pyflowx/cli/filedate.py | 36 +++++----- src/pyflowx/cli/filelevel.py | 10 ++- src/pyflowx/cli/lscalc.py | 12 ++-- src/pyflowx/cli/packtool.py | 80 +++++++++++---------- src/pyflowx/cli/pdftool.py | 128 ++++++++++++++++++---------------- src/pyflowx/cli/piptool.py | 58 +++++++++------ src/pyflowx/cli/screenshot.py | 13 ++-- src/pyflowx/cli/sshcopyid.py | 19 ++--- src/pyflowx/cli/taskkill.py | 9 ++- tests/cli/test_autofmt.py | 58 +++++++-------- tests/cli/test_bumpversion.py | 2 +- tests/cli/test_clearscreen.py | 6 +- tests/cli/test_envpy.py | 33 +++++---- tests/cli/test_envqt.py | 3 +- tests/cli/test_envrs.py | 57 +++++++-------- tests/cli/test_filedate.py | 38 +++++----- tests/cli/test_folderback.py | 3 +- tests/cli/test_folderzip.py | 3 +- tests/cli/test_gittool.py | 4 +- tests/cli/test_lscalc.py | 54 +++++++------- tests/cli/test_packtool.py | 90 ++++++++++++------------ tests/cli/test_piptool.py | 2 +- tests/cli/test_screenshot.py | 8 +-- tests/cli/test_sshcopyid.py | 2 +- tests/cli/test_taskkill.py | 31 ++++---- tests/cli/test_which.py | 28 ++++---- 29 files changed, 419 insertions(+), 406 deletions(-) diff --git a/src/pyflowx/cli/autofmt.py b/src/pyflowx/cli/autofmt.py index f9c10b6..c249de2 100644 --- a/src/pyflowx/cli/autofmt.py +++ b/src/pyflowx/cli/autofmt.py @@ -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 diff --git a/src/pyflowx/cli/envpy.py b/src/pyflowx/cli/envpy.py index 3f51238..f84fceb 100644 --- a/src/pyflowx/cli/envpy.py +++ b/src/pyflowx/cli/envpy.py @@ -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 diff --git a/src/pyflowx/cli/envrs.py b/src/pyflowx/cli/envrs.py index 430aa8a..4e8ecab 100644 --- a/src/pyflowx/cli/envrs.py +++ b/src/pyflowx/cli/envrs.py @@ -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 diff --git a/src/pyflowx/cli/filedate.py b/src/pyflowx/cli/filedate.py index fc1c7f3..dbdf96e 100644 --- a/src/pyflowx/cli/filedate.py +++ b/src/pyflowx/cli/filedate.py @@ -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 diff --git a/src/pyflowx/cli/filelevel.py b/src/pyflowx/cli/filelevel.py index 7dca50e..7f4ba1c 100644 --- a/src/pyflowx/cli/filelevel.py +++ b/src/pyflowx/cli/filelevel.py @@ -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 diff --git a/src/pyflowx/cli/lscalc.py b/src/pyflowx/cli/lscalc.py index cb56958..cff807b 100644 --- a/src/pyflowx/cli/lscalc.py +++ b/src/pyflowx/cli/lscalc.py @@ -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: diff --git a/src/pyflowx/cli/packtool.py b/src/pyflowx/cli/packtool.py index 020809f..d30465a 100644 --- a/src/pyflowx/cli/packtool.py +++ b/src/pyflowx/cli/packtool.py @@ -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: diff --git a/src/pyflowx/cli/pdftool.py b/src/pyflowx/cli/pdftool.py index 9192177..06f845a 100644 --- a/src/pyflowx/cli/pdftool.py +++ b/src/pyflowx/cli/pdftool.py @@ -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 diff --git a/src/pyflowx/cli/piptool.py b/src/pyflowx/cli/piptool.py index f7c8195..c8d795c 100644 --- a/src/pyflowx/cli/piptool.py +++ b/src/pyflowx/cli/piptool.py @@ -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 diff --git a/src/pyflowx/cli/screenshot.py b/src/pyflowx/cli/screenshot.py index 37a1934..ab0d90c 100644 --- a/src/pyflowx/cli/screenshot.py +++ b/src/pyflowx/cli/screenshot.py @@ -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 diff --git a/src/pyflowx/cli/sshcopyid.py b/src/pyflowx/cli/sshcopyid.py index c89f21b..c8c5844 100644 --- a/src/pyflowx/cli/sshcopyid.py +++ b/src/pyflowx/cli/sshcopyid.py @@ -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") diff --git a/src/pyflowx/cli/taskkill.py b/src/pyflowx/cli/taskkill.py index e14563e..a07148b 100644 --- a/src/pyflowx/cli/taskkill.py +++ b/src/pyflowx/cli/taskkill.py @@ -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") diff --git a/tests/cli/test_autofmt.py b/tests/cli/test_autofmt.py index 8927a73..62ef3a2 100644 --- a/tests/cli/test_autofmt.py +++ b/tests/cli/test_autofmt.py @@ -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" \ No newline at end of file + assert mock_run.call_args[1]["strategy"] == "thread" diff --git a/tests/cli/test_bumpversion.py b/tests/cli/test_bumpversion.py index f4a0c68..83860d3 100644 --- a/tests/cli/test_bumpversion.py +++ b/tests/cli/test_bumpversion.py @@ -2,7 +2,7 @@ from __future__ import annotations -from unittest.mock import patch +from unittest.mock import MagicMock, patch import pytest diff --git a/tests/cli/test_clearscreen.py b/tests/cli/test_clearscreen.py index 8910852..2fc2356 100644 --- a/tests/cli/test_clearscreen.py +++ b/tests/cli/test_clearscreen.py @@ -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 \ No newline at end of file + assert exc_info.value.code == 1 diff --git a/tests/cli/test_envpy.py b/tests/cli/test_envpy.py index 9d89f63..803eb91 100644 --- a/tests/cli/test_envpy.py +++ b/tests/cli/test_envpy.py @@ -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" \ No newline at end of file + assert mock_run.call_args[1]["strategy"] == "thread" diff --git a/tests/cli/test_envqt.py b/tests/cli/test_envqt.py index 3204fb4..f64af78 100644 --- a/tests/cli/test_envqt.py +++ b/tests/cli/test_envqt.py @@ -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 \ No newline at end of file + assert exc_info.value.code == 1 diff --git a/tests/cli/test_envrs.py b/tests/cli/test_envrs.py index 4b0c235..b026414 100644 --- a/tests/cli/test_envrs.py +++ b/tests/cli/test_envrs.py @@ -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" \ No newline at end of file + assert mock_run.call_args[1]["strategy"] == "thread" diff --git a/tests/cli/test_filedate.py b/tests/cli/test_filedate.py index d94474e..f83316a 100644 --- a/tests/cli/test_filedate.py +++ b/tests/cli/test_filedate.py @@ -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" \ No newline at end of file + assert mock_run.call_args[1]["strategy"] == "thread" diff --git a/tests/cli/test_folderback.py b/tests/cli/test_folderback.py index ae8bf46..5bfb576 100644 --- a/tests/cli/test_folderback.py +++ b/tests/cli/test_folderback.py @@ -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 \ No newline at end of file + assert exc_info.value.code == 1 diff --git a/tests/cli/test_folderzip.py b/tests/cli/test_folderzip.py index 52fe3fe..57c3918 100644 --- a/tests/cli/test_folderzip.py +++ b/tests/cli/test_folderzip.py @@ -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 \ No newline at end of file + assert exc_info.value.code == 1 diff --git a/tests/cli/test_gittool.py b/tests/cli/test_gittool.py index b37b25c..fdae3a2 100644 --- a/tests/cli/test_gittool.py +++ b/tests/cli/test_gittool.py @@ -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 \ No newline at end of file + assert exc_info.value.code == 1 diff --git a/tests/cli/test_lscalc.py b/tests/cli/test_lscalc.py index a81ad99..7a5a1b1 100644 --- a/tests/cli/test_lscalc.py +++ b/tests/cli/test_lscalc.py @@ -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" \ No newline at end of file + assert mock_run.call_args[1]["strategy"] == "thread" diff --git a/tests/cli/test_packtool.py b/tests/cli/test_packtool.py index b1dd56b..bd3ad95 100644 --- a/tests/cli/test_packtool.py +++ b/tests/cli/test_packtool.py @@ -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" \ No newline at end of file + assert mock_run.call_args[1]["strategy"] == "thread" diff --git a/tests/cli/test_piptool.py b/tests/cli/test_piptool.py index 94fdb70..e1242a6 100644 --- a/tests/cli/test_piptool.py +++ b/tests/cli/test_piptool.py @@ -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: diff --git a/tests/cli/test_screenshot.py b/tests/cli/test_screenshot.py index c54621b..126741b 100644 --- a/tests/cli/test_screenshot.py +++ b/tests/cli/test_screenshot.py @@ -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) diff --git a/tests/cli/test_sshcopyid.py b/tests/cli/test_sshcopyid.py index 5382fb7..d2cbf24 100644 --- a/tests/cli/test_sshcopyid.py +++ b/tests/cli/test_sshcopyid.py @@ -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 diff --git a/tests/cli/test_taskkill.py b/tests/cli/test_taskkill.py index 16b2875..e137d42 100644 --- a/tests/cli/test_taskkill.py +++ b/tests/cli/test_taskkill.py @@ -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("*") \ No newline at end of file + assert spec.cmd[-1].endswith("*") diff --git a/tests/cli/test_which.py b/tests/cli/test_which.py index 44cd7be..5ee4577 100644 --- a/tests/cli/test_which.py +++ b/tests/cli/test_which.py @@ -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" \ No newline at end of file + assert mock_run.call_args[1]["strategy"] == "thread"