27 lines
870 B
Python
27 lines
870 B
Python
from __future__ import annotations
|
|
|
|
from contextlib import AbstractContextManager
|
|
from pathlib import Path
|
|
import shutil
|
|
import tempfile
|
|
|
|
from .models import ProtectionSnapshot
|
|
from .protection import MemoryProtectionStore
|
|
|
|
|
|
class DisposableGiteaFixture(AbstractContextManager):
|
|
def __init__(self, initial: ProtectionSnapshot) -> None:
|
|
self.root = Path(tempfile.mkdtemp(prefix="aios-governance-fixture-"))
|
|
self.protection = MemoryProtectionStore(initial)
|
|
self.destroyed = False
|
|
|
|
def __enter__(self) -> "DisposableGiteaFixture":
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc, tb) -> None:
|
|
resolved = self.root.resolve()
|
|
if not resolved.name.startswith("aios-governance-fixture-"):
|
|
raise RuntimeError("fixture cleanup path guard failed")
|
|
shutil.rmtree(resolved)
|
|
self.destroyed = True
|