# Path: stestr/repository/abstract.py
# class AbstractRepositoryFactory:
# class AbstractRepository:
# class AbstractTestRun:
# class RepositoryNotFound(Exception):
#     def initialise(self, url):
#     def open(self, url):
#     def count(self):
#     def get_failing(self):
#     def get_run_ids(self):
#     def remove_run_id(self, run_id):
#     def get_inserter(self, partial=False, run_id=None, metadata=None):
#     def _get_inserter(self, partial=False, run_id=None, metadata=None):
#     def get_latest_run(self):
#     def get_test_run(self, run_id):
#     def get_test_times(self, test_ids):
#     def _get_test_times(self, test_ids):
#     def latest_id(self):
#     def get_test_ids(self, run_id):
#         def gather(test_dict):
#     def find_metadata(self, metadata):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#     def get_metadata(self):
#     def __init__(self, url):
# 
# Path: stestr/utils.py
# class CallWhenProcFinishes:
#     def __init__(self, process, callback):
#     def stdin(self):
#     def stdout(self):
#     def stderr(self):
#     def returncode(self):
#     def wait(self):
# def _iter_internal_streams(input_streams, stream_type):
# def iter_streams(input_streams, stream_type):
# def cleanup_test_name(name, strip_tags=True, strip_scenarios=False):


import datetime
import io
import os.path
import re
import subprocess
import sys
import sqlalchemy
import subunit.v2
import testtools
from sqlalchemy import orm
from subunit2sql.db import api as db_api
from subunit2sql import read_subunit
from subunit2sql import shell
from subunit2sql import write_subunit
from stestr.repository import abstract as repository
from stestr import utils
            test = test_runs[test_id]
            # NOTE(mtreinish): test_run_metadata is not guaranteed to be
            # present for the test run
            metadata = test.get('metadata', None)
            write_subunit.write_test(output, test['start_time'],
                                     test['stop_time'], test['status'],
                                     test_id, metadata)
        output.stopTestRun()
        stream.seek(0)
        return stream

    def get_test(self):
        stream = self.get_subunit_stream()
        case = subunit.ByteStreamToStreamResult(stream)
        return case

    def get_metadata(self):
        if self._run_id:
            session = self.session_factory()
            metadata = db_api.get_run_metadata(self._run_id, session=session)
            for meta in metadata:
                if meta.key == 'stestr_run_meta':
                    return meta.value
        return None


class _SqlInserter(repository.AbstractTestRun):
    """Insert test results into a sql repository."""

    def __init__(self, repository, partial=False, run_id=None, metadata=None):

# Path: stestr/repository/abstract.py
# class AbstractRepositoryFactory:
# class AbstractRepository:
# class AbstractTestRun:
# class RepositoryNotFound(Exception):
#     def initialise(self, url):
#     def open(self, url):
#     def count(self):
#     def get_failing(self):
#     def get_run_ids(self):
#     def remove_run_id(self, run_id):
#     def get_inserter(self, partial=False, run_id=None, metadata=None):
#     def _get_inserter(self, partial=False, run_id=None, metadata=None):
#     def get_latest_run(self):
#     def get_test_run(self, run_id):
#     def get_test_times(self, test_ids):
#     def _get_test_times(self, test_ids):
#     def latest_id(self):
#     def get_test_ids(self, run_id):
#         def gather(test_dict):
#     def find_metadata(self, metadata):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#     def get_metadata(self):
#     def __init__(self, url):
# 
# Path: stestr/utils.py
# class CallWhenProcFinishes:
#     def __init__(self, process, callback):
#     def stdin(self):
#     def stdout(self):
#     def stderr(self):
#     def returncode(self):
#     def wait(self):
# def _iter_internal_streams(input_streams, stream_type):
# def iter_streams(input_streams, stream_type):
# def cleanup_test_name(name, strip_tags=True, strip_scenarios=False):


# Path: stestr/repository/sql.py
import datetime
import io
import os.path
import re
import subprocess
import sys
import sqlalchemy
import subunit.v2
import testtools
from sqlalchemy import orm
from subunit2sql.db import api as db_api
from subunit2sql import read_subunit
from subunit2sql import shell
from subunit2sql import write_subunit
from stestr.repository import abstract as repository
from stestr import utils

            test = test_runs[test_id]
            # NOTE(mtreinish): test_run_metadata is not guaranteed to be
            # present for the test run
            metadata = test.get('metadata', None)
            write_subunit.write_test(output, test['start_time'],
                                     test['stop_time'], test['status'],
                                     test_id, metadata)
        output.stopTestRun()
        stream.seek(0)
        return stream

    def get_test(self):
        stream = self.get_subunit_stream()
        case = subunit.ByteStreamToStreamResult(stream)
        return case

    def get_metadata(self):
        if self._run_id:
            session = self.session_factory()
            metadata = db_api.get_run_metadata(self._run_id, session=session)
            for meta in metadata:
                if meta.key == 'stestr_run_meta':
                    return meta.value
        return None


class _SqlInserter(repository.AbstractTestRun):
    """Insert test results into a sql repository."""

    def __init__(self, repository, partial=False, run_id=None, metadata=None):

        self._repository = repository