summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/util.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-07-19 20:18:21 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-07-19 20:18:21 (GMT)
commitd7b0eebcaea618c982eff7ed92054292b9281d1f (patch)
tree44770fc0c2b7bc4a01f2a041dfd0d484b6c4ab00 /Lib/unittest/util.py
parent5fee460bfabc248ca8c14fc2403fdfabf5051dad (diff)
downloadcpython-d7b0eebcaea618c982eff7ed92054292b9281d1f.zip
cpython-d7b0eebcaea618c982eff7ed92054292b9281d1f.tar.gz
cpython-d7b0eebcaea618c982eff7ed92054292b9281d1f.tar.bz2
split unittest.py into a package
Diffstat (limited to 'Lib/unittest/util.py')
-rw-r--r--Lib/unittest/util.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/unittest/util.py b/Lib/unittest/util.py
new file mode 100644
index 0000000..2546e20
--- /dev/null
+++ b/Lib/unittest/util.py
@@ -0,0 +1,44 @@
+"""Various utility functions."""
+
+def strclass(cls):
+ return "%s.%s" % (cls.__module__, cls.__name__)
+
+def sorted_list_difference(expected, actual):
+ """Finds elements in only one or the other of two, sorted input lists.
+
+ Returns a two-element tuple of lists. The first list contains those
+ elements in the "expected" list but not in the "actual" list, and the
+ second contains those elements in the "actual" list but not in the
+ "expected" list. Duplicate elements in either input list are ignored.
+ """
+ i = j = 0
+ missing = []
+ unexpected = []
+ while True:
+ try:
+ e = expected[i]
+ a = actual[j]
+ if e < a:
+ missing.append(e)
+ i += 1
+ while expected[i] == e:
+ i += 1
+ elif e > a:
+ unexpected.append(a)
+ j += 1
+ while actual[j] == a:
+ j += 1
+ else:
+ i += 1
+ try:
+ while expected[i] == e:
+ i += 1
+ finally:
+ j += 1
+ while actual[j] == a:
+ j += 1
+ except IndexError:
+ missing.extend(expected[i:])
+ unexpected.extend(actual[j:])
+ break
+ return missing, unexpected