]> granicus.if.org Git - python/commitdiff
Fix test 9 (caught by ?!ng)
authorJeremy Hylton <jeremy@alum.mit.edu>
Mon, 5 Feb 2001 17:35:20 +0000 (17:35 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Mon, 5 Feb 2001 17:35:20 +0000 (17:35 +0000)
Add tests for unbound locals (Nick Mathewson)

Lib/test/output/test_scope
Lib/test/test_scope.py

index 3ada943b3519d52730ee165a3217fc3490c77171..17e5cb80fa9d993c846b193ac851d3f15839efe9 100644 (file)
@@ -11,3 +11,4 @@ test_scope
 10. recursion
 11. unoptimized namespaces
 12. lambdas
+13. UnboundLocal
index 8be3f6185f828f4ad50c201ae4986f9e4ecf2e15..57c0dcb269c64c34c09048e2f72163a58ce43077 100644 (file)
@@ -154,7 +154,7 @@ class Test:
     def str(self):
         return str(self)
 
-t = test()
+t = Test()
 verify(t.test() == "var")
 verify(t.method_and_var() == "method")
 verify(t.actual_global() == "global")
@@ -247,3 +247,32 @@ f8 = lambda x, y, z: lambda a, b, c: lambda : z * (b + y)
 g = f8(1, 2, 3)
 h = g(2, 4, 6)
 verify(h() == 18)
+
+print "13. UnboundLocal"
+
+def errorInOuter():
+    print y
+    def inner():
+        return y
+    y = 1
+
+def errorInInner():
+    def inner():
+        return y
+    inner()
+    y = 1
+
+try:
+    errorInOuter()
+except UnboundLocalError:
+    pass
+else:
+    raise TestFailed
+
+try:
+    errorInInner()
+except UnboundLocalError:
+    pass
+else:
+    raise TestFailed
+