diff options
author | Raymond Hettinger <python@rcn.com> | 2009-01-27 09:52:35 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-01-27 09:52:35 (GMT) |
commit | f93f3032c63906d0a6516d6e75985f0d425f36f5 (patch) | |
tree | f0a305225d17ee6a2a5734e1f7bae8db5eae83c2 | |
parent | 2976aaa39666229fa9591f219b4642f8ccbcc30a (diff) | |
download | cpython-f93f3032c63906d0a6516d6e75985f0d425f36f5.zip cpython-f93f3032c63906d0a6516d6e75985f0d425f36f5.tar.gz cpython-f93f3032c63906d0a6516d6e75985f0d425f36f5.tar.bz2 |
Stronger tests for combinatoric relationships.
-rw-r--r-- | Lib/doctest.py | 4 | ||||
-rw-r--r-- | Lib/test/test_itertools.py | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 3f2baa5..aeeb15d 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -844,6 +844,8 @@ class DocTestFinder: globs = globs.copy() if extraglobs is not None: globs.update(extraglobs) + if '__name__' not in globs: + globs['__name__'] = '__main__' # provide a default module name # Recursively expore `obj`, extracting DocTests. tests = [] @@ -1937,6 +1939,8 @@ def testfile(filename, module_relative=True, name=None, package=None, globs = globs.copy() if extraglobs is not None: globs.update(extraglobs) + if '__name__' not in globs: + globs['__name__'] = '__main__' if raise_on_error: runner = DebugRunner(verbose=verbose, optionflags=optionflags) diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 8d8e059..09908d6 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -281,11 +281,15 @@ class TestBasicOps(unittest.TestCase): perm = list(permutations(s, r)) comb = list(combinations(s, r)) + self.assertEquals(len(prod), len(s)**r) + self.assertEquals(prod, sorted(set(prod))) # prod in lexicographic order without repeats self.assertEquals(cwr, [t for t in prod if sorted(t)==list(t)]) # cwr: prods which are sorted self.assertEquals(perm, [t for t in prod if len(set(t))==r]) # perm: prods with no dups self.assertEqual(comb, [t for t in perm if sorted(t)==list(t)]) # comb: perms that are sorted self.assertEqual(comb, [t for t in cwr if len(set(t))==r]) # comb: cwrs without dups - self.assertEqual(set(comb), set(cwr) & set(perm)) # comb: both a cwr and a perm + self.assertEqual(comb, filter(set(cwr).__contains__, perm)) # comb: perm that is a cwr + self.assertEqual(comb, filter(set(perm).__contains__, cwr)) # comb: cwr that is a perm + self.assertEqual(comb, sorted(set(cwr) & set(perm))) # comb: both a cwr and a perm def test_compress(self): self.assertEqual(list(compress('ABCDEF', [1,0,1,0,1,1])), list('ACEF')) |