summaryrefslogtreecommitdiff
path: root/lib/subunit/python/testtools/utils.py
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-01-08 02:09:20 +0100
committerJelmer Vernooij <jelmer@samba.org>2010-01-16 19:53:49 +1300
commit28577aae928847e64a0274b5922e26e1f15d9916 (patch)
tree78f6b36e8166d3320120df0e1bc91fef7ce8f9b1 /lib/subunit/python/testtools/utils.py
parentb6b46b4978dcaffa0cd9803c43b8a5f1c19e227e (diff)
downloadsamba-28577aae928847e64a0274b5922e26e1f15d9916.tar.gz
samba-28577aae928847e64a0274b5922e26e1f15d9916.tar.bz2
samba-28577aae928847e64a0274b5922e26e1f15d9916.zip
Import testtools as well, required for subunit.
Diffstat (limited to 'lib/subunit/python/testtools/utils.py')
-rw-r--r--lib/subunit/python/testtools/utils.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/subunit/python/testtools/utils.py b/lib/subunit/python/testtools/utils.py
new file mode 100644
index 0000000000..325572297b
--- /dev/null
+++ b/lib/subunit/python/testtools/utils.py
@@ -0,0 +1,39 @@
+# Copyright (c) 2008 Jonathan M. Lange. See LICENSE for details.
+
+"""Utilities for dealing with stuff in unittest."""
+
+
+import sys
+
+__metaclass__ = type
+__all__ = [
+ 'iterate_tests',
+ ]
+
+
+if sys.version_info > (3, 0):
+ def _u(s):
+ """Replacement for u'some string' in Python 3."""
+ return s
+ def _b(s):
+ """A byte literal."""
+ return s.encode("latin-1")
+ advance_iterator = next
+else:
+ def _u(s):
+ return unicode(s, "latin-1")
+ def _b(s):
+ return s
+ advance_iterator = lambda it: it.next()
+
+
+def iterate_tests(test_suite_or_case):
+ """Iterate through all of the test cases in `test_suite_or_case`."""
+ try:
+ suite = iter(test_suite_or_case)
+ except TypeError:
+ yield test_suite_or_case
+ else:
+ for test in suite:
+ for subtest in iterate_tests(test):
+ yield subtest