test: close unclosed file handles in tests (Path read/write)
Replace bare open().read()/write() in tests with Path.read_text/
write_text (or json.loads over read_text); the five remaining
open(...).close() empty-file creations become Path.write_text('').
No assertion, predicate, or production code changed; no behaviour
change beyond closing the handle deterministically.
Long-function splits and server.py module split intentionally not
included: the longest functions (_dispatch, _create_task,
_dispatch_project, ~375-395 lines in a 10430-line server.py) are
central routing/creation paths, and splitting them is not low-risk;
see PR body.
This commit is contained in:
1 parent
82d0e84371
commit
7b537c31a6
9 files changed
+61
-57
No files matched your search
@@ -13,6 +13,7 @@ import tarfile
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
|
||||
os.path.abspath(__file__))))
|
||||
@@ -61,7 +62,7 @@ class MonitorSim(unittest.TestCase):
|
||||
"exit 0\n")
|
||||
real_curl = REAL_CURL or "/usr/bin/curl"
|
||||
self.curl_log = os.path.join(base, "curl.log")
|
||||
open(self.curl_log, "w").close()
|
||||
Path(self.curl_log).write_text("", encoding="utf-8")
|
||||
_write_exe(os.path.join(fake_bin, "curl"),
|
||||
"#!/bin/sh\n"
|
||||
"echo \"$@\" >> \"$FAKE_CURL_LOG\"\n"
|
||||
@@ -200,7 +201,7 @@ class RollbackSim(unittest.TestCase):
|
||||
fake_bin = os.path.join(base, "fakebin")
|
||||
os.makedirs(fake_bin)
|
||||
self.log_path = os.path.join(base, "systemctl.log")
|
||||
open(self.log_path, "w").close()
|
||||
Path(self.log_path).write_text("", encoding="utf-8")
|
||||
_write_exe(os.path.join(fake_bin, "ssh"),
|
||||
"#!/bin/sh\n"
|
||||
"# 假 ssh:忽略目标参数,直接把 heredoc 脚本在本地跑。\n"
|
||||
|
||||
Reference in new issue
Block a user