~testing-cabal/testtools/trunk

« back to all changes in this revision

Viewing changes to testtools/testsuite.py

  • Committer: Robert Collins
  • Author(s): hugovk
  • Date: 2018-01-09 12:25:34 UTC
  • Revision ID: git-v1:0a609e10198a818ba21d607107a667cb95afef0a
Remove old Python 2.6 code

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
    'sorted_tests',
11
11
]
12
12
 
 
13
from collections import Counter
13
14
from pprint import pformat
14
15
import sys
15
16
import threading
301
302
    return suite_or_case
302
303
 
303
304
 
304
 
# XXX: Python 2.6. Replace this with Counter when we drop 2.6 support.
305
 
def _counter(xs):
306
 
    """Return a dict mapping values of xs to number of times they appear."""
307
 
    counts = {}
308
 
    for x in xs:
309
 
        times = counts.setdefault(x, 0)
310
 
        counts[x] = times + 1
311
 
    return counts
312
 
 
313
 
 
314
305
def sorted_tests(suite_or_case, unpack_outer=False):
315
306
    """Sort suite_or_case while preserving non-vanilla TestSuites."""
316
307
    # Duplicate test id can induce TypeError in Python 3.3.
317
308
    # Detect the duplicate test ids, raise exception when found.
318
 
    seen = _counter(case.id() for case in iterate_tests(suite_or_case))
 
309
    seen = Counter(case.id() for case in iterate_tests(suite_or_case))
319
310
    duplicates = dict(
320
311
        (test_id, count) for test_id, count in seen.items() if count > 1)
321
312
    if duplicates: