diff options
author | Georg Brandl <georg@python.org> | 2014-10-07 17:42:01 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-07 17:42:01 +0200 |
commit | 52abd65f03505ef10fbe4e517f615b2805baddf2 (patch) | |
tree | 485bb5b545848fce40f6ad65682af6166c924805 /tests/test_regexopt.py | |
parent | 06af846e38aa39e526454c215d80fe0edef50e9d (diff) | |
download | pygments-52abd65f03505ef10fbe4e517f615b2805baddf2.tar.gz |
Closes #1041: Fix test suite to pass under Python 2.6.
Diffstat (limited to 'tests/test_regexopt.py')
-rw-r--r-- | tests/test_regexopt.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/test_regexopt.py b/tests/test_regexopt.py index 743d4d72..f62a57ef 100644 --- a/tests/test_regexopt.py +++ b/tests/test_regexopt.py @@ -15,14 +15,26 @@ import itertools from pygments.regexopt import regex_opt ALPHABET = ['a', 'b', 'c', 'd', 'e'] -N_TRIES = 15 + +try: + from itertools import combinations_with_replacement + N_TRIES = 15 +except ImportError: + # Python 2.6 + def combinations_with_replacement(iterable, r): + pool = tuple(iterable) + n = len(pool) + for indices in itertools.product(range(n), repeat=r): + if sorted(indices) == list(indices): + yield tuple(pool[i] for i in indices) + N_TRIES = 9 class RegexOptTestCase(unittest.TestCase): def generate_keywordlist(self, length): return [''.join(p) for p in - itertools.combinations_with_replacement(ALPHABET, length)] + combinations_with_replacement(ALPHABET, length)] def test_randomly(self): # generate a list of all possible keywords of a certain length using |