diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-05 17:35:20 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-05 17:35:20 (GMT) |
commit | de6024872abe4fd95972036db63d0a57cf557f94 (patch) | |
tree | 4390aab05bcd1462be258ea9cf164f3a0b772cd9 /Lib/test | |
parent | 2524d699f572c5839dcc5c6a7ce06533ac2ef0a6 (diff) | |
download | cpython-de6024872abe4fd95972036db63d0a57cf557f94.zip cpython-de6024872abe4fd95972036db63d0a57cf557f94.tar.gz cpython-de6024872abe4fd95972036db63d0a57cf557f94.tar.bz2 |
Fix test 9 (caught by ?!ng)
Add tests for unbound locals (Nick Mathewson)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/output/test_scope | 1 | ||||
-rw-r--r-- | Lib/test/test_scope.py | 31 |
2 files changed, 31 insertions, 1 deletions
diff --git a/Lib/test/output/test_scope b/Lib/test/output/test_scope index 3ada943..17e5cb8 100644 --- a/Lib/test/output/test_scope +++ b/Lib/test/output/test_scope @@ -11,3 +11,4 @@ test_scope 10. recursion 11. unoptimized namespaces 12. lambdas +13. UnboundLocal diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 8be3f61..57c0dcb 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -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 + |