summaryrefslogtreecommitdiff
path: root/functional_tests
diff options
context:
space:
mode:
Diffstat (limited to 'functional_tests')
-rw-r--r--functional_tests/support/dir3/.hidden0
-rw-r--r--functional_tests/test_importer.py70
2 files changed, 61 insertions, 9 deletions
diff --git a/functional_tests/support/dir3/.hidden b/functional_tests/support/dir3/.hidden
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/functional_tests/support/dir3/.hidden
diff --git a/functional_tests/test_importer.py b/functional_tests/test_importer.py
index c24fdcf..20fb15d 100644
--- a/functional_tests/test_importer.py
+++ b/functional_tests/test_importer.py
@@ -2,6 +2,7 @@ import os
import sys
import unittest
from nose.importer import Importer
+from nose.plugins.skip import SkipTest
class TestImporter(unittest.TestCase):
@@ -16,7 +17,15 @@ class TestImporter(unittest.TestCase):
sys.modules.pop('pak', None)
sys.modules.pop('pak.mod', None)
sys.modules.pop('pak.sub', None)
-
+ try:
+ os.symlink(
+ os.path.abspath(os.path.join(self.dir, 'dir1', 'pak')),
+ os.path.join(self.dir, 'dir3', 'pak'))
+ except (AttributeError, NotImplementedError):
+ self.has_symlinks = False
+ else:
+ self.has_symlinks = True
+
def tearDown(self):
to_del = [ m for m in sys.modules.keys() if
m not in self._mods ]
@@ -25,14 +34,16 @@ class TestImporter(unittest.TestCase):
del sys.modules[mod]
sys.modules.update(self._mods)
sys.path = self._path[:]
+ if self.has_symlinks:
+ os.unlink(os.path.join(self.dir, 'dir3', 'pak'))
def test_import_from_dir(self):
imp = self.imp
d1 = os.path.join(self.dir, 'dir1')
d2 = os.path.join(self.dir, 'dir2')
-
- # simple name
+
+ # simple name
m1 = imp.importFromDir(d1, 'mod')
m2 = imp.importFromDir(d2, 'mod')
self.assertNotEqual(m1, m2)
@@ -44,14 +55,34 @@ class TestImporter(unittest.TestCase):
self.assertNotEqual(p1, p2)
self.assertNotEqual(p1.__file__, p2.__file__)
+ def test_import_from_dirlink(self):
+ if not self.has_symlinks:
+ raise SkipTest("symlinks not available")
+ imp = self.imp
+
+ d1 = os.path.join(self.dir, 'dir3')
+ d2 = os.path.join(self.dir, 'dir2')
+
+ # simple name
+ m1 = imp.importFromDir(d1, 'pak')
+ m2 = imp.importFromDir(d2, 'pak')
+ self.assertNotEqual(m1, m2)
+ self.assertNotEqual(m1.__file__, m2.__file__)
+
+ # dotted name
+ p1 = imp.importFromDir(d1, 'pak.mod')
+ p2 = imp.importFromDir(d2, 'pak.mod')
+ self.assertNotEqual(p1, p2)
+ self.assertNotEqual(p1.__file__, p2.__file__)
+
def test_import_from_path(self):
imp = self.imp
jn = os.path.join
d1 = jn(self.dir, 'dir1')
d2 = jn(self.dir, 'dir2')
-
- # simple name
+
+ # simple name
m1 = imp.importFromPath(jn(d1, 'mod.py'), 'mod')
m2 = imp.importFromPath(jn(d2, 'mod.py'), 'mod')
self.assertNotEqual(m1, m2)
@@ -88,12 +119,12 @@ class TestImporter(unittest.TestCase):
assert 'test_pak' in sys.modules, 'test_pak was not imported?'
test_pak = sys.modules['test_pak']
assert hasattr(test_pak, 'test_sub'), "test_pak.test_sub was not set"
-
+
def test_cached_no_reload(self):
imp = self.imp
d1 = os.path.join(self.dir, 'dir1')
m1 = imp.importFromDir(d1, 'mod')
- m2 = imp.importFromDir(d1, 'mod')
+ m2 = imp.importFromDir(d1, 'mod')
assert m1 is m2, "%s is not %s" % (m1, m2)
def test_cached_no_reload_dotted(self):
@@ -133,13 +164,34 @@ class TestImporter(unittest.TestCase):
assert mod_nose_imported2 != mod_sys_imported, \
"nose failed to reimport same name, different dir"
+ def test_sys_modules_symlinked_package_no_reload(self):
+ if not self.has_symlinks:
+ raise SkipTest("symlinks not available")
+ imp = self.imp
+
+ d1 = os.path.join(self.dir, 'dir1')
+ d2 = os.path.join(self.dir, 'dir3')
+ sys.path.insert(0, d1)
+ # Symlinked package
+ mod_sys_imported = __import__('pak')
+ mod_nose_imported = imp.importFromDir(d2, 'pak')
+ assert mod_nose_imported is mod_sys_imported, \
+ "nose reimported a module in sys.modules from the same file"
+
+ # Module inside symlinked package
+ mod_sys_imported = __import__('pak.mod', fromlist=['mod'])
+ mod_nose_imported = imp.importFromDir(d2, 'pak.mod')
+ assert mod_nose_imported is mod_sys_imported, \
+ ("nose reimported a module in sys.modules from the same file",
+ mod_sys_imported.__file__, mod_nose_imported.__file__)
+
def test_import_pkg_from_path_fpw(self):
imp = self.imp
imp.config.firstPackageWins = True
jn = os.path.join
d1 = jn(self.dir, 'dir1')
d2 = jn(self.dir, 'dir2')
-
+
# dotted name
p1 = imp.importFromPath(jn(d1, 'pak', 'mod.py'), 'pak.mod')
p2 = imp.importFromPath(jn(d2, 'pak', 'mod.py'), 'pak.mod')
@@ -161,7 +213,7 @@ class TestImporter(unittest.TestCase):
assert dp1.__path__
assert dp2.__path__
self.assertEqual(dp1.__path__, dp2.__path__)
-
+
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.DEBUG)