23 lines
631 B
Python
23 lines
631 B
Python
"""Record stores for tests, held to record_store.contract like every backend."""
|
|
import dataclasses
|
|
|
|
from failure import Failure
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class MemoryStore:
|
|
"""A record held in memory, as a backend outside git holds one. Set fails to make every read and write fail with that reason."""
|
|
text: str = ""
|
|
label: str = "the record in memory"
|
|
tracked: str | None = None
|
|
fails: str | None = None
|
|
|
|
def read(self) -> str | Failure:
|
|
return Failure(self.fails) if self.fails else self.text
|
|
|
|
def write(self, text: str) -> Failure | None:
|
|
if self.fails:
|
|
return Failure(self.fails)
|
|
self.text = text
|
|
return None
|