* fix: a default Windows clone keeps pinned files byte for byte; LoRA test no longer depends on TEMP (#636) Git for Windows converts text files to CRLF on checkout by default, so a fresh clone failed npm run --prefix tools/vendor check with Viewer.js drift. .gitattributes now marks the pinned Viewer.js, Toolkit and concept stylesheet files as never converted, and a test holds that for every tracked file under them. .gitattributes stays out of the Registry package. test_preview_writes_nothing_and_makes_no_requests expected the full settings path, which only holds when the temp folder is outside the home folder. On Windows %TEMP% is under the profile, so the review showed ~\... and the test failed. It now pins the home folder beside the temp root. * fix(tests): the Built-in instructions test reads Python source with either line ending (#636) In a default Windows clone py/tagging_defaults.py is checked out with CRLF, so the test's search for the closing paren missed and JSON.parse failed on a carriage return: 1453 of 1454 frontend tests passed. The test now normalizes CRLF before it slices the source. * fix(tests): two more Windows machine failures: killed test servers, nearby ComfyUI (#636) On a Windows machine with a virtual environment, the tests that start tests/browser/server.py failed their cleanup with WinError 32 on the server's log file, 3 of 3 runs. The venv's python.exe is a launcher that runs the real interpreter as a child; killing the launcher returns while Windows is still ending that child. The temp folder is now removed by remove_when_released, which waits until the files are released, up to 30 s. CI never saw it: its Windows job runs a plain interpreter. The diagnostics tests that expect no output folder ran in the temp root, so the fallback's ../../ComfyUI/output could reach a real ComfyUI next to it. They now run two folders deep inside the temp folder. * docs(testing): what a Windows development machine needs for the suite (#636) * fix(tests): one import style in test_process_cleanup; the line-ending test ignores GIT_* (#636) Code quality flagged unittest imported both ways. The line-ending test shells out to git, which inside the pre-push hook would follow the exported GIT_DIR; it now runs git without GIT_* variables, proved with GIT_DIR and GIT_INDEX_FILE pointing at a decoy repository that stays untouched.
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
"""remove_when_released waits for a dying process's files, within a bound (#636)."""
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
import unittest.mock
|
|
|
|
try:
|
|
from tests import process_cleanup
|
|
except ImportError: # discovered with tests/ as the top-level directory
|
|
import process_cleanup
|
|
|
|
|
|
class TestRemoveWhenReleased(unittest.TestCase):
|
|
def test_removes_the_folder(self):
|
|
folder = tempfile.mkdtemp()
|
|
with open(os.path.join(folder, "server.log"), "w") as handle:
|
|
handle.write("x")
|
|
process_cleanup.remove_when_released(folder)
|
|
self.assertFalse(os.path.exists(folder))
|
|
|
|
def test_a_missing_folder_is_already_removed(self):
|
|
folder = tempfile.mkdtemp()
|
|
os.rmdir(folder)
|
|
process_cleanup.remove_when_released(folder)
|
|
|
|
def test_retries_while_another_process_still_holds_a_file(self):
|
|
held = PermissionError(32, "being used by another process")
|
|
with (
|
|
unittest.mock.patch.object(
|
|
process_cleanup.shutil, "rmtree", side_effect=[held, held, None]
|
|
) as rmtree,
|
|
unittest.mock.patch.object(process_cleanup.time, "sleep") as sleep,
|
|
):
|
|
process_cleanup.remove_when_released("folder")
|
|
self.assertEqual(rmtree.call_count, 3)
|
|
self.assertEqual(sleep.call_count, 2)
|
|
|
|
def test_raises_the_last_error_after_the_bound(self):
|
|
held = PermissionError(32, "being used by another process")
|
|
clock = iter([0.0, 0.0, 5.0, 11.0])
|
|
with (
|
|
unittest.mock.patch.object(
|
|
process_cleanup.shutil, "rmtree", side_effect=held
|
|
),
|
|
unittest.mock.patch.object(process_cleanup.time, "sleep"),
|
|
unittest.mock.patch.object(
|
|
process_cleanup.time, "monotonic", side_effect=lambda: next(clock)
|
|
),
|
|
):
|
|
with self.assertRaises(PermissionError):
|
|
process_cleanup.remove_when_released("folder", timeout=10)
|
|
|
|
def test_other_errors_are_not_retried(self):
|
|
with unittest.mock.patch.object(
|
|
process_cleanup.shutil, "rmtree", side_effect=OSError("disk gone")
|
|
) as rmtree:
|
|
with self.assertRaises(OSError):
|
|
process_cleanup.remove_when_released("folder")
|
|
self.assertEqual(rmtree.call_count, 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|