refactor: 统一格式化代码中的多行列表与函数调用
对多处代码进行了统一的多行列表和函数调用进行格式化调整,包括将单行代码拆分为多行以提升可读性。
This commit is contained in:
+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"
|
||||
|
||||
Reference in New Issue
Block a user