def test_partition_tests_914359(self):
     # When two partitions have the same duration, timed tests should be
     # appended to the shortest partition. In theory this doesn't matter,
     # but in practice, if a test is recorded with 0 duration (e.g. due to a
     # bug), it is better to have them split out rather than all in one
     # partition. 0 duration tests are unlikely to really be 0 duration.
     repo = memory.RepositoryFactory().initialise('memory:')
     # Seed with two 0-duration tests.
     result = repo.get_inserter()
     result.startTestRun()
     run_timed("zero1", 0, result)
     run_timed("zero2", 0, result)
     result.stopTestRun()
     ui, command = self.get_test_ui_and_cmd(repository=repo)
     self.set_config('[DEFAULT]\ntest_command=foo $IDLIST\n')
     fixture = self.useFixture(command.get_run_command())
     # partitioning by two should generate two one-entry partitions.
     test_ids = frozenset(['zero1', 'zero2'])
     partitions = fixture.partition_tests(test_ids, 2)
     self.assertEqual(1, len(partitions[0]))
     self.assertEqual(1, len(partitions[1]))
Exemple #2
0
 def test_partition_tests_smoke(self):
     repo = memory.RepositoryFactory().initialise('memory:')
     # Seed with 1 slow and 2 tests making up 2/3 the time.
     result = repo.get_inserter()
     result.startTestRun()
     run_timed("slow", 3, result)
     run_timed("fast1", 1, result)
     run_timed("fast2", 1, result)
     result.stopTestRun()
     ui, command = self.get_test_ui_and_cmd(repository=repo)
     self.set_config(
         '[DEFAULT]\ntest_command=foo $IDLIST $LISTOPT\n'
         'test_list_option=--list\n')
     fixture = self.useFixture(command.get_run_command())
     # partitioning by two generates 'slow' and the two fast ones as partitions
     # flushed out by equal numbers of unknown duration tests.
     test_ids = frozenset(['slow', 'fast1', 'fast2', 'unknown1', 'unknown2',
         'unknown3', 'unknown4'])
     partitions = fixture.partition_tests(test_ids, 2)
     self.assertTrue('slow' in partitions[0])
     self.assertFalse('fast1' in partitions[0])
     self.assertFalse('fast2' in partitions[0])
     self.assertFalse('slow' in partitions[1])
     self.assertTrue('fast1' in partitions[1])
     self.assertTrue('fast2' in partitions[1])
     self.assertEqual(3, len(partitions[0]))
     self.assertEqual(4, len(partitions[1]))
 def test_partition_tests_914359(self):
     # When two partitions have the same duration, timed tests should be
     # appended to the shortest partition. In theory this doesn't matter,
     # but in practice, if a test is recorded with 0 duration (e.g. due to a
     # bug), it is better to have them split out rather than all in one
     # partition. 0 duration tests are unlikely to really be 0 duration.
     repo = memory.RepositoryFactory().initialise('memory:')
     # Seed with two 0-duration tests.
     result = repo.get_inserter()
     result.startTestRun()
     run_timed("zero1", 0, result)
     run_timed("zero2", 0, result)
     result.stopTestRun()
     ui, command = self.get_test_ui_and_cmd(repository=repo)
     self.set_config(
         '[DEFAULT]\ntest_command=foo $IDLIST\n')
     fixture = self.useFixture(command.get_run_command())
     # partitioning by two should generate two one-entry partitions.
     test_ids = frozenset(['zero1', 'zero2'])
     partitions = fixture.partition_tests(test_ids, 2)
     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()
        run_timed("TestCase1.slow", 3, result)
        run_timed("TestCase2.fast1", 1, result)
        run_timed("TestCase2.fast2", 1, result)
        result.stopTestRun()
        ui, command = self.get_test_ui_and_cmd(repository=repo)
        self.set_config('[DEFAULT]\ntest_command=foo $IDLIST $LISTOPT\n'
                        'test_list_option=--list\n')
        fixture = self.useFixture(command.get_run_command())
        test_ids = frozenset([
            'TestCase1.slow', 'TestCase1.fast', 'TestCase1.fast2',
            'TestCase2.fast1', 'TestCase3.test1', 'TestCase3.test2',
            'TestCase2.fast2', 'TestCase4.test',
            'testdir.testfile.TestCase5.test'
        ])
        regex = 'TestCase[0-5]'

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

        # There isn't a public way to define a group callback [as yet].
        fixture._group_callback = group_id
        partitions = fixture.partition_tests(test_ids, 2)
        # 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 kept together:
        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])
 def test_partition_tests_with_grouping(self):
     repo = memory.RepositoryFactory().initialise('memory:')
     result = repo.get_inserter()
     result.startTestRun()
     run_timed("TestCase1.slow", 3, result)
     run_timed("TestCase2.fast1", 1, result)
     run_timed("TestCase2.fast2", 1, result)
     result.stopTestRun()
     ui, command = self.get_test_ui_and_cmd(repository=repo)
     self.set_config(
         '[DEFAULT]\ntest_command=foo $IDLIST $LISTOPT\n'
         'test_list_option=--list\n')
     fixture = self.useFixture(command.get_run_command())
     test_ids = frozenset(['TestCase1.slow', 'TestCase1.fast',
                           'TestCase1.fast2', 'TestCase2.fast1',
                           'TestCase3.test1', 'TestCase3.test2',
                           'TestCase2.fast2', 'TestCase4.test',
                           'testdir.testfile.TestCase5.test'])
     regex = 'TestCase[0-5]'
     def group_id(test_id, regex=re.compile('TestCase[0-5]')):
         match = regex.match(test_id)
         if match:
             return match.group(0)
     # There isn't a public way to define a group callback [as yet].
     fixture._group_callback = group_id
     partitions = fixture.partition_tests(test_ids, 2)
     # 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 kept together:
     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])