# Abstract Repository Class

Storage of test results.

A Repository provides storage and indexing of results.

The AbstractRepository class defines the contract to which any Repository implementation must adhere.

The stestr.repository.file module (see: File Repository Type is the usual repository that will be used. The stestr.repository.memory module (see: Memory Repository Type) provides a memory only repository useful for internal testing.

Repositories are identified by their URL, and new ones are made by calling the initialize function in the appropriate repository module.

class `stestr.repository.abstract.``AbstractRepository`

  The base class for Repository implementations.

  There are no interesting attributes or methods as yet.

  `count`()

    Return the number of test runs this repository has stored.

    Return count: | The count of test runs stored in the repository.

  `find_metadata`(metadata)

    Return the list of run_ids for a given metadata string.

    Param: | metadata: the metadata string to search for.
    Returns: | a list of any test_ids that have that metadata value.

  `get_failing`()

    Get a TestRun that contains all of and only current failing tests.

    Returns: | a TestRun.

  `get_inserter`(partial=False, run_id=None, metadata=None)

    Get an inserter that will insert a test run into the repository.

    Repository implementations should implement _get_inserter.

    get_inserter() does not add timing data to streams: it should be provided by the caller of get_inserter (e.g. commands.load).

    Parameters: | partial – DEPREACTED: If True, the stream being inserted only executed some tests rather than all the projects tests. This option is deprecated and no longer does anything. It will be removed in the future.
    Return an inserter:
    | Inserters meet the extended TestResult protocol that testtools 0.9.2 and above offer. The startTestRun and stopTestRun methods in particular must be called.

  `get_latest_run`()

    Return the latest run.

    Equivalent to get_test_run(latest_id()).

  `get_test_ids`(run_id)

    Return the test ids from the specified run.

    Parameters: | run_id – the id of the test run to query.
    Returns: | a list of test ids for the tests that were part of the specified test run.

  `get_test_run`(run_id)

    Retrieve a TestRun object for run_id.

    Parameters: | run_id – The test run id to retrieve.
    Returns: | A TestRun object.

  `get_test_times`(test_ids)

    Retrieve estimated times for the tests test_ids.

    Parameters: | test_ids – The test ids to query for timing data.
    Returns: | A dict with two keys: ‘known’ and ‘unknown’. The unknown key contains a set with the test ids that did run. The known key contains a dict mapping test ids to time in seconds.

  `latest_id`()

    Return the run id for the most recently inserted test run.

class `stestr.repository.abstract.``AbstractRepositoryFactory`

  Interface for making or opening repositories.

  `initialise`(url)

    Create a repository at URL.

    Call on the class of the repository you wish to create.

  `open`(url)

    Open the repository at url.

    Raise RepositoryNotFound if there is no repository at the given url.

class `stestr.repository.abstract.``AbstractTestRun`

  A test run that has been stored in a repository.

  Should implement the StreamResult protocol as well as the stestr specific methods documented here.

  `get_id`()

    Get the id of the test run.

    Sometimes test runs will not have an id, e.g. test runs for ‘failing’. In that case, this should return None.

  `get_metadata`()

    Get the metadata value for the test run.

    Returns: | A string of the metadata or None if it doesn’t exist.

  `get_subunit_stream`()

    Get a subunit stream for this test run.

  `get_test`()

    Get a testtools.TestCase-like object that can be run.

    Returns: | A TestCase like object which can be run to get the individual tests reported to a testtools.StreamResult/TestResult. (Clients of repository should provide an ExtendedToStreamDecorator decorator to permit either API to be used).

exception `stestr.repository.abstract.``RepositoryNotFound`(url)

  Raised when we try to open a repository that isn’t there.