Skip to content

Contract suite (testing)

The checks every DB backend and dump format must pass. A third-party package runs them from its own tests, so its class is held to what the built-in ones are:

from pkgforge.testing import check_db_provider, check_dump_format

def test_my_backend(tmp_path):
    check_db_provider(MyDb, tmp_path)

def test_my_format(tmp_path):
    check_dump_format(MyFormat, tmp_path)

pkgforge.testing.DB_PROVIDER_CHECKS and DUMP_FORMAT_CHECKS are tuples of the individual checks, (cls, directory) -> None, for a runner that parametrises one test per check. A failure is an AssertionError naming the class and the check. The module does not import pytest.

pkgforge.testing.check_db_provider(cls, directory)

Run every :data:DB_PROVIDER_CHECKS check against cls in directory.

Each check works in its own subdirectory of directory, in a file named contract plus the class's first SUFFIXES entry (else .db). Raises :class:AssertionError naming cls and the failed check.

Source code in src/pkgforge/testing.py
191
192
193
194
195
196
197
198
199
200
def check_db_provider(cls: typing.Type[DbProvider], directory: StrPath) -> None:
    """Run every :data:`DB_PROVIDER_CHECKS` check against ``cls`` in
    ``directory``.

    Each check works in its own subdirectory of ``directory``, in a file named
    ``contract`` plus the class's first ``SUFFIXES`` entry (else ``.db``).
    Raises :class:`AssertionError` naming ``cls`` and the failed check.
    """
    for check in DB_PROVIDER_CHECKS:
        check(cls, directory)

pkgforge.testing.check_dump_format(cls, directory)

Run every :data:DUMP_FORMAT_CHECKS check against cls in directory.

The sample is seven entries owned by root: a file with capabilities, a directory, a symlink, a config-noreplace file outside /etc, a doc file and a ghost file and directory, all in one package named contract; each check works in its own subdirectory of directory. Raises :class:AssertionError naming cls and the failed check.

Source code in src/pkgforge/testing.py
329
330
331
332
333
334
335
336
337
338
339
340
def check_dump_format(cls: typing.Type[DumpFormat], directory: StrPath) -> None:
    """Run every :data:`DUMP_FORMAT_CHECKS` check against ``cls`` in
    ``directory``.

    The sample is seven entries owned by ``root``: a file with capabilities, a
    directory, a symlink, a ``config-noreplace`` file outside ``/etc``, a
    ``doc`` file and a ghost file and directory, all in one package named
    ``contract``; each check works in its own subdirectory of ``directory``.
    Raises :class:`AssertionError` naming ``cls`` and the failed check.
    """
    for check in DUMP_FORMAT_CHECKS:
        check(cls, directory)