Files
claude-config/bin/record_store/contract.py
T

33 lines
1.1 KiB
Python

"""What every record backend must hold, as tests. A backend's test case inherits RecordStoreContract and unittest.TestCase, and builds its store in new_store."""
import typing
from record_store.stores import RecordStore
class RecordStoreContract:
"""Runs against the store new_store returns: one that holds no record yet."""
assertEqual: typing.Callable[..., None]
assertIsNone: typing.Callable[..., None]
assertTrue: typing.Callable[..., None]
def new_store(self) -> RecordStore:
raise NotImplementedError
def test_a_record_never_written_reads_empty(self) -> None:
self.assertEqual(self.new_store().read(), "")
def test_reads_back_what_it_wrote_to_the_character(self) -> None:
store = self.new_store()
text = "# Decisions\n\n- Å, 🔴 and a | pipe\n\n\n"
self.assertIsNone(store.write(text))
self.assertEqual(store.read(), text)
def test_a_write_replaces_the_whole_record(self) -> None:
store = self.new_store()
store.write("first\nsecond\n")
self.assertIsNone(store.write("third\n"))
self.assertEqual(store.read(), "third\n")
def test_names_itself_for_a_message(self) -> None:
self.assertTrue(self.new_store().label.strip())