def test_import_in_nested_blocks(self): """using import in nested blocks""" #del time # picked this up from iptest.assert_util def f(): import time now = time.time() f() try: print(time) except NameError: pass else: self.fail("time should be undefined") def f(): import time as t now = t.time() try: now = time except NameError: pass else: self.fail("time should be undefined") f() try: print(time) except NameError: pass else: self.fail("time should be undefined") def f(): from time import clock now = clock() try: now = time except NameError: pass else: self.fail("time should be undefined") f() try: print(time) except NameError: pass else: self.fail("time should be undefined") try: print(clock) except NameError: pass else: self.fail("clock should be undefined") def f(): from time import clock as c now = c() try: now = time except NameError: pass else: self.fail("time should be undefined") try: now = clock except NameError: pass else: self.fail("clock should be undefined") f() try: print(time) except NameError: pass else: self.fail("time should be undefined") try: print(clock) except NameError: pass else: self.fail("clock should be undefined") # with closures def f(): def g(): now = clock_in_closure() from time import clock as clock_in_closure g() f()
result = sys.modules #u = sys.modules.pop("iptest") g = sys.modules.pop("ImportTestDir.Gen") from ImportTestDir import Gen AreEqual(Gen.gen().next(), "yield inside try") ######################################################################################### # using import in nested blocks del time # picked this up from iptest.assert_util def f(): import time now = time.time() f() try: print time except NameError: pass else: Fail("time should be undefined") def f(): import time as t now = t.time() try: now = time except NameError: pass else: Fail("time should be undefined") f()
def test_import_in_nested_blocks(self): """using import in nested blocks""" #del time # picked this up from iptest.assert_util def f(): import time now = time.time() f() try: print time except NameError: pass else: self.fail("time should be undefined") def f(): import time as t now = t.time() try: now = time except NameError: pass else: self.fail("time should be undefined") f() try: print time except NameError: pass else: self.fail("time should be undefined") def f(): from time import clock now = clock() try: now = time except NameError: pass else: self.fail("time should be undefined") f() try: print time except NameError: pass else: self.fail("time should be undefined") try: print clock except NameError: pass else: self.fail("clock should be undefined") def f(): from time import clock as c now = c() try: now = time except NameError: pass else: self.fail("time should be undefined") try: now = clock except NameError: pass else: self.fail("clock should be undefined") f() try: print time except NameError: pass else: self.fail("time should be undefined") try: print clock except NameError: pass else: self.fail("clock should be undefined") # with closures def f(): def g(): now = clock_in_closure() from time import clock as clock_in_closure g() f()