blob: 8168d7ed92952a1d9405824665e1519f63a0d85d [file] [log] [blame]
Brett Cannon0096e262004-06-05 01:12:51 +00001"""Tests for 'site'.
2
3Tests assume the initial paths in sys.path once the interpreter has begun
4executing have not been removed.
5
6"""
7import unittest
Walter Dörwaldb525e182009-04-26 21:39:21 +00008from test.support import run_unittest, TESTFN, EnvironmentVarGuard
R. David Murrayb4ca59b2010-12-26 19:54:29 +00009from test.support import captured_stderr
Georg Brandl1a3284e2007-12-02 09:40:06 +000010import builtins
Brett Cannon0096e262004-06-05 01:12:51 +000011import os
12import sys
R. David Murrayab9d8d62010-12-27 00:03:13 +000013import re
Brett Cannon0096e262004-06-05 01:12:51 +000014import encodings
Christian Heimes8dc226f2008-05-06 23:45:46 +000015import subprocess
Tarek Ziadéedacea32010-01-29 11:41:03 +000016import sysconfig
17from copy import copy
18
Brett Cannon0096e262004-06-05 01:12:51 +000019# Need to make sure to not import 'site' if someone specified ``-S`` at the
20# command-line. Detect this by just making sure 'site' has not been imported
21# already.
22if "site" in sys.modules:
23 import site
24else:
Benjamin Petersone549ead2009-03-28 21:42:05 +000025 raise unittest.SkipTest("importation of site.py suppressed")
Brett Cannon0096e262004-06-05 01:12:51 +000026
Christian Heimes8dc226f2008-05-06 23:45:46 +000027if not os.path.isdir(site.USER_SITE):
28 # need to add user site directory for tests
29 os.makedirs(site.USER_SITE)
30 site.addsitedir(site.USER_SITE)
31
Brett Cannon0096e262004-06-05 01:12:51 +000032class HelperFunctionsTests(unittest.TestCase):
33 """Tests for helper functions.
Brett Cannon0096e262004-06-05 01:12:51 +000034 """
35
36 def setUp(self):
37 """Save a copy of sys.path"""
38 self.sys_path = sys.path[:]
Tarek Ziadé4a608c02009-08-20 21:28:05 +000039 self.old_base = site.USER_BASE
40 self.old_site = site.USER_SITE
41 self.old_prefixes = site.PREFIXES
Tarek Ziadéedacea32010-01-29 11:41:03 +000042 self.old_vars = copy(sysconfig._CONFIG_VARS)
Brett Cannon0096e262004-06-05 01:12:51 +000043
Alexandre Vassalottie9f305f2008-05-16 04:39:54 +000044 def tearDown(self):
Brett Cannon0096e262004-06-05 01:12:51 +000045 """Restore sys.path"""
Nick Coghlan6ead5522009-10-18 13:19:33 +000046 sys.path[:] = self.sys_path
Tarek Ziadé4a608c02009-08-20 21:28:05 +000047 site.USER_BASE = self.old_base
48 site.USER_SITE = self.old_site
49 site.PREFIXES = self.old_prefixes
Tarek Ziadéedacea32010-01-29 11:41:03 +000050 sysconfig._CONFIG_VARS = self.old_vars
Raymond Hettingerebd95222004-06-27 03:02:18 +000051
Brett Cannon0096e262004-06-05 01:12:51 +000052 def test_makepath(self):
53 # Test makepath() have an absolute path for its first return value
54 # and a case-normalized version of the absolute path for its
55 # second value.
56 path_parts = ("Beginning", "End")
57 original_dir = os.path.join(*path_parts)
58 abs_dir, norm_dir = site.makepath(*path_parts)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000059 self.assertEqual(os.path.abspath(original_dir), abs_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000060 if original_dir == os.path.normcase(original_dir):
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000061 self.assertEqual(abs_dir, norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000062 else:
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000063 self.assertEqual(os.path.normcase(abs_dir), norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000064
65 def test_init_pathinfo(self):
66 dir_set = site._init_pathinfo()
67 for entry in [site.makepath(path)[1] for path in sys.path
68 if path and os.path.isdir(path)]:
Ezio Melottib58e0bd2010-01-23 15:40:09 +000069 self.assertIn(entry, dir_set,
70 "%s from sys.path not found in set returned "
71 "by _init_pathinfo(): %s" % (entry, dir_set))
Raymond Hettingerebd95222004-06-27 03:02:18 +000072
Brett Cannonee86a662004-07-13 07:12:25 +000073 def pth_file_tests(self, pth_file):
74 """Contain common code for testing results of reading a .pth file"""
Ezio Melottib58e0bd2010-01-23 15:40:09 +000075 self.assertIn(pth_file.imported, sys.modules,
76 "%s not in sys.modules" % pth_file.imported)
Antoine Pitrou9166e6a2009-11-01 23:55:40 +000077 self.assertIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
78 self.assertFalse(os.path.exists(pth_file.bad_dir_path))
Brett Cannonee86a662004-07-13 07:12:25 +000079
Brett Cannon0096e262004-06-05 01:12:51 +000080 def test_addpackage(self):
81 # Make sure addpackage() imports if the line starts with 'import',
Brett Cannon64a84702004-07-10 02:10:45 +000082 # adds directories to sys.path for any line in the file that is not a
83 # comment or import that is a valid directory name for where the .pth
84 # file resides; invalid directories are not added
85 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +000086 pth_file.cleanup(prep=True) # to make sure that nothing is
87 # pre-existing that shouldn't be
Brett Cannon0096e262004-06-05 01:12:51 +000088 try:
Brett Cannon64a84702004-07-10 02:10:45 +000089 pth_file.create()
90 site.addpackage(pth_file.base_dir, pth_file.filename, set())
Brett Cannonee86a662004-07-13 07:12:25 +000091 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +000092 finally:
Brett Cannon64a84702004-07-10 02:10:45 +000093 pth_file.cleanup()
Raymond Hettingerebd95222004-06-27 03:02:18 +000094
R. David Murrayb4ca59b2010-12-26 19:54:29 +000095 def make_pth(self, contents, pth_dir='.', pth_name=TESTFN):
96 # Create a .pth file and return its (abspath, basename).
97 pth_dir = os.path.abspath(pth_dir)
98 pth_basename = pth_name + '.pth'
99 pth_fn = os.path.join(pth_dir, pth_basename)
100 pth_file = open(pth_fn, 'w', encoding='utf-8')
101 self.addCleanup(lambda: os.remove(pth_fn))
102 pth_file.write(contents)
103 pth_file.close()
104 return pth_dir, pth_basename
105
106 def test_addpackage_import_bad_syntax(self):
107 # Issue 10642
108 pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
109 with captured_stderr() as err_out:
110 site.addpackage(pth_dir, pth_fn, set())
111 self.assertRegex(err_out.getvalue(), "line 1")
R. David Murrayab9d8d62010-12-27 00:03:13 +0000112 self.assertRegex(err_out.getvalue(),
113 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murrayb4ca59b2010-12-26 19:54:29 +0000114 # XXX: the previous two should be independent checks so that the
115 # order doesn't matter. The next three could be a single check
116 # but my regex foo isn't good enough to write it.
117 self.assertRegex(err_out.getvalue(), 'Traceback')
118 self.assertRegex(err_out.getvalue(), r'import bad\)syntax')
119 self.assertRegex(err_out.getvalue(), 'SyntaxError')
120
121 def test_addpackage_import_bad_exec(self):
122 # Issue 10642
123 pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
124 with captured_stderr() as err_out:
125 site.addpackage(pth_dir, pth_fn, set())
126 self.assertRegex(err_out.getvalue(), "line 2")
R. David Murrayab9d8d62010-12-27 00:03:13 +0000127 self.assertRegex(err_out.getvalue(),
128 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murrayb4ca59b2010-12-26 19:54:29 +0000129 # XXX: ditto previous XXX comment.
130 self.assertRegex(err_out.getvalue(), 'Traceback')
131 self.assertRegex(err_out.getvalue(), 'ImportError')
132
R. David Murrayad4ccfd2010-12-27 04:31:48 +0000133 @unittest.skipIf(sys.platform == "win32", "Windows does not raise an "
134 "error for file paths containing null characters")
R. David Murrayb4ca59b2010-12-26 19:54:29 +0000135 def test_addpackage_import_bad_pth_file(self):
136 # Issue 5258
137 pth_dir, pth_fn = self.make_pth("abc\x00def\n")
138 with captured_stderr() as err_out:
139 site.addpackage(pth_dir, pth_fn, set())
140 self.assertRegex(err_out.getvalue(), "line 1")
R. David Murrayab9d8d62010-12-27 00:03:13 +0000141 self.assertRegex(err_out.getvalue(),
142 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murrayb4ca59b2010-12-26 19:54:29 +0000143 # XXX: ditto previous XXX comment.
144 self.assertRegex(err_out.getvalue(), 'Traceback')
145 self.assertRegex(err_out.getvalue(), 'TypeError')
146
Brett Cannon0096e262004-06-05 01:12:51 +0000147 def test_addsitedir(self):
Brett Cannon64a84702004-07-10 02:10:45 +0000148 # Same tests for test_addpackage since addsitedir() essentially just
149 # calls addpackage() for every .pth file in the directory
150 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000151 pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
152 # that is tested for
Brett Cannon0096e262004-06-05 01:12:51 +0000153 try:
Brett Cannonee86a662004-07-13 07:12:25 +0000154 pth_file.create()
Brett Cannon64a84702004-07-10 02:10:45 +0000155 site.addsitedir(pth_file.base_dir, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000156 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000157 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000158 pth_file.cleanup()
Brett Cannon0096e262004-06-05 01:12:51 +0000159
Christian Heimes8dc226f2008-05-06 23:45:46 +0000160 def test_s_option(self):
161 usersite = site.USER_SITE
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000162 self.assertIn(usersite, sys.path)
Christian Heimes8dc226f2008-05-06 23:45:46 +0000163
Éric Araujo63ebe1c2011-01-03 17:51:11 +0000164 env = os.environ.copy()
Christian Heimes8dc226f2008-05-06 23:45:46 +0000165 rc = subprocess.call([sys.executable, '-c',
Éric Araujo63ebe1c2011-01-03 17:51:11 +0000166 'import sys; sys.exit(%r in sys.path)' % usersite],
167 env=env)
Christian Heimes8dc226f2008-05-06 23:45:46 +0000168 self.assertEqual(rc, 1)
169
Éric Araujo63ebe1c2011-01-03 17:51:11 +0000170 env = os.environ.copy()
Christian Heimes8dc226f2008-05-06 23:45:46 +0000171 rc = subprocess.call([sys.executable, '-s', '-c',
Éric Araujo63ebe1c2011-01-03 17:51:11 +0000172 'import sys; sys.exit(%r in sys.path)' % usersite],
173 env=env)
Christian Heimes8dc226f2008-05-06 23:45:46 +0000174 self.assertEqual(rc, 0)
175
176 env = os.environ.copy()
177 env["PYTHONNOUSERSITE"] = "1"
178 rc = subprocess.call([sys.executable, '-c',
Benjamin Petersonfea6a942008-07-02 16:11:42 +0000179 'import sys; sys.exit(%r in sys.path)' % usersite],
Christian Heimes8dc226f2008-05-06 23:45:46 +0000180 env=env)
181 self.assertEqual(rc, 0)
182
183 env = os.environ.copy()
184 env["PYTHONUSERBASE"] = "/tmp"
185 rc = subprocess.call([sys.executable, '-c',
186 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
187 env=env)
188 self.assertEqual(rc, 1)
189
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000190 def test_getuserbase(self):
191 site.USER_BASE = None
192 user_base = site.getuserbase()
193
194 # the call sets site.USER_BASE
Ezio Melottib3aedd42010-11-20 19:04:17 +0000195 self.assertEqual(site.USER_BASE, user_base)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000196
197 # let's set PYTHONUSERBASE and see if it uses it
198 site.USER_BASE = None
Tarek Ziadéedacea32010-01-29 11:41:03 +0000199 import sysconfig
200 sysconfig._CONFIG_VARS = None
201
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000202 with EnvironmentVarGuard() as environ:
203 environ['PYTHONUSERBASE'] = 'xoxo'
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000204 self.assertTrue(site.getuserbase().startswith('xoxo'),
205 site.getuserbase())
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000206
207 def test_getusersitepackages(self):
208 site.USER_SITE = None
209 site.USER_BASE = None
210 user_site = site.getusersitepackages()
211
212 # the call sets USER_BASE *and* USER_SITE
Ezio Melottib3aedd42010-11-20 19:04:17 +0000213 self.assertEqual(site.USER_SITE, user_site)
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000214 self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000215
216 def test_getsitepackages(self):
217 site.PREFIXES = ['xoxo']
218 dirs = site.getsitepackages()
219
220 if sys.platform in ('os2emx', 'riscos'):
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000221 self.assertEqual(len(dirs), 1)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000222 wanted = os.path.join('xoxo', 'Lib', 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000223 self.assertEqual(dirs[0], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000224 elif os.sep == '/':
Ezio Melottifc8b2052010-08-17 08:35:41 +0000225 self.assertEqual(len(dirs), 2)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000226 wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
227 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000228 self.assertEqual(dirs[0], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000229 wanted = os.path.join('xoxo', 'lib', 'site-python')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000230 self.assertEqual(dirs[1], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000231 else:
Ezio Melottifc8b2052010-08-17 08:35:41 +0000232 self.assertEqual(len(dirs), 2)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000233 self.assertEqual(dirs[0], 'xoxo')
Tarek Ziadé8c0e2172009-10-27 21:24:21 +0000234 wanted = os.path.join('xoxo', 'lib', 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000235 self.assertEqual(dirs[1], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000236
237 # let's try the specific Apple location
Brett Cannonbbb2d492010-05-14 00:04:56 +0000238 if (sys.platform == "darwin" and
239 sysconfig.get_config_var("PYTHONFRAMEWORK")):
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000240 site.PREFIXES = ['Python.framework']
241 dirs = site.getsitepackages()
Ronald Oussorenbda46722010-08-01 09:02:50 +0000242 self.assertEqual(len(dirs), 3)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000243 wanted = os.path.join('/Library', 'Python', sys.version[:3],
244 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000245 self.assertEqual(dirs[2], wanted)
Christian Heimes8dc226f2008-05-06 23:45:46 +0000246
Brett Cannon64a84702004-07-10 02:10:45 +0000247class PthFile(object):
248 """Helper class for handling testing of .pth files"""
Brett Cannon0096e262004-06-05 01:12:51 +0000249
Brett Cannon64a84702004-07-10 02:10:45 +0000250 def __init__(self, filename_base=TESTFN, imported="time",
251 good_dirname="__testdir__", bad_dirname="__bad"):
252 """Initialize instance variables"""
253 self.filename = filename_base + ".pth"
254 self.base_dir = os.path.abspath('')
255 self.file_path = os.path.join(self.base_dir, self.filename)
Brett Cannonee86a662004-07-13 07:12:25 +0000256 self.imported = imported
Brett Cannon64a84702004-07-10 02:10:45 +0000257 self.good_dirname = good_dirname
258 self.bad_dirname = bad_dirname
259 self.good_dir_path = os.path.join(self.base_dir, self.good_dirname)
260 self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname)
Brett Cannon0096e262004-06-05 01:12:51 +0000261
Brett Cannon64a84702004-07-10 02:10:45 +0000262 def create(self):
263 """Create a .pth file with a comment, blank lines, an ``import
264 <self.imported>``, a line with self.good_dirname, and a line with
265 self.bad_dirname.
Tim Peters182b5ac2004-07-18 06:16:08 +0000266
Brett Cannon64a84702004-07-10 02:10:45 +0000267 Creation of the directory for self.good_dir_path (based off of
268 self.good_dirname) is also performed.
Brett Cannon0096e262004-06-05 01:12:51 +0000269
Brett Cannon64a84702004-07-10 02:10:45 +0000270 Make sure to call self.cleanup() to undo anything done by this method.
Tim Peters182b5ac2004-07-18 06:16:08 +0000271
Brett Cannon64a84702004-07-10 02:10:45 +0000272 """
Michael W. Hudsonff522862005-05-27 14:58:06 +0000273 FILE = open(self.file_path, 'w')
Brett Cannon64a84702004-07-10 02:10:45 +0000274 try:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000275 print("#import @bad module name", file=FILE)
276 print("\n", file=FILE)
277 print("import %s" % self.imported, file=FILE)
278 print(self.good_dirname, file=FILE)
279 print(self.bad_dirname, file=FILE)
Brett Cannon64a84702004-07-10 02:10:45 +0000280 finally:
281 FILE.close()
282 os.mkdir(self.good_dir_path)
283
Brett Cannonee86a662004-07-13 07:12:25 +0000284 def cleanup(self, prep=False):
Brett Cannon64a84702004-07-10 02:10:45 +0000285 """Make sure that the .pth file is deleted, self.imported is not in
286 sys.modules, and that both self.good_dirname and self.bad_dirname are
287 not existing directories."""
Brett Cannonee86a662004-07-13 07:12:25 +0000288 if os.path.exists(self.file_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000289 os.remove(self.file_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000290 if prep:
291 self.imported_module = sys.modules.get(self.imported)
292 if self.imported_module:
293 del sys.modules[self.imported]
294 else:
295 if self.imported_module:
296 sys.modules[self.imported] = self.imported_module
297 if os.path.exists(self.good_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000298 os.rmdir(self.good_dir_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000299 if os.path.exists(self.bad_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000300 os.rmdir(self.bad_dir_path)
Brett Cannon0096e262004-06-05 01:12:51 +0000301
302class ImportSideEffectTests(unittest.TestCase):
303 """Test side-effects from importing 'site'."""
304
305 def setUp(self):
306 """Make a copy of sys.path"""
307 self.sys_path = sys.path[:]
308
309 def tearDown(self):
310 """Restore sys.path"""
Nick Coghlan6ead5522009-10-18 13:19:33 +0000311 sys.path[:] = self.sys_path
Brett Cannon0096e262004-06-05 01:12:51 +0000312
Barry Warsaw28a691b2010-04-17 00:19:56 +0000313 def test_abs_paths(self):
314 # Make sure all imported modules have their __file__ and __cached__
315 # attributes as absolute paths. Arranging to put the Lib directory on
316 # PYTHONPATH would cause the os module to have a relative path for
317 # __file__ if abs_paths() does not get run. sys and builtins (the
318 # only other modules imported before site.py runs) do not have
319 # __file__ or __cached__ because they are built-in.
320 parent = os.path.relpath(os.path.dirname(os.__file__))
321 env = os.environ.copy()
322 env['PYTHONPATH'] = parent
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000323 code = ('import os, sys',
324 # use ASCII to avoid locale issues with non-ASCII directories
325 'os_file = os.__file__.encode("ascii", "backslashreplace")',
326 r'sys.stdout.buffer.write(os_file + b"\n")',
327 'os_cached = os.__cached__.encode("ascii", "backslashreplace")',
328 r'sys.stdout.buffer.write(os_cached + b"\n")')
329 command = '\n'.join(code)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000330 # First, prove that with -S (no 'import site'), the paths are
331 # relative.
332 proc = subprocess.Popen([sys.executable, '-S', '-c', command],
333 env=env,
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000334 stdout=subprocess.PIPE)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000335 stdout, stderr = proc.communicate()
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000336
Barry Warsaw28a691b2010-04-17 00:19:56 +0000337 self.assertEqual(proc.returncode, 0)
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000338 os__file__, os__cached__ = stdout.splitlines()[:2]
Barry Warsaw28a691b2010-04-17 00:19:56 +0000339 self.assertFalse(os.path.isabs(os__file__))
340 self.assertFalse(os.path.isabs(os__cached__))
341 # Now, with 'import site', it works.
342 proc = subprocess.Popen([sys.executable, '-c', command],
343 env=env,
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000344 stdout=subprocess.PIPE)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000345 stdout, stderr = proc.communicate()
346 self.assertEqual(proc.returncode, 0)
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000347 os__file__, os__cached__ = stdout.splitlines()[:2]
Barry Warsaw28a691b2010-04-17 00:19:56 +0000348 self.assertTrue(os.path.isabs(os__file__))
349 self.assertTrue(os.path.isabs(os__cached__))
Brett Cannon0096e262004-06-05 01:12:51 +0000350
351 def test_no_duplicate_paths(self):
352 # No duplicate paths should exist in sys.path
353 # Handled by removeduppaths()
354 site.removeduppaths()
355 seen_paths = set()
356 for path in sys.path:
Benjamin Peterson577473f2010-01-19 00:09:57 +0000357 self.assertNotIn(path, seen_paths)
Brett Cannon0096e262004-06-05 01:12:51 +0000358 seen_paths.add(path)
359
360 def test_add_build_dir(self):
361 # Test that the build directory's Modules directory is used when it
362 # should be.
363 # XXX: implement
364 pass
365
Brett Cannon0096e262004-06-05 01:12:51 +0000366 def test_setting_quit(self):
Georg Brandl1a3284e2007-12-02 09:40:06 +0000367 # 'quit' and 'exit' should be injected into builtins
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000368 self.assertTrue(hasattr(builtins, "quit"))
369 self.assertTrue(hasattr(builtins, "exit"))
Brett Cannon0096e262004-06-05 01:12:51 +0000370
371 def test_setting_copyright(self):
Georg Brandl1a3284e2007-12-02 09:40:06 +0000372 # 'copyright' and 'credits' should be in builtins
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000373 self.assertTrue(hasattr(builtins, "copyright"))
374 self.assertTrue(hasattr(builtins, "credits"))
Brett Cannon0096e262004-06-05 01:12:51 +0000375
376 def test_setting_help(self):
Georg Brandl1a3284e2007-12-02 09:40:06 +0000377 # 'help' should be set in builtins
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000378 self.assertTrue(hasattr(builtins, "help"))
Brett Cannon0096e262004-06-05 01:12:51 +0000379
380 def test_aliasing_mbcs(self):
381 if sys.platform == "win32":
382 import locale
383 if locale.getdefaultlocale()[1].startswith('cp'):
Guido van Rossumcc2b0162007-02-11 06:12:03 +0000384 for value in encodings.aliases.aliases.values():
Brett Cannon0096e262004-06-05 01:12:51 +0000385 if value == "mbcs":
386 break
387 else:
388 self.fail("did not alias mbcs")
389
Brett Cannon0096e262004-06-05 01:12:51 +0000390 def test_sitecustomize_executed(self):
391 # If sitecustomize is available, it should have been imported.
Guido van Rossume2b70bc2006-08-18 22:13:04 +0000392 if "sitecustomize" not in sys.modules:
Brett Cannon0096e262004-06-05 01:12:51 +0000393 try:
394 import sitecustomize
395 except ImportError:
396 pass
397 else:
398 self.fail("sitecustomize not imported automatically")
399
Brett Cannon0096e262004-06-05 01:12:51 +0000400def test_main():
401 run_unittest(HelperFunctionsTests, ImportSideEffectTests)
402
Brett Cannon0096e262004-06-05 01:12:51 +0000403if __name__ == "__main__":
404 test_main()