# 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
        test_ids = frozenset(['zero1', 'zero2'])
        partitions = scheduler.partition_tests(test_ids, 2, repo, None)
        self.assertEqual(1, len(partitions[0]))
        self.assertEqual(1, len(partitions[1]))

    def test_partition_tests_with_grouping(self):
        repo = memory.RepositoryFactory().initialise('memory:')
        result = repo.get_inserter()
        result.startTestRun()
        self._add_timed_test("TestCase1.slow", 3, result)
        self._add_timed_test("TestCase2.fast1", 1, result)
        self._add_timed_test("TestCase2.fast2", 1, result)
        result.stopTestRun()
        test_ids = frozenset(['TestCase1.slow', 'TestCase1.fast',
                              'TestCase1.fast2', 'TestCase2.fast1',
                              'TestCase3.test1', 'TestCase3.test2',
                              'TestCase2.fast2', 'TestCase4.test',
                              '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])

# 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

        test_ids = frozenset(['zero1', 'zero2'])
        partitions = scheduler.partition_tests(test_ids, 2, repo, None)
        self.assertEqual(1, len(partitions[0]))
        self.assertEqual(1, len(partitions[1]))

    def test_partition_tests_with_grouping(self):
        repo = memory.RepositoryFactory().initialise('memory:')
        result = repo.get_inserter()
        result.startTestRun()
        self._add_timed_test("TestCase1.slow", 3, result)
        self._add_timed_test("TestCase2.fast1", 1, result)
        self._add_timed_test("TestCase2.fast2", 1, result)
        result.stopTestRun()
        test_ids = frozenset(['TestCase1.slow', 'TestCase1.fast',
                              'TestCase1.fast2', 'TestCase2.fast1',
                              'TestCase3.test1', 'TestCase3.test2',
                              'TestCase2.fast2', 'TestCase4.test',
                              '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])