From 75d80ca18331ecf9f8035a4a3d59a81eb1b5e74a Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 31 May 2010 17:06:46 +0200 Subject: [PATCH] fix pyimport() bug on directories --HG-- branch : trunk --- CHANGELOG | 1 + py/_path/local.py | 2 ++ testing/path/test_local.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 071757a7d..a661df6c3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ Bug fixes ++++++++++++++++++ - fix issue57 -f|--looponfail to work with xpassing tests +- fix pyimport() to work with directories Changes between 1.3.0 and 1.3.1 ================================================== diff --git a/py/_path/local.py b/py/_path/local.py index 6616601e1..5b8ba7310 100644 --- a/py/_path/local.py +++ b/py/_path/local.py @@ -524,6 +524,8 @@ class LocalPath(FSBase): modfile = modfile[:-1] elif modfile.endswith('$py.class'): modfile = modfile[:-9] + '.py' + if modfile.endswith("__init__.py"): + modfile = modfile[:-12] if not self.samefile(modfile): raise EnvironmentError("mismatch:\n" "imported module %r\n" diff --git a/testing/path/test_local.py b/testing/path/test_local.py index 5a58b3548..f60eb1436 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -292,6 +292,12 @@ class TestImport: assert obj.x == 42 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): obj = path1.join('execfile.py').pyimport(modname="0x.y.z") assert obj.x == 42