# Path: stestr/repository/memory.py
# class RepositoryFactory(repository.AbstractRepositoryFactory):
# class Repository(repository.AbstractRepository):
# class _Failures(repository.AbstractTestRun):
# class _Inserter(repository.AbstractTestRun):
#     def __init__(self):
#     def initialise(self, url):
#     def open(self, url):
#     def __init__(self):
#     def count(self):
#     def get_failing(self):
#     def get_test_run(self, run_id):
#     def get_run_ids(self):
#     def remove_run_id(self, run_id):
#     def latest_id(self):
#     def _get_inserter(self, partial, run_id=None, metadata=None):
#     def _get_test_times(self, test_ids):
#     def __init__(self, repository):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#         def wrap_result(result):
#     def run(self, result):
#     def __init__(self, repository, partial, run_id=None, metadata=None):
#     def startTestRun(self):
#     def _handle_test(self, test_dict):
#     def stopTestRun(self):
#     def status(self, *args, **kwargs):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#         def wrap_result(result):
#     def run(self, result):
# 
# Path: stestr/scheduler.py
# def partition_tests(test_ids, concurrency, repository, group_callback,
#                     randomize=False):
#     def noop(_):
#     def consume_queue(groups):
# def local_concurrency():
# def generate_worker_partitions(ids, worker_path, repository=None,
#                                group_callback=None, randomize=False):
# 
# Path: stestr/tests/base.py
# class TestCase(testtools.TestCase):
#     def setUp(self):


import datetime
import re
from unittest import mock
from subunit import iso8601
from stestr.repository import memory
from stestr import scheduler
from stestr.tests import base
                              'testdir.testfile.TestCase5.test'])

        def group_id(test_id, regex=re.compile('TestCase[0-5]')):
            match = regex.match(test_id)
            if match:
                return match.group(0)

        partitions = scheduler.partition_tests(test_ids, 2, repo, group_id)
        # Timed groups are deterministic:
        self.assertTrue('TestCase2.fast1' in partitions[0])
        self.assertTrue('TestCase2.fast2' in partitions[0])
        self.assertTrue('TestCase1.slow' in partitions[1])
        self.assertTrue('TestCase1.fast' in partitions[1])
        self.assertTrue('TestCase1.fast2' in partitions[1])
        # Untimed groups just need to be in the same partition:
        if 'TestCase3.test1' in partitions[0]:
            self.assertTrue('TestCase3.test2' in partitions[0])
        if 'TestCase4.test' not in partitions[0]:
            self.assertTrue('TestCase4.test' in partitions[1])
        if 'testdir.testfile.TestCase5.test' not in partitions[0]:
            self.assertTrue('testdir.testfile.TestCase5.test' in partitions[1])

    @mock.patch('builtins.open', mock.mock_open(), create=True)
    def test_generate_worker_partitions(self):
        test_ids = ['test_a', 'test_b', 'your_test']
        fake_worker_yaml = [
            {'worker': ['test_']},
            {'worker': ['test']},
        ]
        with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):

# Path: stestr/repository/memory.py
# class RepositoryFactory(repository.AbstractRepositoryFactory):
# class Repository(repository.AbstractRepository):
# class _Failures(repository.AbstractTestRun):
# class _Inserter(repository.AbstractTestRun):
#     def __init__(self):
#     def initialise(self, url):
#     def open(self, url):
#     def __init__(self):
#     def count(self):
#     def get_failing(self):
#     def get_test_run(self, run_id):
#     def get_run_ids(self):
#     def remove_run_id(self, run_id):
#     def latest_id(self):
#     def _get_inserter(self, partial, run_id=None, metadata=None):
#     def _get_test_times(self, test_ids):
#     def __init__(self, repository):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#         def wrap_result(result):
#     def run(self, result):
#     def __init__(self, repository, partial, run_id=None, metadata=None):
#     def startTestRun(self):
#     def _handle_test(self, test_dict):
#     def stopTestRun(self):
#     def status(self, *args, **kwargs):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#         def wrap_result(result):
#     def run(self, result):
# 
# Path: stestr/scheduler.py
# def partition_tests(test_ids, concurrency, repository, group_callback,
#                     randomize=False):
#     def noop(_):
#     def consume_queue(groups):
# def local_concurrency():
# def generate_worker_partitions(ids, worker_path, repository=None,
#                                group_callback=None, randomize=False):
# 
# Path: stestr/tests/base.py
# class TestCase(testtools.TestCase):
#     def setUp(self):


# Path: stestr/tests/test_scheduler.py
import datetime
import re
from unittest import mock
from subunit import iso8601
from stestr.repository import memory
from stestr import scheduler
from stestr.tests import base

                              'testdir.testfile.TestCase5.test'])

        def group_id(test_id, regex=re.compile('TestCase[0-5]')):
            match = regex.match(test_id)
            if match:
                return match.group(0)

        partitions = scheduler.partition_tests(test_ids, 2, repo, group_id)
        # Timed groups are deterministic:
        self.assertTrue('TestCase2.fast1' in partitions[0])
        self.assertTrue('TestCase2.fast2' in partitions[0])
        self.assertTrue('TestCase1.slow' in partitions[1])
        self.assertTrue('TestCase1.fast' in partitions[1])
        self.assertTrue('TestCase1.fast2' in partitions[1])
        # Untimed groups just need to be in the same partition:
        if 'TestCase3.test1' in partitions[0]:
            self.assertTrue('TestCase3.test2' in partitions[0])
        if 'TestCase4.test' not in partitions[0]:
            self.assertTrue('TestCase4.test' in partitions[1])
        if 'testdir.testfile.TestCase5.test' not in partitions[0]:
            self.assertTrue('testdir.testfile.TestCase5.test' in partitions[1])

    @mock.patch('builtins.open', mock.mock_open(), create=True)
    def test_generate_worker_partitions(self):
        test_ids = ['test_a', 'test_b', 'your_test']
        fake_worker_yaml = [
            {'worker': ['test_']},
            {'worker': ['test']},
        ]
        with mock.patch('yaml.safe_load', return_value=fake_worker_yaml):

            groups = scheduler.generate_worker_partitions(test_ids, 'fakepath')