]> granicus.if.org Git - python/commitdiff
Add tests for weakref support for generator-iterators.
authorFred Drake <fdrake@acm.org>
Fri, 9 Aug 2002 18:37:10 +0000 (18:37 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 9 Aug 2002 18:37:10 +0000 (18:37 +0000)
Part of fixing SF bug #591704.

Lib/test/test_generators.py

index 170d92ec726c66a3c6758265a29a23ef3eb179dd..9078b5564e221218e83b828036230783a9f7894b 100644 (file)
@@ -1359,12 +1359,38 @@ Solution 2
 +---+---+---+---+---+---+---+---+---+---+
 """
 
+weakref_tests = """\
+Generators are weakly referencable:
+
+>>> import weakref
+>>> def gen():
+...     yield 'foo!'
+...
+>>> wr = weakref.ref(gen)
+>>> wr() is gen
+True
+>>> p = weakref.proxy(gen)
+
+Generator-iterators are weakly referencable as well:
+
+>>> gi = gen()
+>>> wr = weakref.ref(gi)
+>>> wr() is gi
+True
+>>> p = weakref.proxy(gi)
+>>> list(p)
+['foo!']
+
+"""
+
 __test__ = {"tut":      tutorial_tests,
             "pep":      pep_tests,
             "email":    email_tests,
             "fun":      fun_tests,
             "syntax":   syntax_tests,
-            "conjoin":  conjoin_tests}
+            "conjoin":  conjoin_tests,
+            "weakref":  weakref_tests,
+            }
 
 # Magic test name that regrtest.py invokes *after* importing this module.
 # This worms around a bootstrap problem.