# 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
        self._subunit = None
        self._run_id = run_id
        self._metadata = metadata
        # Create a new session factory
        self.engine = sqlalchemy.create_engine(self._repository.base)
        self.session_factory = orm.sessionmaker(bind=self.engine,
                                                autocommit=True)

    def startTestRun(self):
        self._subunit = io.BytesIO()
        self.subunit_stream = subunit.v2.StreamResultToBytes(self._subunit)
        self.hook = testtools.CopyStreamResult([
            testtools.StreamToDict(self._handle_test),
            self.subunit_stream])
        self.hook.startTestRun()
        self.start_time = datetime.datetime.utcnow()
        session = self.session_factory()
        if not self._run_id:
            self.run = db_api.create_run(session=session)
            if self._metadata:
                db_api.add_run_metadata({'stestr_run_meta': self._metadata},
                                        self.run.id, session=session)
            self._run_id = self.run.uuid
        else:
            int_id = db_api.get_run_id_from_uuid(self._run_id, session=session)
            self.run = db_api.get_run_by_id(int_id, session=session)
        session.close()
        self.totals = {}

    def _update_test(self, test_dict, session, start_time, stop_time):

# 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

        self._subunit = None
        self._run_id = run_id
        self._metadata = metadata
        # Create a new session factory
        self.engine = sqlalchemy.create_engine(self._repository.base)
        self.session_factory = orm.sessionmaker(bind=self.engine,
                                                autocommit=True)

    def startTestRun(self):
        self._subunit = io.BytesIO()
        self.subunit_stream = subunit.v2.StreamResultToBytes(self._subunit)
        self.hook = testtools.CopyStreamResult([
            testtools.StreamToDict(self._handle_test),
            self.subunit_stream])
        self.hook.startTestRun()
        self.start_time = datetime.datetime.utcnow()
        session = self.session_factory()
        if not self._run_id:
            self.run = db_api.create_run(session=session)
            if self._metadata:
                db_api.add_run_metadata({'stestr_run_meta': self._metadata},
                                        self.run.id, session=session)
            self._run_id = self.run.uuid
        else:
            int_id = db_api.get_run_id_from_uuid(self._run_id, session=session)
            self.run = db_api.get_run_by_id(int_id, session=session)
        session.close()
        self.totals = {}

    def _update_test(self, test_dict, session, start_time, stop_time):

        test_id = utils.cleanup_test_name(test_dict['id'])