summaryrefslogtreecommitdiff
path: root/lib/testtools/utils.py
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-03-31 03:19:18 +0200
committerJelmer Vernooij <jelmer@samba.org>2010-03-31 03:19:18 +0200
commita8ac7fda573a924debf165d39eff3c1837240d4f (patch)
tree6085df961a5fbcc57a240d7065d2fc4a258cf170 /lib/testtools/utils.py
parente4af3afd7ae3e39218b42a42d39c2ec10be9a642 (diff)
downloadsamba-a8ac7fda573a924debf165d39eff3c1837240d4f.tar.gz
samba-a8ac7fda573a924debf165d39eff3c1837240d4f.tar.bz2
samba-a8ac7fda573a924debf165d39eff3c1837240d4f.zip
Put testtools directly under lib/ to make it easier to install from Samba 4.
Diffstat (limited to 'lib/testtools/utils.py')
-rw-r--r--lib/testtools/utils.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/testtools/utils.py b/lib/testtools/utils.py
new file mode 100644
index 0000000000..c0845b610c
--- /dev/null
+++ b/lib/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