blob: 0ed4706e7c272ebab17cc15f8aa96089342d2a90 [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
13import encodings
Christian Heimes8dc226f2008-05-06 23:45:46 +000014import subprocess
Tarek Ziadéedacea32010-01-29 11:41:03 +000015import sysconfig
16from copy import copy
17
Brett Cannon0096e262004-06-05 01:12:51 +000018# Need to make sure to not import 'site' if someone specified ``-S`` at the
19# command-line. Detect this by just making sure 'site' has not been imported
20# already.
21if "site" in sys.modules:
22 import site
23else:
Benjamin Petersone549ead2009-03-28 21:42:05 +000024 raise unittest.SkipTest("importation of site.py suppressed")
Brett Cannon0096e262004-06-05 01:12:51 +000025
Christian Heimes8dc226f2008-05-06 23:45:46 +000026if not os.path.isdir(site.USER_SITE):
27 # need to add user site directory for tests
28 os.makedirs(site.USER_SITE)
29 site.addsitedir(site.USER_SITE)
30
Brett Cannon0096e262004-06-05 01:12:51 +000031class HelperFunctionsTests(unittest.TestCase):
32 """Tests for helper functions.
Brett Cannon0096e262004-06-05 01:12:51 +000033 """
34
35 def setUp(self):
36 """Save a copy of sys.path"""
37 self.sys_path = sys.path[:]
Tarek Ziadé4a608c02009-08-20 21:28:05 +000038 self.old_base = site.USER_BASE
39 self.old_site = site.USER_SITE
40 self.old_prefixes = site.PREFIXES
Tarek Ziadéedacea32010-01-29 11:41:03 +000041 self.old_vars = copy(sysconfig._CONFIG_VARS)
Brett Cannon0096e262004-06-05 01:12:51 +000042
Alexandre Vassalottie9f305f2008-05-16 04:39:54 +000043 def tearDown(self):
Brett Cannon0096e262004-06-05 01:12:51 +000044 """Restore sys.path"""
Nick Coghlan6ead5522009-10-18 13:19:33 +000045 sys.path[:] = self.sys_path
Tarek Ziadé4a608c02009-08-20 21:28:05 +000046 site.USER_BASE = self.old_base
47 site.USER_SITE = self.old_site
48 site.PREFIXES = self.old_prefixes
Tarek Ziadéedacea32010-01-29 11:41:03 +000049 sysconfig._CONFIG_VARS = self.old_vars
Raymond Hettingerebd95222004-06-27 03:02:18 +000050
Brett Cannon0096e262004-06-05 01:12:51 +000051 def test_makepath(self):
52 # Test makepath() have an absolute path for its first return value
53 # and a case-normalized version of the absolute path for its
54 # second value.
55 path_parts = ("Beginning", "End")
56 original_dir = os.path.join(*path_parts)
57 abs_dir, norm_dir = site.makepath(*path_parts)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000058 self.assertEqual(os.path.abspath(original_dir), abs_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000059 if original_dir == os.path.normcase(original_dir):
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000060 self.assertEqual(abs_dir, norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000061 else:
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000062 self.assertEqual(os.path.normcase(abs_dir), norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000063
64 def test_init_pathinfo(self):
65 dir_set = site._init_pathinfo()
66 for entry in [site.makepath(path)[1] for path in sys.path
67 if path and os.path.isdir(path)]:
Ezio Melottib58e0bd2010-01-23 15:40:09 +000068 self.assertIn(entry, dir_set,
69 "%s from sys.path not found in set returned "
70 "by _init_pathinfo(): %s" % (entry, dir_set))
Raymond Hettingerebd95222004-06-27 03:02:18 +000071
Brett Cannonee86a662004-07-13 07:12:25 +000072 def pth_file_tests(self, pth_file):
73 """Contain common code for testing results of reading a .pth file"""
Ezio Melottib58e0bd2010-01-23 15:40:09 +000074 self.assertIn(pth_file.imported, sys.modules,
75 "%s not in sys.modules" % pth_file.imported)
Antoine Pitrou9166e6a2009-11-01 23:55:40 +000076 self.assertIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
77 self.assertFalse(os.path.exists(pth_file.bad_dir_path))
Brett Cannonee86a662004-07-13 07:12:25 +000078
Brett Cannon0096e262004-06-05 01:12:51 +000079 def test_addpackage(self):
80 # Make sure addpackage() imports if the line starts with 'import',
Brett Cannon64a84702004-07-10 02:10:45 +000081 # adds directories to sys.path for any line in the file that is not a
82 # comment or import that is a valid directory name for where the .pth
83 # file resides; invalid directories are not added
84 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +000085 pth_file.cleanup(prep=True) # to make sure that nothing is
86 # pre-existing that shouldn't be
Brett Cannon0096e262004-06-05 01:12:51 +000087 try:
Brett Cannon64a84702004-07-10 02:10:45 +000088 pth_file.create()
89 site.addpackage(pth_file.base_dir, pth_file.filename, set())
Brett Cannonee86a662004-07-13 07:12:25 +000090 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +000091 finally:
Brett Cannon64a84702004-07-10 02:10:45 +000092 pth_file.cleanup()
Raymond Hettingerebd95222004-06-27 03:02:18 +000093
R. David Murrayb4ca59b2010-12-26 19:54:29 +000094 def make_pth(self, contents, pth_dir='.', pth_name=TESTFN):
95 # Create a .pth file and return its (abspath, basename).
96 pth_dir = os.path.abspath(pth_dir)
97 pth_basename = pth_name + '.pth'
98 pth_fn = os.path.join(pth_dir, pth_basename)
99 pth_file = open(pth_fn, 'w', encoding='utf-8')
100 self.addCleanup(lambda: os.remove(pth_fn))
101 pth_file.write(contents)
102 pth_file.close()
103 return pth_dir, pth_basename
104
105 def test_addpackage_import_bad_syntax(self):
106 # Issue 10642
107 pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
108 with captured_stderr() as err_out:
109 site.addpackage(pth_dir, pth_fn, set())
110 self.assertRegex(err_out.getvalue(), "line 1")
111 self.assertRegex(err_out.getvalue(), os.path.join(pth_dir, pth_fn))
112 # XXX: the previous two should be independent checks so that the
113 # order doesn't matter. The next three could be a single check
114 # but my regex foo isn't good enough to write it.
115 self.assertRegex(err_out.getvalue(), 'Traceback')
116 self.assertRegex(err_out.getvalue(), r'import bad\)syntax')
117 self.assertRegex(err_out.getvalue(), 'SyntaxError')
118
119 def test_addpackage_import_bad_exec(self):
120 # Issue 10642
121 pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
122 with captured_stderr() as err_out:
123 site.addpackage(pth_dir, pth_fn, set())
124 self.assertRegex(err_out.getvalue(), "line 2")
125 self.assertRegex(err_out.getvalue(), os.path.join(pth_dir, pth_fn))
126 # XXX: ditto previous XXX comment.
127 self.assertRegex(err_out.getvalue(), 'Traceback')
128 self.assertRegex(err_out.getvalue(), 'ImportError')
129
130 def test_addpackage_import_bad_pth_file(self):
131 # Issue 5258
132 pth_dir, pth_fn = self.make_pth("abc\x00def\n")
133 with captured_stderr() as err_out:
134 site.addpackage(pth_dir, pth_fn, set())
135 self.assertRegex(err_out.getvalue(), "line 1")
136 self.assertRegex(err_out.getvalue(), os.path.join(pth_dir, pth_fn))
137 # XXX: ditto previous XXX comment.
138 self.assertRegex(err_out.getvalue(), 'Traceback')
139 self.assertRegex(err_out.getvalue(), 'TypeError')
140
Brett Cannon0096e262004-06-05 01:12:51 +0000141 def test_addsitedir(self):
Brett Cannon64a84702004-07-10 02:10:45 +0000142 # Same tests for test_addpackage since addsitedir() essentially just
143 # calls addpackage() for every .pth file in the directory
144 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000145 pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
146 # that is tested for
Brett Cannon0096e262004-06-05 01:12:51 +0000147 try:
Brett Cannonee86a662004-07-13 07:12:25 +0000148 pth_file.create()
Brett Cannon64a84702004-07-10 02:10:45 +0000149 site.addsitedir(pth_file.base_dir, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000150 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000151 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000152 pth_file.cleanup()
Brett Cannon0096e262004-06-05 01:12:51 +0000153
Christian Heimes8dc226f2008-05-06 23:45:46 +0000154 def test_s_option(self):
155 usersite = site.USER_SITE
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000156 self.assertIn(usersite, sys.path)
Christian Heimes8dc226f2008-05-06 23:45:46 +0000157
158 rc = subprocess.call([sys.executable, '-c',
Benjamin Petersonfea6a942008-07-02 16:11:42 +0000159 'import sys; sys.exit(%r in sys.path)' % usersite])
Christian Heimes8dc226f2008-05-06 23:45:46 +0000160 self.assertEqual(rc, 1)
161
162 rc = subprocess.call([sys.executable, '-s', '-c',
Benjamin Petersonfea6a942008-07-02 16:11:42 +0000163 'import sys; sys.exit(%r in sys.path)' % usersite])
Christian Heimes8dc226f2008-05-06 23:45:46 +0000164 self.assertEqual(rc, 0)
165
166 env = os.environ.copy()
167 env["PYTHONNOUSERSITE"] = "1"
168 rc = subprocess.call([sys.executable, '-c',
Benjamin Petersonfea6a942008-07-02 16:11:42 +0000169 'import sys; sys.exit(%r in sys.path)' % usersite],
Christian Heimes8dc226f2008-05-06 23:45:46 +0000170 env=env)
171 self.assertEqual(rc, 0)
172
173 env = os.environ.copy()
174 env["PYTHONUSERBASE"] = "/tmp"
175 rc = subprocess.call([sys.executable, '-c',
176 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
177 env=env)
178 self.assertEqual(rc, 1)
179
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000180 def test_getuserbase(self):
181 site.USER_BASE = None
182 user_base = site.getuserbase()
183
184 # the call sets site.USER_BASE
Ezio Melottib3aedd42010-11-20 19:04:17 +0000185 self.assertEqual(site.USER_BASE, user_base)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000186
187 # let's set PYTHONUSERBASE and see if it uses it
188 site.USER_BASE = None
Tarek Ziadéedacea32010-01-29 11:41:03 +0000189 import sysconfig
190 sysconfig._CONFIG_VARS = None
191
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000192 with EnvironmentVarGuard() as environ:
193 environ['PYTHONUSERBASE'] = 'xoxo'
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000194 self.assertTrue(site.getuserbase().startswith('xoxo'),
195 site.getuserbase())
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000196
197 def test_getusersitepackages(self):
198 site.USER_SITE = None
199 site.USER_BASE = None
200 user_site = site.getusersitepackages()
201
202 # the call sets USER_BASE *and* USER_SITE
Ezio Melottib3aedd42010-11-20 19:04:17 +0000203 self.assertEqual(site.USER_SITE, user_site)
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000204 self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000205
206 def test_getsitepackages(self):
207 site.PREFIXES = ['xoxo']
208 dirs = site.getsitepackages()
209
210 if sys.platform in ('os2emx', 'riscos'):
Antoine Pitrou9166e6a2009-11-01 23:55:40 +0000211 self.assertEqual(len(dirs), 1)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000212 wanted = os.path.join('xoxo', 'Lib', 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000213 self.assertEqual(dirs[0], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000214 elif os.sep == '/':
Ezio Melottifc8b2052010-08-17 08:35:41 +0000215 self.assertEqual(len(dirs), 2)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000216 wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
217 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000218 self.assertEqual(dirs[0], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000219 wanted = os.path.join('xoxo', 'lib', 'site-python')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000220 self.assertEqual(dirs[1], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000221 else:
Ezio Melottifc8b2052010-08-17 08:35:41 +0000222 self.assertEqual(len(dirs), 2)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000223 self.assertEqual(dirs[0], 'xoxo')
Tarek Ziadé8c0e2172009-10-27 21:24:21 +0000224 wanted = os.path.join('xoxo', 'lib', 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000225 self.assertEqual(dirs[1], wanted)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000226
227 # let's try the specific Apple location
Brett Cannonbbb2d492010-05-14 00:04:56 +0000228 if (sys.platform == "darwin" and
229 sysconfig.get_config_var("PYTHONFRAMEWORK")):
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000230 site.PREFIXES = ['Python.framework']
231 dirs = site.getsitepackages()
Ronald Oussorenbda46722010-08-01 09:02:50 +0000232 self.assertEqual(len(dirs), 3)
Tarek Ziadé4a608c02009-08-20 21:28:05 +0000233 wanted = os.path.join('/Library', 'Python', sys.version[:3],
234 'site-packages')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000235 self.assertEqual(dirs[2], wanted)
Christian Heimes8dc226f2008-05-06 23:45:46 +0000236
Brett Cannon64a84702004-07-10 02:10:45 +0000237class PthFile(object):
238 """Helper class for handling testing of .pth files"""
Brett Cannon0096e262004-06-05 01:12:51 +0000239
Brett Cannon64a84702004-07-10 02:10:45 +0000240 def __init__(self, filename_base=TESTFN, imported="time",
241 good_dirname="__testdir__", bad_dirname="__bad"):
242 """Initialize instance variables"""
243 self.filename = filename_base + ".pth"
244 self.base_dir = os.path.abspath('')
245 self.file_path = os.path.join(self.base_dir, self.filename)
Brett Cannonee86a662004-07-13 07:12:25 +0000246 self.imported = imported
Brett Cannon64a84702004-07-10 02:10:45 +0000247 self.good_dirname = good_dirname
248 self.bad_dirname = bad_dirname
249 self.good_dir_path = os.path.join(self.base_dir, self.good_dirname)
250 self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname)
Brett Cannon0096e262004-06-05 01:12:51 +0000251
Brett Cannon64a84702004-07-10 02:10:45 +0000252 def create(self):
253 """Create a .pth file with a comment, blank lines, an ``import
254 <self.imported>``, a line with self.good_dirname, and a line with
255 self.bad_dirname.
Tim Peters182b5ac2004-07-18 06:16:08 +0000256
Brett Cannon64a84702004-07-10 02:10:45 +0000257 Creation of the directory for self.good_dir_path (based off of
258 self.good_dirname) is also performed.
Brett Cannon0096e262004-06-05 01:12:51 +0000259
Brett Cannon64a84702004-07-10 02:10:45 +0000260 Make sure to call self.cleanup() to undo anything done by this method.
Tim Peters182b5ac2004-07-18 06:16:08 +0000261
Brett Cannon64a84702004-07-10 02:10:45 +0000262 """
Michael W. Hudsonff522862005-05-27 14:58:06 +0000263 FILE = open(self.file_path, 'w')
Brett Cannon64a84702004-07-10 02:10:45 +0000264 try:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000265 print("#import @bad module name", file=FILE)
266 print("\n", file=FILE)
267 print("import %s" % self.imported, file=FILE)
268 print(self.good_dirname, file=FILE)
269 print(self.bad_dirname, file=FILE)
Brett Cannon64a84702004-07-10 02:10:45 +0000270 finally:
271 FILE.close()
272 os.mkdir(self.good_dir_path)
273
Brett Cannonee86a662004-07-13 07:12:25 +0000274 def cleanup(self, prep=False):
Brett Cannon64a84702004-07-10 02:10:45 +0000275 """Make sure that the .pth file is deleted, self.imported is not in
276 sys.modules, and that both self.good_dirname and self.bad_dirname are
277 not existing directories."""
Brett Cannonee86a662004-07-13 07:12:25 +0000278 if os.path.exists(self.file_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000279 os.remove(self.file_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000280 if prep:
281 self.imported_module = sys.modules.get(self.imported)
282 if self.imported_module:
283 del sys.modules[self.imported]
284 else:
285 if self.imported_module:
286 sys.modules[self.imported] = self.imported_module
287 if os.path.exists(self.good_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000288 os.rmdir(self.good_dir_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000289 if os.path.exists(self.bad_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000290 os.rmdir(self.bad_dir_path)
Brett Cannon0096e262004-06-05 01:12:51 +0000291
292class ImportSideEffectTests(unittest.TestCase):
293 """Test side-effects from importing 'site'."""
294
295 def setUp(self):
296 """Make a copy of sys.path"""
297 self.sys_path = sys.path[:]
298
299 def tearDown(self):
300 """Restore sys.path"""
Nick Coghlan6ead5522009-10-18 13:19:33 +0000301 sys.path[:] = self.sys_path
Brett Cannon0096e262004-06-05 01:12:51 +0000302
Barry Warsaw28a691b2010-04-17 00:19:56 +0000303 def test_abs_paths(self):
304 # Make sure all imported modules have their __file__ and __cached__
305 # attributes as absolute paths. Arranging to put the Lib directory on
306 # PYTHONPATH would cause the os module to have a relative path for
307 # __file__ if abs_paths() does not get run. sys and builtins (the
308 # only other modules imported before site.py runs) do not have
309 # __file__ or __cached__ because they are built-in.
310 parent = os.path.relpath(os.path.dirname(os.__file__))
311 env = os.environ.copy()
312 env['PYTHONPATH'] = parent
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000313 code = ('import os, sys',
314 # use ASCII to avoid locale issues with non-ASCII directories
315 'os_file = os.__file__.encode("ascii", "backslashreplace")',
316 r'sys.stdout.buffer.write(os_file + b"\n")',
317 'os_cached = os.__cached__.encode("ascii", "backslashreplace")',
318 r'sys.stdout.buffer.write(os_cached + b"\n")')
319 command = '\n'.join(code)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000320 # First, prove that with -S (no 'import site'), the paths are
321 # relative.
322 proc = subprocess.Popen([sys.executable, '-S', '-c', command],
323 env=env,
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000324 stdout=subprocess.PIPE)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000325 stdout, stderr = proc.communicate()
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000326
Barry Warsaw28a691b2010-04-17 00:19:56 +0000327 self.assertEqual(proc.returncode, 0)
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000328 os__file__, os__cached__ = stdout.splitlines()[:2]
Barry Warsaw28a691b2010-04-17 00:19:56 +0000329 self.assertFalse(os.path.isabs(os__file__))
330 self.assertFalse(os.path.isabs(os__cached__))
331 # Now, with 'import site', it works.
332 proc = subprocess.Popen([sys.executable, '-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()
336 self.assertEqual(proc.returncode, 0)
Victor Stinnerf3bc2582010-04-18 07:59:53 +0000337 os__file__, os__cached__ = stdout.splitlines()[:2]
Barry Warsaw28a691b2010-04-17 00:19:56 +0000338 self.assertTrue(os.path.isabs(os__file__))
339 self.assertTrue(os.path.isabs(os__cached__))
Brett Cannon0096e262004-06-05 01:12:51 +0000340
341 def test_no_duplicate_paths(self):
342 # No duplicate paths should exist in sys.path
343 # Handled by removeduppaths()
344 site.removeduppaths()
345 seen_paths = set()
346 for path in sys.path:
Benjamin Peterson577473f2010-01-19 00:09:57 +0000347 self.assertNotIn(path, seen_paths)
Brett Cannon0096e262004-06-05 01:12:51 +0000348 seen_paths.add(path)
349
350 def test_add_build_dir(self):
351 # Test that the build directory's Modules directory is used when it
352 # should be.
353 # XXX: implement
354 pass
355
Brett Cannon0096e262004-06-05 01:12:51 +0000356 def test_setting_quit(self):
Georg Brandl1a3284e2007-12-02 09:40:06 +0000357 # 'quit' and 'exit' should be injected into builtins
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000358 self.assertTrue(hasattr(builtins, "quit"))
359 self.assertTrue(hasattr(builtins, "exit"))
Brett Cannon0096e262004-06-05 01:12:51 +0000360
361 def test_setting_copyright(self):
Georg Brandl1a3284e2007-12-02 09:40:06 +0000362 # 'copyright' and 'credits' should be in builtins
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000363 self.assertTrue(hasattr(builtins, "copyright"))
364 self.assertTrue(hasattr(builtins, "credits"))
Brett Cannon0096e262004-06-05 01:12:51 +0000365
366 def test_setting_help(self):
Georg Brandl1a3284e2007-12-02 09:40:06 +0000367 # 'help' should be set in builtins
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000368 self.assertTrue(hasattr(builtins, "help"))
Brett Cannon0096e262004-06-05 01:12:51 +0000369
370 def test_aliasing_mbcs(self):
371 if sys.platform == "win32":
372 import locale
373 if locale.getdefaultlocale()[1].startswith('cp'):
Guido van Rossumcc2b0162007-02-11 06:12:03 +0000374 for value in encodings.aliases.aliases.values():
Brett Cannon0096e262004-06-05 01:12:51 +0000375 if value == "mbcs":
376 break
377 else:
378 self.fail("did not alias mbcs")
379
Brett Cannon0096e262004-06-05 01:12:51 +0000380 def test_sitecustomize_executed(self):
381 # If sitecustomize is available, it should have been imported.
Guido van Rossume2b70bc2006-08-18 22:13:04 +0000382 if "sitecustomize" not in sys.modules:
Brett Cannon0096e262004-06-05 01:12:51 +0000383 try:
384 import sitecustomize
385 except ImportError:
386 pass
387 else:
388 self.fail("sitecustomize not imported automatically")
389
Brett Cannon0096e262004-06-05 01:12:51 +0000390def test_main():
391 run_unittest(HelperFunctionsTests, ImportSideEffectTests)
392
Brett Cannon0096e262004-06-05 01:12:51 +0000393if __name__ == "__main__":
394 test_main()