[pypy-svn] r4782 - pypy/trunk/src/pypy/module/test

hpk at codespeak.net hpk at codespeak.net
Mon May 31 19:04:57 CEST 2004


Author: hpk
Date: Mon May 31 19:04:44 2004
New Revision: 4782

Modified:
   pypy/trunk/src/pypy/module/test/test_import.py
Log:
use os.chdir and back to import from 'impsubdir' 


Modified: pypy/trunk/src/pypy/module/test/test_import.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_import.py	(original)
+++ pypy/trunk/src/pypy/module/test/test_import.py	Mon May 31 19:04:44 2004
@@ -1,41 +1,47 @@
 import autopath
 from pypy.tool import testit
+import os
 
-class TestImport(testit.AppTestCase):
+class TestImport(testit.AppTestCase): 
+    def setUp(self): # interpreter-level
+        self.space = testit.new_objspace()
+    def test_import_bare_dir_fails(self):
+        def imp():
+           import impsubdir
+        self.assertRaises(ImportError,imp)
+
+class TestImportChdiredToimpsubdir(testit.AppTestCase):
 
     def setUp(self): # interpreter-level
         self.space = testit.new_objspace()
+        dn = os.path.abspath(os.path.join(os.path.dirname(__file__), 'impsubdir'))
+        self.olddir = os.getcwd() 
+        os.chdir(dn) 
+
+    def tearDown(self): # interpreter-level
+        os.chdir(self.olddir) 
 
     def test_import_sys(self):
         import sys
 
     def test_import_a(self):
         import sys
-        sys.path.append('impsubdir')
         import a
         self.assertEquals(a, sys.modules.get('a'))
 
-    def test_import_bare_dir_fails(self):
-        def imp():
-           import impsubdir
-        self.assertRaises(ImportError,imp)
-
     def test_import_pkg(self):
         import sys
-        sys.path.append('impsubdir')
         import pkg
         self.assertEquals(pkg, sys.modules.get('pkg'))
 
     def test_import_dotted(self):
         import sys
-        sys.path.append('impsubdir')
         import pkg.a
         self.assertEquals(pkg, sys.modules.get('pkg'))
         self.assertEquals(pkg.a, sys.modules.get('pkg.a'))
 
     def test_import_dotted2(self):
         import sys
-        sys.path.append('impsubdir')
         import pkg.pkg1.a
         self.assertEquals(pkg, sys.modules.get('pkg'))
         self.assertEquals(pkg.pkg1, sys.modules.get('pkg.pkg1'))
@@ -43,21 +49,18 @@
 
     def test_import_ambig(self):
         import sys
-        sys.path.append('impsubdir')
         import ambig
         self.assertEquals(ambig, sys.modules.get('ambig'))
         self.assert_(hasattr(ambig,'imapackage'))
 
     def test_from_a(self):
         import sys
-        sys.path.append('impsubdir')
         from a import imamodule
         self.assert_('a' in sys.modules)
         self.assertEquals(imamodule, 1)
 
     def test_from_dotted(self):
         import sys
-        sys.path.append('impsubdir')
         from pkg.a import imamodule
         self.assert_('pkg' in sys.modules)
         self.assert_('pkg.a' in sys.modules)
@@ -65,7 +68,6 @@
 
     def test_from_pkg_import_module(self):
         import sys
-        sys.path.append('impsubdir')
         from pkg import a
         self.assert_('pkg' in sys.modules)
         self.assert_('pkg.a' in sys.modules)
@@ -75,8 +77,6 @@
         self.assertEquals(a, aa)
 
     def test_import_relative(self):
-        import sys
-        sys.path.append('impsubdir')
         from pkg import relative_a
         self.assertEquals(relative_a.a.inpackage,1)
         



More information about the Pypy-commit mailing list