/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

(spiv) Better (and simpler) algorithm for partition_tests. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import difflib
35
35
import doctest
36
36
import errno
 
37
import itertools
37
38
import logging
38
39
import math
39
40
import os
3196
3197
 
3197
3198
def partition_tests(suite, count):
3198
3199
    """Partition suite into count lists of tests."""
3199
 
    result = []
3200
 
    tests = list(iter_suite_tests(suite))
3201
 
    tests_per_process = int(math.ceil(float(len(tests)) / count))
3202
 
    for block in range(count):
3203
 
        low_test = block * tests_per_process
3204
 
        high_test = low_test + tests_per_process
3205
 
        process_tests = tests[low_test:high_test]
3206
 
        result.append(process_tests)
3207
 
    return result
 
3200
    # This just assigns tests in a round-robin fashion.  On one hand this
 
3201
    # splits up blocks of related tests that might run faster if they shared
 
3202
    # resources, but on the other it avoids assigning blocks of slow tests to
 
3203
    # just one partition.  So the slowest partition shouldn't be much slower
 
3204
    # than the fastest.
 
3205
    partitions = [list() for i in range(count)]
 
3206
    tests = iter_suite_tests(suite)
 
3207
    for partition, test in itertools.izip(itertools.cycle(partitions), tests):
 
3208
        partition.append(test)
 
3209
    return partitions
3208
3210
 
3209
3211
 
3210
3212
def workaround_zealous_crypto_random():