blob: 9569135c2ca2f654a1d1973511a84bacce32936b [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__
Victor Stinnere81e3552017-05-04 18:52:26 +020011import errno
Brett Cannon0096e262004-06-05 01:12:51 +000012import os
13import sys
R. David Murray82f58462010-12-27 00:09:41 +000014import re
Brett Cannon0096e262004-06-05 01:12:51 +000015import encodings
Christian Heimesaf748c32008-05-06 22:41:46 +000016import subprocess
Tarek Ziadé5633a802010-01-23 09:23:15 +000017import sysconfig
18from copy import copy
19
Brett Cannon0096e262004-06-05 01:12:51 +000020# Need to make sure to not import 'site' if someone specified ``-S`` at the
21# command-line. Detect this by just making sure 'site' has not been imported
22# already.
23if "site" in sys.modules:
24 import site
25else:
Benjamin Petersonbec087f2009-03-26 21:10:30 +000026 raise unittest.SkipTest("importation of site.py suppressed")
Brett Cannon0096e262004-06-05 01:12:51 +000027
Victor Stinner78064382017-05-04 18:21:52 +020028
29OLD_SYS_PATH = None
30
31
32def setUpModule():
33 global OLD_SYS_PATH
34 OLD_SYS_PATH = sys.path[:]
35
36 if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
37 # need to add user site directory for tests
38 try:
39 os.makedirs(site.USER_SITE)
40 # modify sys.path: will be restored by tearDownModule()
41 site.addsitedir(site.USER_SITE)
Victor Stinnere81e3552017-05-04 18:52:26 +020042 except OSError as exc:
43 if exc.errno in (errno.EACCES, errno.EPERM):
44 raise unittest.SkipTest('unable to create user site directory (%r): %s'
45 % (site.USER_SITE, exc))
46 else:
47 raise
Victor Stinner78064382017-05-04 18:21:52 +020048
49
50def tearDownModule():
51 sys.path[:] = OLD_SYS_PATH
Victor Stinnerec8d6c22016-03-14 17:49:46 +010052
Christian Heimesaf748c32008-05-06 22:41:46 +000053
Brett Cannon0096e262004-06-05 01:12:51 +000054class HelperFunctionsTests(unittest.TestCase):
55 """Tests for helper functions.
Raymond Hettingerebd95222004-06-27 03:02:18 +000056
Brett Cannon0096e262004-06-05 01:12:51 +000057 The setting of the encoding (set using sys.setdefaultencoding) used by
58 the Unicode implementation is not tested.
Raymond Hettingerebd95222004-06-27 03:02:18 +000059
Brett Cannon0096e262004-06-05 01:12:51 +000060 """
61
62 def setUp(self):
63 """Save a copy of sys.path"""
64 self.sys_path = sys.path[:]
Tarek Ziadé764fc232009-08-20 21:23:13 +000065 self.old_base = site.USER_BASE
66 self.old_site = site.USER_SITE
67 self.old_prefixes = site.PREFIXES
Tarek Ziadé5633a802010-01-23 09:23:15 +000068 self.old_vars = copy(sysconfig._CONFIG_VARS)
Brett Cannon0096e262004-06-05 01:12:51 +000069
Neal Norwitz40388cc2008-05-14 06:47:56 +000070 def tearDown(self):
Brett Cannon0096e262004-06-05 01:12:51 +000071 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +000072 sys.path[:] = self.sys_path
Tarek Ziadé764fc232009-08-20 21:23:13 +000073 site.USER_BASE = self.old_base
74 site.USER_SITE = self.old_site
75 site.PREFIXES = self.old_prefixes
Tarek Ziadé5633a802010-01-23 09:23:15 +000076 sysconfig._CONFIG_VARS = self.old_vars
Raymond Hettingerebd95222004-06-27 03:02:18 +000077
Brett Cannon0096e262004-06-05 01:12:51 +000078 def test_makepath(self):
79 # Test makepath() have an absolute path for its first return value
80 # and a case-normalized version of the absolute path for its
81 # second value.
82 path_parts = ("Beginning", "End")
83 original_dir = os.path.join(*path_parts)
84 abs_dir, norm_dir = site.makepath(*path_parts)
Benjamin Peterson5c8da862009-06-30 22:57:08 +000085 self.assertEqual(os.path.abspath(original_dir), abs_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000086 if original_dir == os.path.normcase(original_dir):
Benjamin Peterson5c8da862009-06-30 22:57:08 +000087 self.assertEqual(abs_dir, norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000088 else:
Benjamin Peterson5c8da862009-06-30 22:57:08 +000089 self.assertEqual(os.path.normcase(abs_dir), norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000090
91 def test_init_pathinfo(self):
92 dir_set = site._init_pathinfo()
93 for entry in [site.makepath(path)[1] for path in sys.path
94 if path and os.path.isdir(path)]:
Ezio Melottiaa980582010-01-23 23:04:36 +000095 self.assertIn(entry, dir_set,
96 "%s from sys.path not found in set returned "
97 "by _init_pathinfo(): %s" % (entry, dir_set))
Raymond Hettingerebd95222004-06-27 03:02:18 +000098
Brett Cannonee86a662004-07-13 07:12:25 +000099 def pth_file_tests(self, pth_file):
100 """Contain common code for testing results of reading a .pth file"""
Ezio Melottiaa980582010-01-23 23:04:36 +0000101 self.assertIn(pth_file.imported, sys.modules,
102 "%s not in sys.modules" % pth_file.imported)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000103 self.assertIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
104 self.assertFalse(os.path.exists(pth_file.bad_dir_path))
Brett Cannonee86a662004-07-13 07:12:25 +0000105
Brett Cannon0096e262004-06-05 01:12:51 +0000106 def test_addpackage(self):
107 # Make sure addpackage() imports if the line starts with 'import',
Brett Cannon64a84702004-07-10 02:10:45 +0000108 # adds directories to sys.path for any line in the file that is not a
109 # comment or import that is a valid directory name for where the .pth
110 # file resides; invalid directories are not added
111 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000112 pth_file.cleanup(prep=True) # to make sure that nothing is
113 # pre-existing that shouldn't be
Brett Cannon0096e262004-06-05 01:12:51 +0000114 try:
Brett Cannon64a84702004-07-10 02:10:45 +0000115 pth_file.create()
116 site.addpackage(pth_file.base_dir, pth_file.filename, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000117 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000118 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000119 pth_file.cleanup()
Raymond Hettingerebd95222004-06-27 03:02:18 +0000120
R. David Murray5874ed62010-12-26 22:29:53 +0000121 def make_pth(self, contents, pth_dir='.', pth_name=TESTFN):
122 # Create a .pth file and return its (abspath, basename).
123 pth_dir = os.path.abspath(pth_dir)
124 pth_basename = pth_name + '.pth'
125 pth_fn = os.path.join(pth_dir, pth_basename)
126 pth_file = open(pth_fn, 'w')
127 self.addCleanup(lambda: os.remove(pth_fn))
128 pth_file.write(contents)
129 pth_file.close()
130 return pth_dir, pth_basename
131
132 def test_addpackage_import_bad_syntax(self):
133 # Issue 10642
134 pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
135 with captured_output("stderr") as err_out:
136 site.addpackage(pth_dir, pth_fn, set())
137 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000138 self.assertRegexpMatches(err_out.getvalue(),
139 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000140 # XXX: the previous two should be independent checks so that the
141 # order doesn't matter. The next three could be a single check
142 # but my regex foo isn't good enough to write it.
143 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
144 self.assertRegexpMatches(err_out.getvalue(), r'import bad\)syntax')
145 self.assertRegexpMatches(err_out.getvalue(), 'SyntaxError')
146
147 def test_addpackage_import_bad_exec(self):
148 # Issue 10642
149 pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
150 with captured_output("stderr") as err_out:
151 site.addpackage(pth_dir, pth_fn, set())
152 self.assertRegexpMatches(err_out.getvalue(), "line 2")
R. David Murray82f58462010-12-27 00:09:41 +0000153 self.assertRegexpMatches(err_out.getvalue(),
154 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000155 # XXX: ditto previous XXX comment.
156 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
157 self.assertRegexpMatches(err_out.getvalue(), 'ImportError')
158
R. David Murray49ee82c2010-12-27 04:37:25 +0000159 @unittest.skipIf(sys.platform == "win32", "Windows does not raise an "
160 "error for file paths containing null characters")
R. David Murray5874ed62010-12-26 22:29:53 +0000161 def test_addpackage_import_bad_pth_file(self):
162 # Issue 5258
163 pth_dir, pth_fn = self.make_pth("abc\x00def\n")
164 with captured_output("stderr") as err_out:
165 site.addpackage(pth_dir, pth_fn, set())
166 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000167 self.assertRegexpMatches(err_out.getvalue(),
168 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000169 # XXX: ditto previous XXX comment.
170 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
171 self.assertRegexpMatches(err_out.getvalue(), 'TypeError')
172
Brett Cannon0096e262004-06-05 01:12:51 +0000173 def test_addsitedir(self):
Brett Cannon64a84702004-07-10 02:10:45 +0000174 # Same tests for test_addpackage since addsitedir() essentially just
175 # calls addpackage() for every .pth file in the directory
176 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000177 pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
178 # that is tested for
Brett Cannon0096e262004-06-05 01:12:51 +0000179 try:
Brett Cannonee86a662004-07-13 07:12:25 +0000180 pth_file.create()
Brett Cannon64a84702004-07-10 02:10:45 +0000181 site.addsitedir(pth_file.base_dir, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000182 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000183 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000184 pth_file.cleanup()
Brett Cannon0096e262004-06-05 01:12:51 +0000185
Ned Deily1aacd7b2011-10-31 16:14:52 -0700186 @unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
187 "user-site (site.ENABLE_USER_SITE)")
Christian Heimesaf748c32008-05-06 22:41:46 +0000188 def test_s_option(self):
189 usersite = site.USER_SITE
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000190 self.assertIn(usersite, sys.path)
Christian Heimesaf748c32008-05-06 22:41:46 +0000191
Éric Araujo513c4f82011-01-03 17:57:29 +0000192 env = os.environ.copy()
Christian Heimesaf748c32008-05-06 22:41:46 +0000193 rc = subprocess.call([sys.executable, '-c',
Éric Araujo513c4f82011-01-03 17:57:29 +0000194 'import sys; sys.exit(%r in sys.path)' % usersite],
195 env=env)
Brett Cannonb7019d82009-02-24 22:01:02 +0000196 self.assertEqual(rc, 1, "%r is not in sys.path (sys.exit returned %r)"
197 % (usersite, rc))
Christian Heimesaf748c32008-05-06 22:41:46 +0000198
Éric Araujo513c4f82011-01-03 17:57:29 +0000199 env = os.environ.copy()
Christian Heimesaf748c32008-05-06 22:41:46 +0000200 rc = subprocess.call([sys.executable, '-s', '-c',
Éric Araujo513c4f82011-01-03 17:57:29 +0000201 'import sys; sys.exit(%r in sys.path)' % usersite],
202 env=env)
Christian Heimesaf748c32008-05-06 22:41:46 +0000203 self.assertEqual(rc, 0)
204
205 env = os.environ.copy()
206 env["PYTHONNOUSERSITE"] = "1"
207 rc = subprocess.call([sys.executable, '-c',
Amaury Forgeot d'Arc9b69ed92008-06-19 21:17:12 +0000208 'import sys; sys.exit(%r in sys.path)' % usersite],
Christian Heimesaf748c32008-05-06 22:41:46 +0000209 env=env)
210 self.assertEqual(rc, 0)
211
212 env = os.environ.copy()
213 env["PYTHONUSERBASE"] = "/tmp"
214 rc = subprocess.call([sys.executable, '-c',
215 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
216 env=env)
217 self.assertEqual(rc, 1)
218
Tarek Ziadé764fc232009-08-20 21:23:13 +0000219 def test_getuserbase(self):
220 site.USER_BASE = None
221 user_base = site.getuserbase()
222
223 # the call sets site.USER_BASE
Ezio Melotti2623a372010-11-21 13:34:58 +0000224 self.assertEqual(site.USER_BASE, user_base)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000225
226 # let's set PYTHONUSERBASE and see if it uses it
227 site.USER_BASE = None
Tarek Ziadé5633a802010-01-23 09:23:15 +0000228 import sysconfig
229 sysconfig._CONFIG_VARS = None
230
Tarek Ziadé764fc232009-08-20 21:23:13 +0000231 with EnvironmentVarGuard() as environ:
232 environ['PYTHONUSERBASE'] = 'xoxo'
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000233 self.assertTrue(site.getuserbase().startswith('xoxo'),
234 site.getuserbase())
Tarek Ziadé764fc232009-08-20 21:23:13 +0000235
236 def test_getusersitepackages(self):
237 site.USER_SITE = None
238 site.USER_BASE = None
239 user_site = site.getusersitepackages()
240
241 # the call sets USER_BASE *and* USER_SITE
Ezio Melotti2623a372010-11-21 13:34:58 +0000242 self.assertEqual(site.USER_SITE, user_site)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000243 self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000244
245 def test_getsitepackages(self):
246 site.PREFIXES = ['xoxo']
247 dirs = site.getsitepackages()
248
249 if sys.platform in ('os2emx', 'riscos'):
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000250 self.assertEqual(len(dirs), 1)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000251 wanted = os.path.join('xoxo', 'Lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000252 self.assertEqual(dirs[0], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000253 elif os.sep == '/':
Ned Deily32b37342016-12-03 02:14:09 -0500254 # OS X, Linux, FreeBSD, etc
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000255 self.assertEqual(len(dirs), 2)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000256 wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
257 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000258 self.assertEqual(dirs[0], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000259 wanted = os.path.join('xoxo', 'lib', 'site-python')
Ezio Melotti2623a372010-11-21 13:34:58 +0000260 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000261 else:
Ned Deily2c8bf042012-02-06 00:55:50 +0100262 # other platforms
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000263 self.assertEqual(len(dirs), 2)
Ezio Melotti2623a372010-11-21 13:34:58 +0000264 self.assertEqual(dirs[0], 'xoxo')
Tarek Ziadéd24cab82009-10-27 21:20:27 +0000265 wanted = os.path.join('xoxo', 'lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000266 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000267
Brett Cannon64a84702004-07-10 02:10:45 +0000268class PthFile(object):
269 """Helper class for handling testing of .pth files"""
Brett Cannon0096e262004-06-05 01:12:51 +0000270
Brett Cannon64a84702004-07-10 02:10:45 +0000271 def __init__(self, filename_base=TESTFN, imported="time",
272 good_dirname="__testdir__", bad_dirname="__bad"):
273 """Initialize instance variables"""
274 self.filename = filename_base + ".pth"
275 self.base_dir = os.path.abspath('')
276 self.file_path = os.path.join(self.base_dir, self.filename)
Brett Cannonee86a662004-07-13 07:12:25 +0000277 self.imported = imported
Brett Cannon64a84702004-07-10 02:10:45 +0000278 self.good_dirname = good_dirname
279 self.bad_dirname = bad_dirname
280 self.good_dir_path = os.path.join(self.base_dir, self.good_dirname)
281 self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname)
Brett Cannon0096e262004-06-05 01:12:51 +0000282
Brett Cannon64a84702004-07-10 02:10:45 +0000283 def create(self):
284 """Create a .pth file with a comment, blank lines, an ``import
285 <self.imported>``, a line with self.good_dirname, and a line with
286 self.bad_dirname.
Tim Peters182b5ac2004-07-18 06:16:08 +0000287
Brett Cannon64a84702004-07-10 02:10:45 +0000288 Creation of the directory for self.good_dir_path (based off of
289 self.good_dirname) is also performed.
Brett Cannon0096e262004-06-05 01:12:51 +0000290
Brett Cannon64a84702004-07-10 02:10:45 +0000291 Make sure to call self.cleanup() to undo anything done by this method.
Tim Peters182b5ac2004-07-18 06:16:08 +0000292
Brett Cannon64a84702004-07-10 02:10:45 +0000293 """
Michael W. Hudsonff522862005-05-27 14:58:06 +0000294 FILE = open(self.file_path, 'w')
Brett Cannon64a84702004-07-10 02:10:45 +0000295 try:
296 print>>FILE, "#import @bad module name"
297 print>>FILE, "\n"
298 print>>FILE, "import %s" % self.imported
299 print>>FILE, self.good_dirname
300 print>>FILE, self.bad_dirname
301 finally:
302 FILE.close()
303 os.mkdir(self.good_dir_path)
304
Brett Cannonee86a662004-07-13 07:12:25 +0000305 def cleanup(self, prep=False):
Brett Cannon64a84702004-07-10 02:10:45 +0000306 """Make sure that the .pth file is deleted, self.imported is not in
307 sys.modules, and that both self.good_dirname and self.bad_dirname are
308 not existing directories."""
Brett Cannonee86a662004-07-13 07:12:25 +0000309 if os.path.exists(self.file_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000310 os.remove(self.file_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000311 if prep:
312 self.imported_module = sys.modules.get(self.imported)
313 if self.imported_module:
314 del sys.modules[self.imported]
315 else:
316 if self.imported_module:
317 sys.modules[self.imported] = self.imported_module
318 if os.path.exists(self.good_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000319 os.rmdir(self.good_dir_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000320 if os.path.exists(self.bad_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000321 os.rmdir(self.bad_dir_path)
Brett Cannon0096e262004-06-05 01:12:51 +0000322
323class ImportSideEffectTests(unittest.TestCase):
324 """Test side-effects from importing 'site'."""
325
326 def setUp(self):
327 """Make a copy of sys.path"""
328 self.sys_path = sys.path[:]
329
330 def tearDown(self):
331 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +0000332 sys.path[:] = self.sys_path
Brett Cannon0096e262004-06-05 01:12:51 +0000333
334 def test_abs__file__(self):
335 # Make sure all imported modules have their __file__ attribute
336 # as an absolute path.
337 # Handled by abs__file__()
338 site.abs__file__()
Raymond Hettingerebd95222004-06-27 03:02:18 +0000339 for module in (sys, os, __builtin__):
Brett Cannon0096e262004-06-05 01:12:51 +0000340 try:
Ezio Melottidde5b942010-02-03 05:37:26 +0000341 self.assertTrue(os.path.isabs(module.__file__), repr(module))
Brett Cannon0096e262004-06-05 01:12:51 +0000342 except AttributeError:
343 continue
Raymond Hettingerebd95222004-06-27 03:02:18 +0000344 # We could try everything in sys.modules; however, when regrtest.py
345 # runs something like test_frozen before test_site, then we will
346 # be testing things loaded *after* test_site did path normalization
Brett Cannon0096e262004-06-05 01:12:51 +0000347
348 def test_no_duplicate_paths(self):
349 # No duplicate paths should exist in sys.path
350 # Handled by removeduppaths()
351 site.removeduppaths()
352 seen_paths = set()
353 for path in sys.path:
Ezio Melottiaa980582010-01-23 23:04:36 +0000354 self.assertNotIn(path, seen_paths)
Brett Cannon0096e262004-06-05 01:12:51 +0000355 seen_paths.add(path)
356
Zachary Ware1f702212013-12-10 14:09:20 -0600357 @unittest.skip('test not implemented')
Brett Cannon0096e262004-06-05 01:12:51 +0000358 def test_add_build_dir(self):
359 # Test that the build directory's Modules directory is used when it
360 # should be.
361 # XXX: implement
362 pass
363
Brett Cannon0096e262004-06-05 01:12:51 +0000364 def test_setting_quit(self):
365 # 'quit' and 'exit' should be injected into __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000366 self.assertTrue(hasattr(__builtin__, "quit"))
367 self.assertTrue(hasattr(__builtin__, "exit"))
Brett Cannon0096e262004-06-05 01:12:51 +0000368
369 def test_setting_copyright(self):
370 # 'copyright' and 'credits' should be in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000371 self.assertTrue(hasattr(__builtin__, "copyright"))
372 self.assertTrue(hasattr(__builtin__, "credits"))
Brett Cannon0096e262004-06-05 01:12:51 +0000373
374 def test_setting_help(self):
375 # 'help' should be set in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000376 self.assertTrue(hasattr(__builtin__, "help"))
Brett Cannon0096e262004-06-05 01:12:51 +0000377
378 def test_aliasing_mbcs(self):
379 if sys.platform == "win32":
380 import locale
381 if locale.getdefaultlocale()[1].startswith('cp'):
382 for value in encodings.aliases.aliases.itervalues():
383 if value == "mbcs":
384 break
385 else:
386 self.fail("did not alias mbcs")
387
388 def test_setdefaultencoding_removed(self):
389 # Make sure sys.setdefaultencoding is gone
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000390 self.assertTrue(not hasattr(sys, "setdefaultencoding"))
Brett Cannon0096e262004-06-05 01:12:51 +0000391
392 def test_sitecustomize_executed(self):
393 # If sitecustomize is available, it should have been imported.
Ezio Melottidde5b942010-02-03 05:37:26 +0000394 if "sitecustomize" not in sys.modules:
Brett Cannon0096e262004-06-05 01:12:51 +0000395 try:
396 import sitecustomize
397 except ImportError:
398 pass
399 else:
400 self.fail("sitecustomize not imported automatically")
401
Brett Cannon0096e262004-06-05 01:12:51 +0000402def test_main():
403 run_unittest(HelperFunctionsTests, ImportSideEffectTests)
404
Brett Cannon0096e262004-06-05 01:12:51 +0000405if __name__ == "__main__":
406 test_main()