#11420: merge with 3.2.

This commit is contained in:
Ezio Melotti 2013-03-16 21:49:20 +02:00
commit e5e7a7cbf4
6 changed files with 54 additions and 31 deletions

View file

@ -24,6 +24,10 @@ from test.support import (
from test import script_helper
skip_if_dont_write_bytecode = unittest.skipIf(
sys.dont_write_bytecode,
"test meaningful only when writing bytecode")
def remove_files(name):
for f in (name + ".py",
name + ".pyc",
@ -120,6 +124,7 @@ class ImportTests(unittest.TestCase):
finally:
del sys.path[0]
@skip_if_dont_write_bytecode
def test_bug7732(self):
source = TESTFN + '.py'
os.mkdir(source)
@ -230,6 +235,7 @@ class ImportTests(unittest.TestCase):
remove_files(TESTFN)
unload(TESTFN)
@skip_if_dont_write_bytecode
def test_file_to_source(self):
# check if __file__ points to the source file where available
source = TESTFN + ".py"
@ -316,6 +322,7 @@ class ImportTests(unittest.TestCase):
self.fail("fromlist must allow bogus names")
@skip_if_dont_write_bytecode
class FilePermissionTests(unittest.TestCase):
# tests for file mode on cached .pyc/.pyo files
@ -642,6 +649,7 @@ class PycacheTests(unittest.TestCase):
del sys.path[0]
self._clean()
@skip_if_dont_write_bytecode
def test_import_pyc_path(self):
self.assertFalse(os.path.exists('__pycache__'))
__import__(TESTFN)
@ -654,6 +662,7 @@ class PycacheTests(unittest.TestCase):
"test meaningful only on posix systems")
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
"due to varying filesystem permission semantics (issue #11956)")
@skip_if_dont_write_bytecode
def test_unwritable_directory(self):
# When the umask causes the new __pycache__ directory to be
# unwritable, the import still succeeds but no .pyc file is written.
@ -663,6 +672,7 @@ class PycacheTests(unittest.TestCase):
self.assertFalse(os.path.exists(os.path.join(
'__pycache__', '{}.{}.pyc'.format(TESTFN, self.tag))))
@skip_if_dont_write_bytecode
def test_missing_source(self):
# With PEP 3147 cache layout, removing the source but leaving the pyc
# file does not satisfy the import.
@ -673,6 +683,7 @@ class PycacheTests(unittest.TestCase):
forget(TESTFN)
self.assertRaises(ImportError, __import__, TESTFN)
@skip_if_dont_write_bytecode
def test_missing_source_legacy(self):
# Like test_missing_source() except that for backward compatibility,
# when the pyc file lives where the py file would have been (and named
@ -694,6 +705,7 @@ class PycacheTests(unittest.TestCase):
pyc_file = imp.cache_from_source(TESTFN + '.py')
self.assertEqual(m.__cached__, os.path.join(os.curdir, pyc_file))
@skip_if_dont_write_bytecode
def test___cached___legacy_pyc(self):
# Like test___cached__() except that for backward compatibility,
# when the pyc file lives where the py file would have been (and named
@ -709,6 +721,7 @@ class PycacheTests(unittest.TestCase):
self.assertEqual(m.__cached__,
os.path.join(os.curdir, os.path.relpath(pyc_file)))
@skip_if_dont_write_bytecode
def test_package___cached__(self):
# Like test___cached__ but for packages.
def cleanup():