diff options
author | Brett Cannon <brett@python.org> | 2013-01-11 20:42:30 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-01-11 20:42:30 (GMT) |
commit | c57f9f9419154ffa6b653da58a7eb3f35da478c7 (patch) | |
tree | ae79b45e2bcc73b81eee8c201d4c38c24df190dc /Lib/test | |
parent | b463c482bf6506095f5f11c4f650b7ae356f4452 (diff) | |
parent | a9976b3e32b612e33dc9f6d8874a88d028de7424 (diff) | |
download | cpython-c57f9f9419154ffa6b653da58a7eb3f35da478c7.zip cpython-c57f9f9419154ffa6b653da58a7eb3f35da478c7.tar.gz cpython-c57f9f9419154ffa6b653da58a7eb3f35da478c7.tar.bz2 |
Merge from 3.3 for fix for issue #16730
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_importlib/source/test_finder.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py index 8bc16a5..8e49868 100644 --- a/Lib/test/test_importlib/source/test_finder.py +++ b/Lib/test/test_importlib/source/test_finder.py @@ -6,6 +6,9 @@ import errno import imp import os import py_compile +import stat +import sys +import tempfile from test.support import make_legacy_pyc import unittest import warnings @@ -147,6 +150,38 @@ class FinderTests(abc.FinderTests): self.assertIsNotNone(finder.find_module(mod)) self.assertIsNone(finder.find_module(mod)) + @unittest.skipUnless(sys.platform != 'win32', + 'os.chmod() does not support the needed arguments under Windows') + def test_no_read_directory(self): + # Issue #16730 + tempdir = tempfile.TemporaryDirectory() + original_mode = os.stat(tempdir.name).st_mode + def cleanup(tempdir): + """Cleanup function for the temporary directory. + + Since we muck with the permissions, we want to set them back to + their original values to make sure the directory can be properly + cleaned up. + + """ + os.chmod(tempdir.name, original_mode) + # If this is not explicitly called then the __del__ method is used, + # but since already mucking around might as well explicitly clean + # up. + tempdir.__exit__(None, None, None) + self.addCleanup(cleanup, tempdir) + os.chmod(tempdir.name, stat.S_IWUSR | stat.S_IXUSR) + finder = self.get_finder(tempdir.name) + self.assertEqual((None, []), finder.find_loader('doesnotexist')) + + def test_ignore_file(self): + # If a directory got changed to a file from underneath us, then don't + # worry about looking for submodules. + with tempfile.NamedTemporaryFile() as file_obj: + finder = self.get_finder(file_obj.name) + self.assertEqual((None, []), finder.find_loader('doesnotexist')) + + def test_main(): from test.support import run_unittest run_unittest(FinderTests) |