Utility Tests
tests/utils/test_file_io.py​
Unit tests for Batho's file input/output and inter-process locking utilities.
This module validates that the lock mechanism works correctly across multiple processes or threads, preventing concurrent builds or patches, and verifies that checking for locks does not prematurely create files on the filesystem.
Standalone Tests​
test_interprocess_locking​
Verify that InterProcessLock prevents concurrent acquisitions of the same lock file.
View Test Details
Scenario: Two separate lock manager instances try to acquire a lock on the exact same lock file. The first instance succeeds, while the second instance must fail with a RuntimeError indicating that another process or execution thread is active.
Execution Flow:
- Initialize
lock1andlock2pointing to the same file pathtest.lock. 2. Acquirelock1using a context manager. 3. Within that context, attempt to acquirelock2. 4. Assert thatRuntimeErroris raised with the correct message. 5. Exit thelock1context, releasing it. 6. Verify thatlock2can now be acquired successfully.
Flowchart:
Expectations:
- The lock file is exclusive: only one acquirer can hold it at any given time.
- RuntimeError is raised during nested acquisition attempts.
- Lock is fully re-acquirable once released by the previous holder.
test_is_locked_by_other_no_file_creation​
Verify that is_locked_by_other does not create a lock file if it does not exist.
View Test Details
Scenario: We query whether a lock file is held by another process before the file is even created. The query should return False, and the filesystem state must remain clean (the lock file should NOT be implicitly created by the query).
Execution Flow:
- Specify a path
nonexistent.lockthat does not exist in our temporary directory. 2. Assert that the file does not exist initially. 3. Call the static methodInterProcessLock.is_locked_by_other(lock_file). 4. Assert that the returned value is False. 5. Assert that the lock file still does not exist on disk.
Flowchart:
Expectations:
- Querying lock status is a read-only operation.
- No side-effects (file creations) are triggered on the filesystem.