[pypy-svn] r4766 - in pypy/trunk/src/pypy/module: . test
alex at codespeak.net
alex at codespeak.net
Mon May 31 17:22:37 CEST 2004
Author: alex
Date: Mon May 31 17:22:36 2004
New Revision: 4766
Modified:
pypy/trunk/src/pypy/module/__builtin__interp.py
pypy/trunk/src/pypy/module/test/test_import.py
Log:
stricter tests
Modified: pypy/trunk/src/pypy/module/__builtin__interp.py
==============================================================================
--- pypy/trunk/src/pypy/module/__builtin__interp.py (original)
+++ pypy/trunk/src/pypy/module/__builtin__interp.py Mon May 31 17:22:36 2004
@@ -32,14 +32,14 @@
return _actframe(position).getdictscope()
-def try_import_mod(w_modulename,f,pkgdir=None):
+def try_import_mod(w_modulename, f, pkgdir=None):
w = space.wrap
if os.path.exists(f):
w_mod = space.wrap(Module(space, w_modulename))
space.sys.setmodule(w_mod)
space.setattr(w_mod, w('__file__'), w(f))
if pkgdir is not None:
- space.setattr(w_mod,w('__path__'),space.newlist([w(pkgdir)]))
+ space.setattr(w_mod, w('__path__'), space.newlist([w(pkgdir)]))
w_dict = space.getattr(w_mod, w('__dict__'))
execfile(w(f), w_dict, w_dict)
return w_mod
@@ -49,7 +49,7 @@
def check_sys_modules(w_modulename):
try:
w_mod = space.getitem(space.sys.w_modules, w_modulename)
- except OperationError,e:
+ except OperationError, e:
pass
else:
return w_mod
@@ -85,7 +85,7 @@
first = None
for part in parts:
- w_mod = load_part(w_path,prefix,part)
+ w_mod = load_part(w_path, prefix, part)
if w_mod is None:
# ImportError
w_failing = w('.'.join(prefix+[part]))
@@ -95,24 +95,26 @@
first = w_mod
prefix.append(part)
try:
- w_path = space.getattr(w_mod,w('__path__'))
- except OperationError,e:
+ w_path = space.getattr(w_mod, w('__path__'))
+ except OperationError, e:
if not e.match(space, space.w_AttributeError):
raise
w_path = None
if w_fromlist is not None and space.is_true(w_fromlist):
+ if w_path is not None:
+ for w_name in space.unpackiterable(w_fromlist):
+ load_part(w_path, prefix, space.unwrap(w_name))
return w_mod
else:
return first
-def load_part(w_path,prefix,partname):
+def load_part(w_path, prefix, partname):
w = space.wrap
w_modulename = w('.'.join(prefix+[partname]))
w_mod = check_sys_modules(w_modulename)
if w_mod is not None:
return w_mod
-
for path in space.unpackiterable(w_path):
dir = os.path.join(space.unwrap(path), partname)
if os.path.isdir(dir):
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 17:22:36 2004
@@ -13,7 +13,7 @@
import sys
sys.path.append('impsubdir')
import a
- self.assert_('a' in sys.modules)
+ self.assertEquals(a, sys.modules.get('a'))
def test_import_bare_dir_fails(self):
def imp():
@@ -24,28 +24,28 @@
import sys
sys.path.append('impsubdir')
import pkg
- self.assert_('pkg' in sys.modules)
+ self.assertEquals(pkg, sys.modules.get('pkg'))
def test_import_dotted(self):
import sys
sys.path.append('impsubdir')
import pkg.a
- self.assert_('pkg' in sys.modules)
- self.assert_('pkg.a' in sys.modules)
+ 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.assert_('pkg' in sys.modules)
- self.assert_('pkg.pkg1' in sys.modules)
- self.assert_('pkg.pkg1.a' in sys.modules)
+ self.assertEquals(pkg, sys.modules.get('pkg'))
+ self.assertEquals(pkg.pkg1, sys.modules.get('pkg.pkg1'))
+ self.assertEquals(pkg.pkg1.a, sys.modules.get('pkg.pkg1.a'))
def test_import_ambig(self):
import sys
sys.path.append('impsubdir')
import ambig
- self.assert_('ambig' in sys.modules)
+ self.assertEquals(ambig, sys.modules.get('ambig'))
self.assert_(hasattr(ambig,'imapackage'))
def test_from_a(self):
@@ -69,7 +69,10 @@
from pkg import a
self.assert_('pkg' in sys.modules)
self.assert_('pkg.a' in sys.modules)
- self.assert_(hasattr(a, 'imamodule'))
+ pkg = sys.modules.get('pkg')
+ self.assertEquals(a, pkg.a)
+ aa = sys.modules.get('pkg.a')
+ self.assertEquals(a, aa)
if __name__ == '__main__':
testit.main()
More information about the Pypy-commit
mailing list