# Internal API Reference

This document serves as a reference for the python API used in stestr. It should serve as a guide for both internal and external use of stestr components via python. The majority of the contents here are built from internal docstrings in the actual code.

## Repository

- Abstract Repository Class
  - `AbstractRepository`
  - `AbstractRepositoryFactory`
  - `AbstractTestRun`
  - `RepositoryNotFound`
- File Repository Type
  - `Repository`
  - `RepositoryFactory`
- Memory Repository Type
  - `Repository`
  - `RepositoryFactory`

## Commands

These modules are used for the operation of all the various subcommands in stestr. As of the 1.0.0 release each of these commands should be considered a stable interface that can be relied on externally.

Each command module conforms to a basic format that is based on the cliff framework. The basic structure for these modules is the following three functions in each class:

    def get_description():
        """This function returns a string that is used for the subcommand help"""
        help_str = "A descriptive help string about the command"
        return help_str

    def get_parser(prog_name):
        """This function takes a parser and any subcommand arguments are defined
           here"""
        parser.add_argument(...)

    def take_action(parsed_args):
        """This is where the real work for the command is performed. This is the function
           that is called when the command is executed. This function is called being
           wrapped by sys.exit() so an integer return is expected that will be used
           for the command's return code. The arguments input parsed_args is the
           argparse.Namespace object from the parsed CLI options."""
        return call_foo(...)

The command class will not work if all 3 of these function are not defined. However, to make the commands externally consumable each module also contains another public function which performs the real work for the command. Each one of these functions has a defined stable Python API signature with args and kwargs so that people can easily call the functions from other python programs. This function is what can be expected to be used outside of stestr as the stable interface. All the stable functions can be imported the command module directly:

    from stestr import command

    def my_list():
        command.list_command(...)

- stestr Commands
  - `failing_command()`
  - `history_list_command()`
  - `history_remove_command()`
  - `history_show_command()`
  - `init_command()`
  - `last_command()`
  - `list_command()`
  - `load_command()`
  - `run_command()`
  - `slowest_command()`
- stestr failing Command
  - `Failing`
  - `failing()`
- stestr init Command
  - `Init`
  - `init()`
- stestr last Command
  - `Last`
  - `last()`
- stestr list Command
  - `List`
  - `list_command()`
- stestr load Command
  - `Load`
  - `load()`
- stestr run Command
  - `Run`
  - `run_command()`
- stestr slowest Command
  - `Slowest`
  - `slowest()`

## Internal APIs

The modules in this list do not necessarily have any external api contract, they are intended for internal use inside of stestr. If anything in these provides a stable contract and is intended for usage outside of stestr it will be noted in the api doc.

- Configuration File Module
  - `TestrConf`
- Test Selection Module
  - `construct_list()`
  - `filter_tests()`
- The Scheduler Module
  - `generate_worker_partitions()`
  - `local_concurrency()`
  - `partition_tests()`
- The Output Module
  - `ReturnCodeToSubunit`
  - `output_summary()`
  - `output_table()`
  - `output_tests()`
- Test Processor Module
  - API Reference
- Subunit Trace
  - `cleanup_test_name()`
  - `find_worker()`
  - `print_attachments()`
  - `print_fails()`
  - `print_full_output()`