Commits

Philip Jenvey committed 7ce5e8d

hack hack hack around appdirect failures

  • Participants
  • Parent commits b6db8a2
  • Branches py3k

Comments (0)

Files changed (1)

pypy/module/imp/test/test_import.py

 def _setup(cls):
     space = cls.space
     dn = setup_directory_structure(cls)
-    return space.appexec([space.wrap(dn)], """
+    return _setup_path(space, dn)
+
+def _setup_path(space, path):
+    return space.appexec([space.wrap(path)], """
         (dn): 
             import sys
             path = list(sys.path)
         import time
         time.sleep(1)
 
-        f = open(test_reload.__file__, "w")
-        f.write("def test():\n    raise NotImplementedError\n")
-        f.close()
+        with open(test_reload.__file__, "w") as f:
+            f.write("def test():\n    raise NotImplementedError\n")
         imp.reload(test_reload)
         try:
             test_reload.test()
         import os
         os.unlink(test_reload.__file__)
 
+        # restore it for later tests
+        with open(test_reload.__file__, "w") as f:
+            f.write("def test():\n    raise ValueError\n")
+
     def test_reload_failing(self):
         import test_reload
         import time, imp
     def setup_class(cls):
         mydir = os.path.dirname(__file__)
         cls.w_hooktest = cls.space.wrap(os.path.join(mydir, 'hooktest'))
-        cls.space.appexec([cls.space.wrap(mydir)], """
-            (mydir):
-                import sys
-                sys.path.append(mydir)
-
+        cls.w_saved_modules = _setup_path(cls.space, mydir)
+        cls.space.appexec([], """
+            ():
                 # Obscure: manually bootstrap the utf-8/latin1 codecs
                 # for TextIOs opened by imp.find_module. It's not
                 # otherwise loaded by the test infrastructure but would
         """)
 
     def teardown_class(cls):
-        cls.space.appexec([], """
-            ():
-                import sys
-                sys.path.pop()
-        """)
+        _teardown(cls.space, cls.w_saved_modules)
 
     def test_meta_path(self):
         tried_imports = []