blob: 78c48094e4b57daa5b3e93c0aa969cdf6f6d561e [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örwald4b965f62009-04-26 20:51:44 +00008from test.test_support import run_unittest, TESTFN, EnvironmentVarGuard
R. David Murray5874ed62010-12-26 22:29:53 +00009from test.test_support import captured_output
Brett Cannon0096e262004-06-05 01:12:51 +000010import __builtin__
11import os
12import sys
R. David Murray82f58462010-12-27 00:09:41 +000013import re
Brett Cannon0096e262004-06-05 01:12:51 +000014import encodings
Christian Heimesaf748c32008-05-06 22:41:46 +000015import subprocess
Tarek Ziadé5633a802010-01-23 09:23:15 +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 Petersonbec087f2009-03-26 21:10:30 +000025 raise unittest.SkipTest("importation of site.py suppressed")
Brett Cannon0096e262004-06-05 01:12:51 +000026
Ned Deily1aacd7b2011-10-31 16:14:52 -070027if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
Christian Heimesaf748c32008-05-06 22:41:46 +000028 # need to add user site directory for tests
Victor Stinnerec8d6c22016-03-14 17:49:46 +010029 try:
30 os.makedirs(site.USER_SITE)
31 site.addsitedir(site.USER_SITE)
32 except OSError as exc:
33 raise unittest.SkipTest('unable to create user site directory (%r): %s'
34 % (site.USER_SITE, exc))
35
Christian Heimesaf748c32008-05-06 22:41:46 +000036
Brett Cannon0096e262004-06-05 01:12:51 +000037class HelperFunctionsTests(unittest.TestCase):
38 """Tests for helper functions.
Raymond Hettingerebd95222004-06-27 03:02:18 +000039
Brett Cannon0096e262004-06-05 01:12:51 +000040 The setting of the encoding (set using sys.setdefaultencoding) used by
41 the Unicode implementation is not tested.
Raymond Hettingerebd95222004-06-27 03:02:18 +000042
Brett Cannon0096e262004-06-05 01:12:51 +000043 """
44
45 def setUp(self):
46 """Save a copy of sys.path"""
47 self.sys_path = sys.path[:]
Tarek Ziadé764fc232009-08-20 21:23:13 +000048 self.old_base = site.USER_BASE
49 self.old_site = site.USER_SITE
50 self.old_prefixes = site.PREFIXES
Tarek Ziadé5633a802010-01-23 09:23:15 +000051 self.old_vars = copy(sysconfig._CONFIG_VARS)
Brett Cannon0096e262004-06-05 01:12:51 +000052
Neal Norwitz40388cc2008-05-14 06:47:56 +000053 def tearDown(self):
Brett Cannon0096e262004-06-05 01:12:51 +000054 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +000055 sys.path[:] = self.sys_path
Tarek Ziadé764fc232009-08-20 21:23:13 +000056 site.USER_BASE = self.old_base
57 site.USER_SITE = self.old_site
58 site.PREFIXES = self.old_prefixes
Tarek Ziadé5633a802010-01-23 09:23:15 +000059 sysconfig._CONFIG_VARS = self.old_vars
Raymond Hettingerebd95222004-06-27 03:02:18 +000060
Brett Cannon0096e262004-06-05 01:12:51 +000061 def test_makepath(self):
62 # Test makepath() have an absolute path for its first return value
63 # and a case-normalized version of the absolute path for its
64 # second value.
65 path_parts = ("Beginning", "End")
66 original_dir = os.path.join(*path_parts)
67 abs_dir, norm_dir = site.makepath(*path_parts)
Benjamin Peterson5c8da862009-06-30 22:57:08 +000068 self.assertEqual(os.path.abspath(original_dir), abs_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000069 if original_dir == os.path.normcase(original_dir):
Benjamin Peterson5c8da862009-06-30 22:57:08 +000070 self.assertEqual(abs_dir, norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000071 else:
Benjamin Peterson5c8da862009-06-30 22:57:08 +000072 self.assertEqual(os.path.normcase(abs_dir), norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000073
74 def test_init_pathinfo(self):
75 dir_set = site._init_pathinfo()
76 for entry in [site.makepath(path)[1] for path in sys.path
77 if path and os.path.isdir(path)]:
Ezio Melottiaa980582010-01-23 23:04:36 +000078 self.assertIn(entry, dir_set,
79 "%s from sys.path not found in set returned "
80 "by _init_pathinfo(): %s" % (entry, dir_set))
Raymond Hettingerebd95222004-06-27 03:02:18 +000081
Brett Cannonee86a662004-07-13 07:12:25 +000082 def pth_file_tests(self, pth_file):
83 """Contain common code for testing results of reading a .pth file"""
Ezio Melottiaa980582010-01-23 23:04:36 +000084 self.assertIn(pth_file.imported, sys.modules,
85 "%s not in sys.modules" % pth_file.imported)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +000086 self.assertIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
87 self.assertFalse(os.path.exists(pth_file.bad_dir_path))
Brett Cannonee86a662004-07-13 07:12:25 +000088
Brett Cannon0096e262004-06-05 01:12:51 +000089 def test_addpackage(self):
90 # Make sure addpackage() imports if the line starts with 'import',
Brett Cannon64a84702004-07-10 02:10:45 +000091 # adds directories to sys.path for any line in the file that is not a
92 # comment or import that is a valid directory name for where the .pth
93 # file resides; invalid directories are not added
94 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +000095 pth_file.cleanup(prep=True) # to make sure that nothing is
96 # pre-existing that shouldn't be
Brett Cannon0096e262004-06-05 01:12:51 +000097 try:
Brett Cannon64a84702004-07-10 02:10:45 +000098 pth_file.create()
99 site.addpackage(pth_file.base_dir, pth_file.filename, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000100 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000101 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000102 pth_file.cleanup()
Raymond Hettingerebd95222004-06-27 03:02:18 +0000103
R. David Murray5874ed62010-12-26 22:29:53 +0000104 def make_pth(self, contents, pth_dir='.', pth_name=TESTFN):
105 # Create a .pth file and return its (abspath, basename).
106 pth_dir = os.path.abspath(pth_dir)
107 pth_basename = pth_name + '.pth'
108 pth_fn = os.path.join(pth_dir, pth_basename)
109 pth_file = open(pth_fn, 'w')
110 self.addCleanup(lambda: os.remove(pth_fn))
111 pth_file.write(contents)
112 pth_file.close()
113 return pth_dir, pth_basename
114
115 def test_addpackage_import_bad_syntax(self):
116 # Issue 10642
117 pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
118 with captured_output("stderr") as err_out:
119 site.addpackage(pth_dir, pth_fn, set())
120 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000121 self.assertRegexpMatches(err_out.getvalue(),
122 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000123 # XXX: the previous two should be independent checks so that the
124 # order doesn't matter. The next three could be a single check
125 # but my regex foo isn't good enough to write it.
126 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
127 self.assertRegexpMatches(err_out.getvalue(), r'import bad\)syntax')
128 self.assertRegexpMatches(err_out.getvalue(), 'SyntaxError')
129
130 def test_addpackage_import_bad_exec(self):
131 # Issue 10642
132 pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
133 with captured_output("stderr") as err_out:
134 site.addpackage(pth_dir, pth_fn, set())
135 self.assertRegexpMatches(err_out.getvalue(), "line 2")
R. David Murray82f58462010-12-27 00:09:41 +0000136 self.assertRegexpMatches(err_out.getvalue(),
137 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000138 # XXX: ditto previous XXX comment.
139 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
140 self.assertRegexpMatches(err_out.getvalue(), 'ImportError')
141
R. David Murray49ee82c2010-12-27 04:37:25 +0000142 @unittest.skipIf(sys.platform == "win32", "Windows does not raise an "
143 "error for file paths containing null characters")
R. David Murray5874ed62010-12-26 22:29:53 +0000144 def test_addpackage_import_bad_pth_file(self):
145 # Issue 5258
146 pth_dir, pth_fn = self.make_pth("abc\x00def\n")
147 with captured_output("stderr") as err_out:
148 site.addpackage(pth_dir, pth_fn, set())
149 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000150 self.assertRegexpMatches(err_out.getvalue(),
151 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000152 # XXX: ditto previous XXX comment.
153 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
154 self.assertRegexpMatches(err_out.getvalue(), 'TypeError')
155
Brett Cannon0096e262004-06-05 01:12:51 +0000156 def test_addsitedir(self):
Brett Cannon64a84702004-07-10 02:10:45 +0000157 # Same tests for test_addpackage since addsitedir() essentially just
158 # calls addpackage() for every .pth file in the directory
159 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000160 pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
161 # that is tested for
Brett Cannon0096e262004-06-05 01:12:51 +0000162 try:
Brett Cannonee86a662004-07-13 07:12:25 +0000163 pth_file.create()
Brett Cannon64a84702004-07-10 02:10:45 +0000164 site.addsitedir(pth_file.base_dir, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000165 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000166 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000167 pth_file.cleanup()
Brett Cannon0096e262004-06-05 01:12:51 +0000168
Ned Deily1aacd7b2011-10-31 16:14:52 -0700169 @unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
170 "user-site (site.ENABLE_USER_SITE)")
Christian Heimesaf748c32008-05-06 22:41:46 +0000171 def test_s_option(self):
172 usersite = site.USER_SITE
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000173 self.assertIn(usersite, sys.path)
Christian Heimesaf748c32008-05-06 22:41:46 +0000174
Éric Araujo513c4f82011-01-03 17:57:29 +0000175 env = os.environ.copy()
Christian Heimesaf748c32008-05-06 22:41:46 +0000176 rc = subprocess.call([sys.executable, '-c',
Éric Araujo513c4f82011-01-03 17:57:29 +0000177 'import sys; sys.exit(%r in sys.path)' % usersite],
178 env=env)
Brett Cannonb7019d82009-02-24 22:01:02 +0000179 self.assertEqual(rc, 1, "%r is not in sys.path (sys.exit returned %r)"
180 % (usersite, rc))
Christian Heimesaf748c32008-05-06 22:41:46 +0000181
Éric Araujo513c4f82011-01-03 17:57:29 +0000182 env = os.environ.copy()
Christian Heimesaf748c32008-05-06 22:41:46 +0000183 rc = subprocess.call([sys.executable, '-s', '-c',
Éric Araujo513c4f82011-01-03 17:57:29 +0000184 'import sys; sys.exit(%r in sys.path)' % usersite],
185 env=env)
Christian Heimesaf748c32008-05-06 22:41:46 +0000186 self.assertEqual(rc, 0)
187
188 env = os.environ.copy()
189 env["PYTHONNOUSERSITE"] = "1"
190 rc = subprocess.call([sys.executable, '-c',
Amaury Forgeot d'Arc9b69ed92008-06-19 21:17:12 +0000191 'import sys; sys.exit(%r in sys.path)' % usersite],
Christian Heimesaf748c32008-05-06 22:41:46 +0000192 env=env)
193 self.assertEqual(rc, 0)
194
195 env = os.environ.copy()
196 env["PYTHONUSERBASE"] = "/tmp"
197 rc = subprocess.call([sys.executable, '-c',
198 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
199 env=env)
200 self.assertEqual(rc, 1)
201
Tarek Ziadé764fc232009-08-20 21:23:13 +0000202 def test_getuserbase(self):
203 site.USER_BASE = None
204 user_base = site.getuserbase()
205
206 # the call sets site.USER_BASE
Ezio Melotti2623a372010-11-21 13:34:58 +0000207 self.assertEqual(site.USER_BASE, user_base)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000208
209 # let's set PYTHONUSERBASE and see if it uses it
210 site.USER_BASE = None
Tarek Ziadé5633a802010-01-23 09:23:15 +0000211 import sysconfig
212 sysconfig._CONFIG_VARS = None
213
Tarek Ziadé764fc232009-08-20 21:23:13 +0000214 with EnvironmentVarGuard() as environ:
215 environ['PYTHONUSERBASE'] = 'xoxo'
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000216 self.assertTrue(site.getuserbase().startswith('xoxo'),
217 site.getuserbase())
Tarek Ziadé764fc232009-08-20 21:23:13 +0000218
219 def test_getusersitepackages(self):
220 site.USER_SITE = None
221 site.USER_BASE = None
222 user_site = site.getusersitepackages()
223
224 # the call sets USER_BASE *and* USER_SITE
Ezio Melotti2623a372010-11-21 13:34:58 +0000225 self.assertEqual(site.USER_SITE, user_site)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000226 self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000227
228 def test_getsitepackages(self):
229 site.PREFIXES = ['xoxo']
230 dirs = site.getsitepackages()
231
232 if sys.platform in ('os2emx', 'riscos'):
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000233 self.assertEqual(len(dirs), 1)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000234 wanted = os.path.join('xoxo', 'Lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000235 self.assertEqual(dirs[0], wanted)
Ned Deily2c8bf042012-02-06 00:55:50 +0100236 elif (sys.platform == "darwin" and
237 sysconfig.get_config_var("PYTHONFRAMEWORK")):
238 # OS X framework builds
239 site.PREFIXES = ['Python.framework']
240 dirs = site.getsitepackages()
241 self.assertEqual(len(dirs), 3)
242 wanted = os.path.join('/Library',
243 sysconfig.get_config_var("PYTHONFRAMEWORK"),
244 sys.version[:3],
245 'site-packages')
246 self.assertEqual(dirs[2], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000247 elif os.sep == '/':
Ned Deily2c8bf042012-02-06 00:55:50 +0100248 # OS X non-framwework builds, Linux, FreeBSD, etc
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000249 self.assertEqual(len(dirs), 2)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000250 wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
251 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000252 self.assertEqual(dirs[0], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000253 wanted = os.path.join('xoxo', 'lib', 'site-python')
Ezio Melotti2623a372010-11-21 13:34:58 +0000254 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000255 else:
Ned Deily2c8bf042012-02-06 00:55:50 +0100256 # other platforms
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000257 self.assertEqual(len(dirs), 2)
Ezio Melotti2623a372010-11-21 13:34:58 +0000258 self.assertEqual(dirs[0], 'xoxo')
Tarek Ziadéd24cab82009-10-27 21:20:27 +0000259 wanted = os.path.join('xoxo', 'lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000260 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000261
Brett Cannon64a84702004-07-10 02:10:45 +0000262class PthFile(object):
263 """Helper class for handling testing of .pth files"""
Brett Cannon0096e262004-06-05 01:12:51 +0000264
Brett Cannon64a84702004-07-10 02:10:45 +0000265 def __init__(self, filename_base=TESTFN, imported="time",
266 good_dirname="__testdir__", bad_dirname="__bad"):
267 """Initialize instance variables"""
268 self.filename = filename_base + ".pth"
269 self.base_dir = os.path.abspath('')
270 self.file_path = os.path.join(self.base_dir, self.filename)
Brett Cannonee86a662004-07-13 07:12:25 +0000271 self.imported = imported
Brett Cannon64a84702004-07-10 02:10:45 +0000272 self.good_dirname = good_dirname
273 self.bad_dirname = bad_dirname
274 self.good_dir_path = os.path.join(self.base_dir, self.good_dirname)
275 self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname)
Brett Cannon0096e262004-06-05 01:12:51 +0000276
Brett Cannon64a84702004-07-10 02:10:45 +0000277 def create(self):
278 """Create a .pth file with a comment, blank lines, an ``import
279 <self.imported>``, a line with self.good_dirname, and a line with
280 self.bad_dirname.
Tim Peters182b5ac2004-07-18 06:16:08 +0000281
Brett Cannon64a84702004-07-10 02:10:45 +0000282 Creation of the directory for self.good_dir_path (based off of
283 self.good_dirname) is also performed.
Brett Cannon0096e262004-06-05 01:12:51 +0000284
Brett Cannon64a84702004-07-10 02:10:45 +0000285 Make sure to call self.cleanup() to undo anything done by this method.
Tim Peters182b5ac2004-07-18 06:16:08 +0000286
Brett Cannon64a84702004-07-10 02:10:45 +0000287 """
Michael W. Hudsonff522862005-05-27 14:58:06 +0000288 FILE = open(self.file_path, 'w')
Brett Cannon64a84702004-07-10 02:10:45 +0000289 try:
290 print>>FILE, "#import @bad module name"
291 print>>FILE, "\n"
292 print>>FILE, "import %s" % self.imported
293 print>>FILE, self.good_dirname
294 print>>FILE, self.bad_dirname
295 finally:
296 FILE.close()
297 os.mkdir(self.good_dir_path)
298
Brett Cannonee86a662004-07-13 07:12:25 +0000299 def cleanup(self, prep=False):
Brett Cannon64a84702004-07-10 02:10:45 +0000300 """Make sure that the .pth file is deleted, self.imported is not in
301 sys.modules, and that both self.good_dirname and self.bad_dirname are
302 not existing directories."""
Brett Cannonee86a662004-07-13 07:12:25 +0000303 if os.path.exists(self.file_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000304 os.remove(self.file_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000305 if prep:
306 self.imported_module = sys.modules.get(self.imported)
307 if self.imported_module:
308 del sys.modules[self.imported]
309 else:
310 if self.imported_module:
311 sys.modules[self.imported] = self.imported_module
312 if os.path.exists(self.good_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000313 os.rmdir(self.good_dir_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000314 if os.path.exists(self.bad_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000315 os.rmdir(self.bad_dir_path)
Brett Cannon0096e262004-06-05 01:12:51 +0000316
317class ImportSideEffectTests(unittest.TestCase):
318 """Test side-effects from importing 'site'."""
319
320 def setUp(self):
321 """Make a copy of sys.path"""
322 self.sys_path = sys.path[:]
323
324 def tearDown(self):
325 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +0000326 sys.path[:] = self.sys_path
Brett Cannon0096e262004-06-05 01:12:51 +0000327
328 def test_abs__file__(self):
329 # Make sure all imported modules have their __file__ attribute
330 # as an absolute path.
331 # Handled by abs__file__()
332 site.abs__file__()
Raymond Hettingerebd95222004-06-27 03:02:18 +0000333 for module in (sys, os, __builtin__):
Brett Cannon0096e262004-06-05 01:12:51 +0000334 try:
Ezio Melottidde5b942010-02-03 05:37:26 +0000335 self.assertTrue(os.path.isabs(module.__file__), repr(module))
Brett Cannon0096e262004-06-05 01:12:51 +0000336 except AttributeError:
337 continue
Raymond Hettingerebd95222004-06-27 03:02:18 +0000338 # We could try everything in sys.modules; however, when regrtest.py
339 # runs something like test_frozen before test_site, then we will
340 # be testing things loaded *after* test_site did path normalization
Brett Cannon0096e262004-06-05 01:12:51 +0000341
342 def test_no_duplicate_paths(self):
343 # No duplicate paths should exist in sys.path
344 # Handled by removeduppaths()
345 site.removeduppaths()
346 seen_paths = set()
347 for path in sys.path:
Ezio Melottiaa980582010-01-23 23:04:36 +0000348 self.assertNotIn(path, seen_paths)
Brett Cannon0096e262004-06-05 01:12:51 +0000349 seen_paths.add(path)
350
Zachary Ware1f702212013-12-10 14:09:20 -0600351 @unittest.skip('test not implemented')
Brett Cannon0096e262004-06-05 01:12:51 +0000352 def test_add_build_dir(self):
353 # Test that the build directory's Modules directory is used when it
354 # should be.
355 # XXX: implement
356 pass
357
Brett Cannon0096e262004-06-05 01:12:51 +0000358 def test_setting_quit(self):
359 # 'quit' and 'exit' should be injected into __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000360 self.assertTrue(hasattr(__builtin__, "quit"))
361 self.assertTrue(hasattr(__builtin__, "exit"))
Brett Cannon0096e262004-06-05 01:12:51 +0000362
363 def test_setting_copyright(self):
364 # 'copyright' and 'credits' should be in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000365 self.assertTrue(hasattr(__builtin__, "copyright"))
366 self.assertTrue(hasattr(__builtin__, "credits"))
Brett Cannon0096e262004-06-05 01:12:51 +0000367
368 def test_setting_help(self):
369 # 'help' should be set in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000370 self.assertTrue(hasattr(__builtin__, "help"))
Brett Cannon0096e262004-06-05 01:12:51 +0000371
372 def test_aliasing_mbcs(self):
373 if sys.platform == "win32":
374 import locale
375 if locale.getdefaultlocale()[1].startswith('cp'):
376 for value in encodings.aliases.aliases.itervalues():
377 if value == "mbcs":
378 break
379 else:
380 self.fail("did not alias mbcs")
381
382 def test_setdefaultencoding_removed(self):
383 # Make sure sys.setdefaultencoding is gone
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000384 self.assertTrue(not hasattr(sys, "setdefaultencoding"))
Brett Cannon0096e262004-06-05 01:12:51 +0000385
386 def test_sitecustomize_executed(self):
387 # If sitecustomize is available, it should have been imported.
Ezio Melottidde5b942010-02-03 05:37:26 +0000388 if "sitecustomize" not in sys.modules:
Brett Cannon0096e262004-06-05 01:12:51 +0000389 try:
390 import sitecustomize
391 except ImportError:
392 pass
393 else:
394 self.fail("sitecustomize not imported automatically")
395
Brett Cannon0096e262004-06-05 01:12:51 +0000396def test_main():
397 run_unittest(HelperFunctionsTests, ImportSideEffectTests)
398
Brett Cannon0096e262004-06-05 01:12:51 +0000399if __name__ == "__main__":
400 test_main()