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:
openqj authored and host committed 2026-11-04 20:53:46 +00:00
1 parent fa4588a119
commit d779a1b426
9 files changed
+61 -57

No files matched your search

+2 -2
View File
@@ -79,7 +79,7 @@ class RestorePostgresTestCase(unittest.TestCase):
def test_empty_backup_file_rejected(self):
empty = os.path.join(self.tmp.name, "empty.sql")
open(empty, "w").close()
Path(empty).write_text("", encoding="utf-8")
with self.assertRaises(ValueError):
restore_postgres(empty, "restore_test",
runner=lambda c, e: _fake_result())
@@ -126,7 +126,7 @@ class WorkerHeartbeatTestCase(unittest.TestCase):
# 心跳目录不可写时只记日志,不抛异常(写到一个文件路径下当目录)。
tmp = tempfile.TemporaryDirectory()
blocker = os.path.join(tmp.name, "blocker")
open(blocker, "w").close()
Path(blocker).write_text("", encoding="utf-8")
worker = Worker(os.path.join(tmp.name, "db.db"), "/nonexistent/host.py",
env_key="TEST_KEY",
heartbeat_file=os.path.join(blocker, "hb.json"))