summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/string_asserts.py4
-rw-r--r--tests/test_regexopt.py16
-rw-r--r--tests/test_string_asserts.py12
3 files changed, 20 insertions, 12 deletions
diff --git a/tests/string_asserts.py b/tests/string_asserts.py
index 025a5281..3aa50420 100644
--- a/tests/string_asserts.py
+++ b/tests/string_asserts.py
@@ -11,12 +11,12 @@ class StringTests(object):
def assertStartsWith(self, haystack, needle, msg=None):
if msg is None:
- msg = "'{}' does not start with '{}'".format(haystack, needle)
+ msg = "'{0}' does not start with '{1}'".format(haystack, needle)
if not haystack.startswith(needle):
raise(AssertionError(msg))
def assertEndsWith(self, haystack, needle, msg=None):
if msg is None:
- msg = "'{}' does not end with '{}'".format(haystack, needle)
+ msg = "'{0}' does not end with '{1}'".format(haystack, needle)
if not haystack.endswith(needle):
raise(AssertionError(msg))
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
diff --git a/tests/test_string_asserts.py b/tests/test_string_asserts.py
index 0beed15c..90d81d67 100644
--- a/tests/test_string_asserts.py
+++ b/tests/test_string_asserts.py
@@ -17,23 +17,19 @@ class TestStringTests(StringTests, unittest.TestCase):
# @unittest.expectedFailure not supported by nose
def test_startswith_incorrect(self):
- with self.assertRaises(AssertionError):
- self.assertStartsWith("AAA", "B")
+ self.assertRaises(AssertionError, self.assertStartsWith, "AAA", "B")
# @unittest.expectedFailure not supported by nose
def test_startswith_short(self):
- with self.assertRaises(AssertionError):
- self.assertStartsWith("A", "AA")
+ self.assertRaises(AssertionError, self.assertStartsWith, "A", "AA")
def test_endswith_correct(self):
self.assertEndsWith("AAA", "A")
# @unittest.expectedFailure not supported by nose
def test_endswith_incorrect(self):
- with self.assertRaises(AssertionError):
- self.assertEndsWith("AAA", "B")
+ self.assertRaises(AssertionError, self.assertEndsWith, "AAA", "B")
# @unittest.expectedFailure not supported by nose
def test_endswith_short(self):
- with self.assertRaises(AssertionError):
- self.assertEndsWith("A", "AA")
+ self.assertRaises(AssertionError, self.assertEndsWith, "A", "AA")