# Path: stestr/output.py
# def output_table(table, output=sys.stdout):
#     def show_row(row):
# def output_tests(tests, output=sys.stdout):
# def make_result(get_id, output=sys.stdout):
# def output_summary(successful, tests, tests_delta, time, time_delta, values,
#                    output=sys.stdout):
# def output_stream(stream, output=sys.stdout):
#     def __init__(self, process):
#     def _append_return_code_as_test(self):
#     def read(self, count=-1):
#     def readline(self):
#     def readlines(self):
# class ReturnCodeToSubunit:
# 
# Path: stestr/repository/util.py
# def _get_default_repo_url(repo_type):
# def get_repo_open(repo_type, repo_url=None):
# def get_repo_initialise(repo_type, repo_url=None):


import math
import sys
from operator import itemgetter
from cliff import command
from stestr import output
from stestr.repository import util
    instead of just 10. sorted by time.

    :param str repo_type: This is the type of repository to use. Valid choices
        are 'file' and 'sql'.
    :param str repo_url: The url of the repository to use.
    :param bool show_all: Show timing for all tests.
    :param file stdout: The output file to write all output to. By default
        this is sys.stdout

    :return return_code: The exit code for the command. 0 for success and > 0
        for failures.
    :rtype: int
    """

    repo = util.get_repo_open(repo_type, repo_url)
    try:
        latest_id = repo.latest_id()
    except KeyError:
        return 3
    # what happens when there is no timing info?
    test_times = repo.get_test_times(repo.get_test_ids(latest_id))
    known_times = list(test_times['known'].items())
    known_times.sort(key=itemgetter(1), reverse=True)
    if len(known_times) > 0:
        # By default show 10 rows
        if not show_all:
            known_times = known_times[:10]
        known_times = format_times(known_times)
        header = ('Test id', 'Runtime (s)')
        rows = [header] + known_times

# Path: stestr/output.py
# def output_table(table, output=sys.stdout):
#     def show_row(row):
# def output_tests(tests, output=sys.stdout):
# def make_result(get_id, output=sys.stdout):
# def output_summary(successful, tests, tests_delta, time, time_delta, values,
#                    output=sys.stdout):
# def output_stream(stream, output=sys.stdout):
#     def __init__(self, process):
#     def _append_return_code_as_test(self):
#     def read(self, count=-1):
#     def readline(self):
#     def readlines(self):
# class ReturnCodeToSubunit:
# 
# Path: stestr/repository/util.py
# def _get_default_repo_url(repo_type):
# def get_repo_open(repo_type, repo_url=None):
# def get_repo_initialise(repo_type, repo_url=None):


# Path: stestr/commands/slowest.py
import math
import sys
from operator import itemgetter
from cliff import command
from stestr import output
from stestr.repository import util

    instead of just 10. sorted by time.

    :param str repo_type: This is the type of repository to use. Valid choices
        are 'file' and 'sql'.
    :param str repo_url: The url of the repository to use.
    :param bool show_all: Show timing for all tests.
    :param file stdout: The output file to write all output to. By default
        this is sys.stdout

    :return return_code: The exit code for the command. 0 for success and > 0
        for failures.
    :rtype: int
    """

    repo = util.get_repo_open(repo_type, repo_url)
    try:
        latest_id = repo.latest_id()
    except KeyError:
        return 3
    # what happens when there is no timing info?
    test_times = repo.get_test_times(repo.get_test_ids(latest_id))
    known_times = list(test_times['known'].items())
    known_times.sort(key=itemgetter(1), reverse=True)
    if len(known_times) > 0:
        # By default show 10 rows
        if not show_all:
            known_times = known_times[:10]
        known_times = format_times(known_times)
        header = ('Test id', 'Runtime (s)')
        rows = [header] + known_times

        output.output_table(rows, output=stdout)