Debian Codegraph @

tasks/capability/assert_fallback.py

raw
1 """Confirm filelock took its documented fallback when ``FILELOCK_BLOCK_MODULE`` hid a module, or exit non-zero.
2
3 The capability jobs set the module and put ``tasks/capability`` on ``PYTHONPATH`` so the sibling ``sitecustomize``
4 hides it; this checks the import-time consequence before the verifier exercises the resulting lock.
5 """
6
7 from __future__ import annotations
8
9 import os
10
11 import filelock
12
13
14 def main() -> None:
15 blocked = os.environ["FILELOCK_BLOCK_MODULE"]
16 if blocked == "fcntl" and filelock.has_fcntl:
17 msg = f"without fcntl, expected has_fcntl False, got {filelock.has_fcntl!r}"
18 raise SystemExit(msg)
19 if blocked == "sqlite3" and filelock.ReadWriteLock is not None:
20 msg = f"without sqlite3, expected ReadWriteLock None, got {filelock.ReadWriteLock!r}"
21 raise SystemExit(msg)
22 print(f"fallback engaged without {blocked}")
23
24
25 if __name__ == "__main__":
26 main()