summaryrefslogtreecommitdiff
path: root/Lib/test/test_imp.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-07-09 13:58:07 -0400
committerBrett Cannon <brett@python.org>2012-07-09 13:58:07 -0400
commit3f02e053c9f9c46af8379f142b8b8dc989a3503e (patch)
tree3f1b9c12b26e014a4bc719da635887508e06655b /Lib/test/test_imp.py
parent7d8c1f928cf12d4c09c4c898ce9963c4bf0b997c (diff)
downloadcpython-3f02e053c9f9c46af8379f142b8b8dc989a3503e.tar.gz
Issue #15056: imp.cache_from_source() and source_from_cache() raise
NotimplementedError when sys.implementation.cache_tag is None. Thanks to Pranav Ravichandran for taking an initial stab at the patch.
Diffstat (limited to 'Lib/test/test_imp.py')
-rw-r--r--Lib/test/test_imp.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 7b0c7273c2..a660278c9c 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -231,6 +231,8 @@ class PEP3147Tests(unittest.TestCase):
tag = imp.get_tag()
+ @unittest.skipUnless(sys.implementation.cache_tag is not None,
+ 'requires sys.implementation.cache_tag not be None')
def test_cache_from_source(self):
# Given the path to a .py file, return the path to its PEP 3147
# defined .pyc file (i.e. under __pycache__).
@@ -239,6 +241,12 @@ class PEP3147Tests(unittest.TestCase):
'qux.{}.pyc'.format(self.tag))
self.assertEqual(imp.cache_from_source(path, True), expect)
+ def test_cache_from_source_no_cache_tag(self):
+ # Non cache tag means NotImplementedError.
+ with support.swap_attr(sys.implementation, 'cache_tag', None):
+ with self.assertRaises(NotImplementedError):
+ imp.cache_from_source('whatever.py')
+
def test_cache_from_source_no_dot(self):
# Directory with a dot, filename without dot.
path = os.path.join('foo.bar', 'file')
@@ -283,6 +291,9 @@ class PEP3147Tests(unittest.TestCase):
imp.cache_from_source('\\foo\\bar\\baz/qux.py', True),
'\\foo\\bar\\baz\\__pycache__\\qux.{}.pyc'.format(self.tag))
+ @unittest.skipUnless(sys.implementation.cache_tag is not None,
+ 'requires sys.implementation.cache_tag to not be '
+ 'None')
def test_source_from_cache(self):
# Given the path to a PEP 3147 defined .pyc file, return the path to
# its source. This tests the good path.
@@ -291,6 +302,13 @@ class PEP3147Tests(unittest.TestCase):
expect = os.path.join('foo', 'bar', 'baz', 'qux.py')
self.assertEqual(imp.source_from_cache(path), expect)
+ def test_source_from_cache_no_cache_tag(self):
+ # If sys.implementation.cache_tag is None, raise NotImplementedError.
+ path = os.path.join('blah', '__pycache__', 'whatever.pyc')
+ with support.swap_attr(sys.implementation, 'cache_tag', None):
+ with self.assertRaises(NotImplementedError):
+ imp.source_from_cache(path)
+
def test_source_from_cache_bad_path(self):
# When the path to a pyc file is not in PEP 3147 format, a ValueError
# is raised.