fix pyimport() bug on directories

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-05-31 17:06:46 +02:00
parent 395bee4bc0
commit 75d80ca183
3 changed files with 9 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Bug fixes
++++++++++++++++++ ++++++++++++++++++
- fix issue57 -f|--looponfail to work with xpassing tests - fix issue57 -f|--looponfail to work with xpassing tests
- fix pyimport() to work with directories
Changes between 1.3.0 and 1.3.1 Changes between 1.3.0 and 1.3.1
================================================== ==================================================

View File

@ -524,6 +524,8 @@ class LocalPath(FSBase):
modfile = modfile[:-1] modfile = modfile[:-1]
elif modfile.endswith('$py.class'): elif modfile.endswith('$py.class'):
modfile = modfile[:-9] + '.py' modfile = modfile[:-9] + '.py'
if modfile.endswith("__init__.py"):
modfile = modfile[:-12]
if not self.samefile(modfile): if not self.samefile(modfile):
raise EnvironmentError("mismatch:\n" raise EnvironmentError("mismatch:\n"
"imported module %r\n" "imported module %r\n"

View File

@ -292,6 +292,12 @@ class TestImport:
assert obj.x == 42 assert obj.x == 42
assert obj.__name__ == 'execfile' assert obj.__name__ == 'execfile'
def test_pyimport_dir(self, tmpdir):
p = tmpdir.join("hello_123")
p.ensure("__init__.py")
m = p.pyimport()
assert m.__name__ == "hello_123"
def test_pyimport_execfile_different_name(self, path1): def test_pyimport_execfile_different_name(self, path1):
obj = path1.join('execfile.py').pyimport(modname="0x.y.z") obj = path1.join('execfile.py').pyimport(modname="0x.y.z")
assert obj.x == 42 assert obj.x == 42