summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-07-20 18:22:04 (GMT)
committerBrett Cannon <brett@python.org>2012-07-20 18:22:04 (GMT)
commit6ee96952703ebfde9bdfa5852fa4ddfe8363442e (patch)
tree62ce858fa0b1a7e377f889d7a2478301b71fd8ed /Lib/test
parentba52586f764693e8d200cd2e8d3faf978777c4d2 (diff)
downloadcpython-6ee96952703ebfde9bdfa5852fa4ddfe8363442e.zip
cpython-6ee96952703ebfde9bdfa5852fa4ddfe8363442e.tar.gz
cpython-6ee96952703ebfde9bdfa5852fa4ddfe8363442e.tar.bz2
Issue #15091: Call importlib.invalidate_caches() and reactivate a test
of importing a symlinked package.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_import.py42
1 files changed, 15 insertions, 27 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 1accd7e..e833b16 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -704,36 +704,34 @@ class PycacheTests(unittest.TestCase):
class TestSymbolicallyLinkedPackage(unittest.TestCase):
package_name = 'sample'
+ tagged = package_name + '-tagged'
def setUp(self):
- if os.path.exists(self.tagged):
- shutil.rmtree(self.tagged)
- if os.path.exists(self.package_name):
- os.remove(self.package_name)
+ test.support.rmtree(self.tagged)
+ test.support.rmtree(self.package_name)
self.orig_sys_path = sys.path[:]
# create a sample package; imagine you have a package with a tag and
# you want to symbolically link it from its untagged name.
os.mkdir(self.tagged)
+ self.addCleanup(test.support.rmtree, self.tagged)
init_file = os.path.join(self.tagged, '__init__.py')
- open(init_file, 'w').close()
- self.assertEqual(os.path.exists(init_file), True)
+ test.support.create_empty_file(init_file)
+ assert os.path.exists(init_file)
# now create a symlink to the tagged package
# sample -> sample-tagged
os.symlink(self.tagged, self.package_name)
+ self.addCleanup(test.support.unlink, self.package_name)
+ importlib.invalidate_caches()
# disabled because os.isdir currently fails (see issue 15093)
# self.assertEqual(os.path.isdir(self.package_name), True)
- self.assertEqual(
- os.path.isfile(os.path.join(self.package_name, '__init__.py')),
- True,
- )
+ assert os.path.isfile(os.path.join(self.package_name, '__init__.py'))
- @property
- def tagged(self):
- return self.package_name + '-tagged'
+ def tearDown(self):
+ sys.path[:] = self.orig_sys_path
# regression test for issue6727
@unittest.skipUnless(
@@ -741,24 +739,14 @@ class TestSymbolicallyLinkedPackage(unittest.TestCase):
or sys.getwindowsversion() >= (6, 0),
"Windows Vista or later required")
@test.support.skip_unless_symlink
- @unittest.skipUnless(
- sys.platform == 'win32',
- "Test failing on Unix (see issue15091)"
- )
def test_symlinked_dir_importable(self):
# make sure sample can only be imported from the current directory.
sys.path[:] = ['.']
+ assert os.path.exists(self.package_name)
+ assert os.path.exists(os.path.join(self.package_name, '__init__.py'))
- # and try to import the package
- __import__(self.package_name)
-
- def tearDown(self):
- # now cleanup
- if os.path.exists(self.package_name):
- os.remove(self.package_name)
- if os.path.exists(self.tagged):
- shutil.rmtree(self.tagged)
- sys.path[:] = self.orig_sys_path
+ # Try to import the package
+ importlib.import_module(self.package_name)
@cpython_only