14 lines
742 B
Python
14 lines
742 B
Python
import os
|
|
import unittest
|
|
|
|
|
|
# A git hook's GIT_DIR, the host's BUILD_RELEASE_* or PYTHONPATH would point the program under test at the host's own state,
|
|
# and the host's CLAUDE_CODE_SANDBOXED would hide whether build-release sets it.
|
|
def isolated_env() -> dict[str, str]:
|
|
return {name: value for name, value in os.environ.items() if not name.startswith(("GIT_", "BUILD_RELEASE_", "PYTHON")) and name not in ("CLAUDE_CODE_SANDBOXED", "XDG_CONFIG_HOME", "XDG_STATE_HOME")}
|
|
|
|
|
|
# Call it first in a test that takes a file's or a folder's permissions away.
|
|
def assert_not_root(test: unittest.TestCase) -> None:
|
|
test.assertNotEqual(os.geteuid(), 0, "root ignores file permissions, which this test checks: run the tests as a user other than root")
|