Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_site.ImportSideEffectTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_abs_paths
def test_no_duplicate_paths
def test_add_build_dir
def test_setting_quit
def test_setting_copyright
def test_setting_help
def test_aliasing_mbcs
def test_sitecustomize_executed

Public Attributes

 sys_path

Detailed Description

Test side-effects from importing 'site'.

Definition at line 302 of file test_site.py.


Member Function Documentation

Make a copy of sys.path

Definition at line 305 of file test_site.py.

00305 
00306     def setUp(self):
00307         """Make a copy of sys.path"""
00308         self.sys_path = sys.path[:]

Here is the caller graph for this function:

Restore sys.path

Definition at line 309 of file test_site.py.

00309 
00310     def tearDown(self):
00311         """Restore sys.path"""
00312         sys.path[:] = self.sys_path

Here is the caller graph for this function:

Definition at line 313 of file test_site.py.

00313 
00314     def test_abs_paths(self):
00315         # Make sure all imported modules have their __file__ and __cached__
00316         # attributes as absolute paths.  Arranging to put the Lib directory on
00317         # PYTHONPATH would cause the os module to have a relative path for
00318         # __file__ if abs_paths() does not get run.  sys and builtins (the
00319         # only other modules imported before site.py runs) do not have
00320         # __file__ or __cached__ because they are built-in.
00321         parent = os.path.relpath(os.path.dirname(os.__file__))
00322         env = os.environ.copy()
00323         env['PYTHONPATH'] = parent
00324         code = ('import os, sys',
00325             # use ASCII to avoid locale issues with non-ASCII directories
00326             'os_file = os.__file__.encode("ascii", "backslashreplace")',
00327             r'sys.stdout.buffer.write(os_file + b"\n")',
00328             'os_cached = os.__cached__.encode("ascii", "backslashreplace")',
00329             r'sys.stdout.buffer.write(os_cached + b"\n")')
00330         command = '\n'.join(code)
00331         # First, prove that with -S (no 'import site'), the paths are
00332         # relative.
00333         proc = subprocess.Popen([sys.executable, '-S', '-c', command],
00334                                 env=env,
00335                                 stdout=subprocess.PIPE)
00336         stdout, stderr = proc.communicate()
00337 
00338         self.assertEqual(proc.returncode, 0)
00339         os__file__, os__cached__ = stdout.splitlines()[:2]
00340         self.assertFalse(os.path.isabs(os__file__))
00341         self.assertFalse(os.path.isabs(os__cached__))
00342         # Now, with 'import site', it works.
00343         proc = subprocess.Popen([sys.executable, '-c', command],
00344                                 env=env,
00345                                 stdout=subprocess.PIPE)
00346         stdout, stderr = proc.communicate()
00347         self.assertEqual(proc.returncode, 0)
00348         os__file__, os__cached__ = stdout.splitlines()[:2]
00349         self.assertTrue(os.path.isabs(os__file__))
00350         self.assertTrue(os.path.isabs(os__cached__))

Here is the call graph for this function:

Definition at line 360 of file test_site.py.

00360 
00361     def test_add_build_dir(self):
00362         # Test that the build directory's Modules directory is used when it
00363         # should be.
00364         # XXX: implement
00365         pass

Definition at line 380 of file test_site.py.

00380 
00381     def test_aliasing_mbcs(self):
00382         if sys.platform == "win32":
00383             import locale
00384             if locale.getdefaultlocale()[1].startswith('cp'):
00385                 for value in encodings.aliases.aliases.values():
00386                     if value == "mbcs":
00387                         break
00388                 else:
00389                     self.fail("did not alias mbcs")

Here is the call graph for this function:

Definition at line 351 of file test_site.py.

00351 
00352     def test_no_duplicate_paths(self):
00353         # No duplicate paths should exist in sys.path
00354         # Handled by removeduppaths()
00355         site.removeduppaths()
00356         seen_paths = set()
00357         for path in sys.path:
00358             self.assertNotIn(path, seen_paths)
00359             seen_paths.add(path)

Here is the call graph for this function:

Definition at line 371 of file test_site.py.

00371 
00372     def test_setting_copyright(self):
00373         # 'copyright' and 'credits' should be in builtins
00374         self.assertTrue(hasattr(builtins, "copyright"))
00375         self.assertTrue(hasattr(builtins, "credits"))

Here is the call graph for this function:

Definition at line 376 of file test_site.py.

00376 
00377     def test_setting_help(self):
00378         # 'help' should be set in builtins
00379         self.assertTrue(hasattr(builtins, "help"))

Here is the call graph for this function:

Definition at line 366 of file test_site.py.

00366 
00367     def test_setting_quit(self):
00368         # 'quit' and 'exit' should be injected into builtins
00369         self.assertTrue(hasattr(builtins, "quit"))
00370         self.assertTrue(hasattr(builtins, "exit"))

Here is the call graph for this function:

Definition at line 390 of file test_site.py.

00390 
00391     def test_sitecustomize_executed(self):
00392         # If sitecustomize is available, it should have been imported.
00393         if "sitecustomize" not in sys.modules:
00394             try:
00395                 import sitecustomize
00396             except ImportError:
00397                 pass
00398             else:
00399                 self.fail("sitecustomize not imported automatically")

Here is the call graph for this function:


Member Data Documentation

Definition at line 307 of file test_site.py.


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