Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_imp.PEP3147Tests Class Reference

List of all members.

Public Member Functions

def test_cache_from_source
def test_cache_from_source_optimized
def test_cache_from_source_cwd
def test_cache_from_source_override
def test_altsep_cache_from_source
def test_altsep_and_sep_cache_from_source
def test_sep_altsep_and_sep_cache_from_source
def test_source_from_cache
def test_source_from_cache_bad_path
def test_source_from_cache_no_slash
def test_source_from_cache_too_few_dots
def test_source_from_cache_too_many_dots
def test_source_from_cache_no__pycache__
def test_package___file__

Static Public Attributes

tuple tag = imp.get_tag()

Detailed Description

Tests of PEP 3147.

Definition at line 207 of file test_imp.py.


Member Function Documentation

Definition at line 258 of file test_imp.py.

00258 
00259     def test_altsep_and_sep_cache_from_source(self):
00260         # Windows path and PEP 3147 where altsep is right of sep.
00261         self.assertEqual(
00262             imp.cache_from_source('\\foo\\bar/baz\\qux.py', True),
00263             '\\foo\\bar/baz\\__pycache__\\qux.{}.pyc'.format(self.tag))

Here is the call graph for this function:

Definition at line 250 of file test_imp.py.

00250 
00251     def test_altsep_cache_from_source(self):
00252         # Windows path and PEP 3147.
00253         self.assertEqual(
00254             imp.cache_from_source('\\foo\\bar\\baz\\qux.py', True),
00255             '\\foo\\bar\\baz\\__pycache__\\qux.{}.pyc'.format(self.tag))

Here is the call graph for this function:

Definition at line 212 of file test_imp.py.

00212 
00213     def test_cache_from_source(self):
00214         # Given the path to a .py file, return the path to its PEP 3147
00215         # defined .pyc file (i.e. under __pycache__).
00216         self.assertEqual(
00217             imp.cache_from_source('/foo/bar/baz/qux.py', True),
00218             '/foo/bar/baz/__pycache__/qux.{}.pyc'.format(self.tag))

Here is the call graph for this function:

Definition at line 226 of file test_imp.py.

00226 
00227     def test_cache_from_source_cwd(self):
00228         self.assertEqual(imp.cache_from_source('foo.py', True),
00229                          os.sep.join(('__pycache__',
00230                                       'foo.{}.pyc'.format(self.tag))))

Here is the call graph for this function:

Definition at line 219 of file test_imp.py.

00219 
00220     def test_cache_from_source_optimized(self):
00221         # Given the path to a .py file, return the path to its PEP 3147
00222         # defined .pyo file (i.e. under __pycache__).
00223         self.assertEqual(
00224             imp.cache_from_source('/foo/bar/baz/qux.py', False),
00225             '/foo/bar/baz/__pycache__/qux.{}.pyo'.format(self.tag))

Here is the call graph for this function:

Definition at line 231 of file test_imp.py.

00231 
00232     def test_cache_from_source_override(self):
00233         # When debug_override is not None, it can be any true-ish or false-ish
00234         # value.
00235         self.assertEqual(
00236             imp.cache_from_source('/foo/bar/baz.py', []),
00237             '/foo/bar/__pycache__/baz.{}.pyo'.format(self.tag))
00238         self.assertEqual(
00239             imp.cache_from_source('/foo/bar/baz.py', [17]),
00240             '/foo/bar/__pycache__/baz.{}.pyc'.format(self.tag))
00241         # However if the bool-ishness can't be determined, the exception
00242         # propagates.
00243         class Bearish:
00244             def __bool__(self): raise RuntimeError
00245         self.assertRaises(
00246             RuntimeError,
00247             imp.cache_from_source, '/foo/bar/baz.py', Bearish())

Here is the call graph for this function:

Definition at line 307 of file test_imp.py.

00307 
00308     def test_package___file__(self):
00309         # Test that a package's __file__ points to the right source directory.
00310         os.mkdir('pep3147')
00311         sys.path.insert(0, os.curdir)
00312         def cleanup():
00313             if sys.path[0] == os.curdir:
00314                 del sys.path[0]
00315             shutil.rmtree('pep3147')
00316         self.addCleanup(cleanup)
00317         # Touch the __init__.py file.
00318         with open('pep3147/__init__.py', 'w'):
00319             pass
00320         m = __import__('pep3147')
00321         # Ensure we load the pyc file.
00322         support.forget('pep3147')
00323         m = __import__('pep3147')
00324         self.assertEqual(m.__file__,
00325                          os.sep.join(('.', 'pep3147', '__init__.py')))
00326 

Here is the call graph for this function:

Definition at line 266 of file test_imp.py.

00266 
00267     def test_sep_altsep_and_sep_cache_from_source(self):
00268         # Windows path and PEP 3147 where sep is right of altsep.
00269         self.assertEqual(
00270             imp.cache_from_source('\\foo\\bar\\baz/qux.py', True),
00271             '\\foo\\bar\\baz/__pycache__/qux.{}.pyc'.format(self.tag))

Here is the call graph for this function:

Definition at line 272 of file test_imp.py.

00272 
00273     def test_source_from_cache(self):
00274         # Given the path to a PEP 3147 defined .pyc file, return the path to
00275         # its source.  This tests the good path.
00276         self.assertEqual(imp.source_from_cache(
00277             '/foo/bar/baz/__pycache__/qux.{}.pyc'.format(self.tag)),
00278             '/foo/bar/baz/qux.py')

Here is the call graph for this function:

Definition at line 279 of file test_imp.py.

00279 
00280     def test_source_from_cache_bad_path(self):
00281         # When the path to a pyc file is not in PEP 3147 format, a ValueError
00282         # is raised.
00283         self.assertRaises(
00284             ValueError, imp.source_from_cache, '/foo/bar/bazqux.pyc')

Here is the call graph for this function:

Definition at line 301 of file test_imp.py.

00301 
00302     def test_source_from_cache_no__pycache__(self):
00303         # Another problem with the path -> ValueError
00304         self.assertRaises(
00305             ValueError, imp.source_from_cache,
00306             '/foo/bar/foo.cpython-32.foo.pyc')

Here is the call graph for this function:

Definition at line 285 of file test_imp.py.

00285 
00286     def test_source_from_cache_no_slash(self):
00287         # No slashes at all in path -> ValueError
00288         self.assertRaises(
00289             ValueError, imp.source_from_cache, 'foo.cpython-32.pyc')

Here is the call graph for this function:

Definition at line 290 of file test_imp.py.

00290 
00291     def test_source_from_cache_too_few_dots(self):
00292         # Too few dots in final path component -> ValueError
00293         self.assertRaises(
00294             ValueError, imp.source_from_cache, '__pycache__/foo.pyc')

Here is the call graph for this function:

Definition at line 295 of file test_imp.py.

00295 
00296     def test_source_from_cache_too_many_dots(self):
00297         # Too many dots in final path component -> ValueError
00298         self.assertRaises(
00299             ValueError, imp.source_from_cache,
00300             '__pycache__/foo.cpython-32.foo.pyc')

Here is the call graph for this function:


Member Data Documentation

tuple test.test_imp.PEP3147Tests.tag = imp.get_tag() [static]

Definition at line 210 of file test_imp.py.


The documentation for this class was generated from the following file: