blob: 3ba5dca82269c6c12798aacf308b1e977231a209 [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
Victor Stinner78064382017-05-04 18:21:52 +020027
28OLD_SYS_PATH = None
29
30
31def setUpModule():
32 global OLD_SYS_PATH
33 OLD_SYS_PATH = sys.path[:]
34
35 if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
36 # need to add user site directory for tests
37 try:
38 os.makedirs(site.USER_SITE)
39 # modify sys.path: will be restored by tearDownModule()
40 site.addsitedir(site.USER_SITE)
41 except PermissionError as exc:
42 raise unittest.SkipTest('unable to create user site directory (%r): %s'
43 % (site.USER_SITE, exc))
44
45
46def tearDownModule():
47 sys.path[:] = OLD_SYS_PATH
Victor Stinnerec8d6c22016-03-14 17:49:46 +010048
Christian Heimesaf748c32008-05-06 22:41:46 +000049
Brett Cannon0096e262004-06-05 01:12:51 +000050class HelperFunctionsTests(unittest.TestCase):
51 """Tests for helper functions.
Raymond Hettingerebd95222004-06-27 03:02:18 +000052
Brett Cannon0096e262004-06-05 01:12:51 +000053 The setting of the encoding (set using sys.setdefaultencoding) used by
54 the Unicode implementation is not tested.
Raymond Hettingerebd95222004-06-27 03:02:18 +000055
Brett Cannon0096e262004-06-05 01:12:51 +000056 """
57
58 def setUp(self):
59 """Save a copy of sys.path"""
60 self.sys_path = sys.path[:]
Tarek Ziadé764fc232009-08-20 21:23:13 +000061 self.old_base = site.USER_BASE
62 self.old_site = site.USER_SITE
63 self.old_prefixes = site.PREFIXES
Tarek Ziadé5633a802010-01-23 09:23:15 +000064 self.old_vars = copy(sysconfig._CONFIG_VARS)
Brett Cannon0096e262004-06-05 01:12:51 +000065
Neal Norwitz40388cc2008-05-14 06:47:56 +000066 def tearDown(self):
Brett Cannon0096e262004-06-05 01:12:51 +000067 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +000068 sys.path[:] = self.sys_path
Tarek Ziadé764fc232009-08-20 21:23:13 +000069 site.USER_BASE = self.old_base
70 site.USER_SITE = self.old_site
71 site.PREFIXES = self.old_prefixes
Tarek Ziadé5633a802010-01-23 09:23:15 +000072 sysconfig._CONFIG_VARS = self.old_vars
Raymond Hettingerebd95222004-06-27 03:02:18 +000073
Brett Cannon0096e262004-06-05 01:12:51 +000074 def test_makepath(self):
75 # Test makepath() have an absolute path for its first return value
76 # and a case-normalized version of the absolute path for its
77 # second value.
78 path_parts = ("Beginning", "End")
79 original_dir = os.path.join(*path_parts)
80 abs_dir, norm_dir = site.makepath(*path_parts)
Benjamin Peterson5c8da862009-06-30 22:57:08 +000081 self.assertEqual(os.path.abspath(original_dir), abs_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000082 if original_dir == os.path.normcase(original_dir):
Benjamin Peterson5c8da862009-06-30 22:57:08 +000083 self.assertEqual(abs_dir, norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000084 else:
Benjamin Peterson5c8da862009-06-30 22:57:08 +000085 self.assertEqual(os.path.normcase(abs_dir), norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000086
87 def test_init_pathinfo(self):
88 dir_set = site._init_pathinfo()
89 for entry in [site.makepath(path)[1] for path in sys.path
90 if path and os.path.isdir(path)]:
Ezio Melottiaa980582010-01-23 23:04:36 +000091 self.assertIn(entry, dir_set,
92 "%s from sys.path not found in set returned "
93 "by _init_pathinfo(): %s" % (entry, dir_set))
Raymond Hettingerebd95222004-06-27 03:02:18 +000094
Brett Cannonee86a662004-07-13 07:12:25 +000095 def pth_file_tests(self, pth_file):
96 """Contain common code for testing results of reading a .pth file"""
Ezio Melottiaa980582010-01-23 23:04:36 +000097 self.assertIn(pth_file.imported, sys.modules,
98 "%s not in sys.modules" % pth_file.imported)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +000099 self.assertIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
100 self.assertFalse(os.path.exists(pth_file.bad_dir_path))
Brett Cannonee86a662004-07-13 07:12:25 +0000101
Brett Cannon0096e262004-06-05 01:12:51 +0000102 def test_addpackage(self):
103 # Make sure addpackage() imports if the line starts with 'import',
Brett Cannon64a84702004-07-10 02:10:45 +0000104 # adds directories to sys.path for any line in the file that is not a
105 # comment or import that is a valid directory name for where the .pth
106 # file resides; invalid directories are not added
107 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000108 pth_file.cleanup(prep=True) # to make sure that nothing is
109 # pre-existing that shouldn't be
Brett Cannon0096e262004-06-05 01:12:51 +0000110 try:
Brett Cannon64a84702004-07-10 02:10:45 +0000111 pth_file.create()
112 site.addpackage(pth_file.base_dir, pth_file.filename, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000113 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000114 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000115 pth_file.cleanup()
Raymond Hettingerebd95222004-06-27 03:02:18 +0000116
R. David Murray5874ed62010-12-26 22:29:53 +0000117 def make_pth(self, contents, pth_dir='.', pth_name=TESTFN):
118 # Create a .pth file and return its (abspath, basename).
119 pth_dir = os.path.abspath(pth_dir)
120 pth_basename = pth_name + '.pth'
121 pth_fn = os.path.join(pth_dir, pth_basename)
122 pth_file = open(pth_fn, 'w')
123 self.addCleanup(lambda: os.remove(pth_fn))
124 pth_file.write(contents)
125 pth_file.close()
126 return pth_dir, pth_basename
127
128 def test_addpackage_import_bad_syntax(self):
129 # Issue 10642
130 pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
131 with captured_output("stderr") as err_out:
132 site.addpackage(pth_dir, pth_fn, set())
133 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000134 self.assertRegexpMatches(err_out.getvalue(),
135 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000136 # XXX: the previous two should be independent checks so that the
137 # order doesn't matter. The next three could be a single check
138 # but my regex foo isn't good enough to write it.
139 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
140 self.assertRegexpMatches(err_out.getvalue(), r'import bad\)syntax')
141 self.assertRegexpMatches(err_out.getvalue(), 'SyntaxError')
142
143 def test_addpackage_import_bad_exec(self):
144 # Issue 10642
145 pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
146 with captured_output("stderr") as err_out:
147 site.addpackage(pth_dir, pth_fn, set())
148 self.assertRegexpMatches(err_out.getvalue(), "line 2")
R. David Murray82f58462010-12-27 00:09:41 +0000149 self.assertRegexpMatches(err_out.getvalue(),
150 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000151 # XXX: ditto previous XXX comment.
152 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
153 self.assertRegexpMatches(err_out.getvalue(), 'ImportError')
154
R. David Murray49ee82c2010-12-27 04:37:25 +0000155 @unittest.skipIf(sys.platform == "win32", "Windows does not raise an "
156 "error for file paths containing null characters")
R. David Murray5874ed62010-12-26 22:29:53 +0000157 def test_addpackage_import_bad_pth_file(self):
158 # Issue 5258
159 pth_dir, pth_fn = self.make_pth("abc\x00def\n")
160 with captured_output("stderr") as err_out:
161 site.addpackage(pth_dir, pth_fn, set())
162 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000163 self.assertRegexpMatches(err_out.getvalue(),
164 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000165 # XXX: ditto previous XXX comment.
166 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
167 self.assertRegexpMatches(err_out.getvalue(), 'TypeError')
168
Brett Cannon0096e262004-06-05 01:12:51 +0000169 def test_addsitedir(self):
Brett Cannon64a84702004-07-10 02:10:45 +0000170 # Same tests for test_addpackage since addsitedir() essentially just
171 # calls addpackage() for every .pth file in the directory
172 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000173 pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
174 # that is tested for
Brett Cannon0096e262004-06-05 01:12:51 +0000175 try:
Brett Cannonee86a662004-07-13 07:12:25 +0000176 pth_file.create()
Brett Cannon64a84702004-07-10 02:10:45 +0000177 site.addsitedir(pth_file.base_dir, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000178 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000179 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000180 pth_file.cleanup()
Brett Cannon0096e262004-06-05 01:12:51 +0000181
Ned Deily1aacd7b2011-10-31 16:14:52 -0700182 @unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
183 "user-site (site.ENABLE_USER_SITE)")
Christian Heimesaf748c32008-05-06 22:41:46 +0000184 def test_s_option(self):
185 usersite = site.USER_SITE
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000186 self.assertIn(usersite, sys.path)
Christian Heimesaf748c32008-05-06 22:41:46 +0000187
Éric Araujo513c4f82011-01-03 17:57:29 +0000188 env = os.environ.copy()
Christian Heimesaf748c32008-05-06 22:41:46 +0000189 rc = subprocess.call([sys.executable, '-c',
Éric Araujo513c4f82011-01-03 17:57:29 +0000190 'import sys; sys.exit(%r in sys.path)' % usersite],
191 env=env)
Brett Cannonb7019d82009-02-24 22:01:02 +0000192 self.assertEqual(rc, 1, "%r is not in sys.path (sys.exit returned %r)"
193 % (usersite, rc))
Christian Heimesaf748c32008-05-06 22:41:46 +0000194
Éric Araujo513c4f82011-01-03 17:57:29 +0000195 env = os.environ.copy()
Christian Heimesaf748c32008-05-06 22:41:46 +0000196 rc = subprocess.call([sys.executable, '-s', '-c',
Éric Araujo513c4f82011-01-03 17:57:29 +0000197 'import sys; sys.exit(%r in sys.path)' % usersite],
198 env=env)
Christian Heimesaf748c32008-05-06 22:41:46 +0000199 self.assertEqual(rc, 0)
200
201 env = os.environ.copy()
202 env["PYTHONNOUSERSITE"] = "1"
203 rc = subprocess.call([sys.executable, '-c',
Amaury Forgeot d'Arc9b69ed92008-06-19 21:17:12 +0000204 'import sys; sys.exit(%r in sys.path)' % usersite],
Christian Heimesaf748c32008-05-06 22:41:46 +0000205 env=env)
206 self.assertEqual(rc, 0)
207
208 env = os.environ.copy()
209 env["PYTHONUSERBASE"] = "/tmp"
210 rc = subprocess.call([sys.executable, '-c',
211 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
212 env=env)
213 self.assertEqual(rc, 1)
214
Tarek Ziadé764fc232009-08-20 21:23:13 +0000215 def test_getuserbase(self):
216 site.USER_BASE = None
217 user_base = site.getuserbase()
218
219 # the call sets site.USER_BASE
Ezio Melotti2623a372010-11-21 13:34:58 +0000220 self.assertEqual(site.USER_BASE, user_base)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000221
222 # let's set PYTHONUSERBASE and see if it uses it
223 site.USER_BASE = None
Tarek Ziadé5633a802010-01-23 09:23:15 +0000224 import sysconfig
225 sysconfig._CONFIG_VARS = None
226
Tarek Ziadé764fc232009-08-20 21:23:13 +0000227 with EnvironmentVarGuard() as environ:
228 environ['PYTHONUSERBASE'] = 'xoxo'
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000229 self.assertTrue(site.getuserbase().startswith('xoxo'),
230 site.getuserbase())
Tarek Ziadé764fc232009-08-20 21:23:13 +0000231
232 def test_getusersitepackages(self):
233 site.USER_SITE = None
234 site.USER_BASE = None
235 user_site = site.getusersitepackages()
236
237 # the call sets USER_BASE *and* USER_SITE
Ezio Melotti2623a372010-11-21 13:34:58 +0000238 self.assertEqual(site.USER_SITE, user_site)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000239 self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000240
241 def test_getsitepackages(self):
242 site.PREFIXES = ['xoxo']
243 dirs = site.getsitepackages()
244
245 if sys.platform in ('os2emx', 'riscos'):
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000246 self.assertEqual(len(dirs), 1)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000247 wanted = os.path.join('xoxo', 'Lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000248 self.assertEqual(dirs[0], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000249 elif os.sep == '/':
Ned Deily32b37342016-12-03 02:14:09 -0500250 # OS X, Linux, FreeBSD, etc
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000251 self.assertEqual(len(dirs), 2)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000252 wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
253 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000254 self.assertEqual(dirs[0], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000255 wanted = os.path.join('xoxo', 'lib', 'site-python')
Ezio Melotti2623a372010-11-21 13:34:58 +0000256 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000257 else:
Ned Deily2c8bf042012-02-06 00:55:50 +0100258 # other platforms
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000259 self.assertEqual(len(dirs), 2)
Ezio Melotti2623a372010-11-21 13:34:58 +0000260 self.assertEqual(dirs[0], 'xoxo')
Tarek Ziadéd24cab82009-10-27 21:20:27 +0000261 wanted = os.path.join('xoxo', 'lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000262 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000263
Brett Cannon64a84702004-07-10 02:10:45 +0000264class PthFile(object):
265 """Helper class for handling testing of .pth files"""
Brett Cannon0096e262004-06-05 01:12:51 +0000266
Brett Cannon64a84702004-07-10 02:10:45 +0000267 def __init__(self, filename_base=TESTFN, imported="time",
268 good_dirname="__testdir__", bad_dirname="__bad"):
269 """Initialize instance variables"""
270 self.filename = filename_base + ".pth"
271 self.base_dir = os.path.abspath('')
272 self.file_path = os.path.join(self.base_dir, self.filename)
Brett Cannonee86a662004-07-13 07:12:25 +0000273 self.imported = imported
Brett Cannon64a84702004-07-10 02:10:45 +0000274 self.good_dirname = good_dirname
275 self.bad_dirname = bad_dirname
276 self.good_dir_path = os.path.join(self.base_dir, self.good_dirname)
277 self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname)
Brett Cannon0096e262004-06-05 01:12:51 +0000278
Brett Cannon64a84702004-07-10 02:10:45 +0000279 def create(self):
280 """Create a .pth file with a comment, blank lines, an ``import
281 <self.imported>``, a line with self.good_dirname, and a line with
282 self.bad_dirname.
Tim Peters182b5ac2004-07-18 06:16:08 +0000283
Brett Cannon64a84702004-07-10 02:10:45 +0000284 Creation of the directory for self.good_dir_path (based off of
285 self.good_dirname) is also performed.
Brett Cannon0096e262004-06-05 01:12:51 +0000286
Brett Cannon64a84702004-07-10 02:10:45 +0000287 Make sure to call self.cleanup() to undo anything done by this method.
Tim Peters182b5ac2004-07-18 06:16:08 +0000288
Brett Cannon64a84702004-07-10 02:10:45 +0000289 """
Michael W. Hudsonff522862005-05-27 14:58:06 +0000290 FILE = open(self.file_path, 'w')
Brett Cannon64a84702004-07-10 02:10:45 +0000291 try:
292 print>>FILE, "#import @bad module name"
293 print>>FILE, "\n"
294 print>>FILE, "import %s" % self.imported
295 print>>FILE, self.good_dirname
296 print>>FILE, self.bad_dirname
297 finally:
298 FILE.close()
299 os.mkdir(self.good_dir_path)
300
Brett Cannonee86a662004-07-13 07:12:25 +0000301 def cleanup(self, prep=False):
Brett Cannon64a84702004-07-10 02:10:45 +0000302 """Make sure that the .pth file is deleted, self.imported is not in
303 sys.modules, and that both self.good_dirname and self.bad_dirname are
304 not existing directories."""
Brett Cannonee86a662004-07-13 07:12:25 +0000305 if os.path.exists(self.file_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000306 os.remove(self.file_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000307 if prep:
308 self.imported_module = sys.modules.get(self.imported)
309 if self.imported_module:
310 del sys.modules[self.imported]
311 else:
312 if self.imported_module:
313 sys.modules[self.imported] = self.imported_module
314 if os.path.exists(self.good_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000315 os.rmdir(self.good_dir_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000316 if os.path.exists(self.bad_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000317 os.rmdir(self.bad_dir_path)
Brett Cannon0096e262004-06-05 01:12:51 +0000318
319class ImportSideEffectTests(unittest.TestCase):
320 """Test side-effects from importing 'site'."""
321
322 def setUp(self):
323 """Make a copy of sys.path"""
324 self.sys_path = sys.path[:]
325
326 def tearDown(self):
327 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +0000328 sys.path[:] = self.sys_path
Brett Cannon0096e262004-06-05 01:12:51 +0000329
330 def test_abs__file__(self):
331 # Make sure all imported modules have their __file__ attribute
332 # as an absolute path.
333 # Handled by abs__file__()
334 site.abs__file__()
Raymond Hettingerebd95222004-06-27 03:02:18 +0000335 for module in (sys, os, __builtin__):
Brett Cannon0096e262004-06-05 01:12:51 +0000336 try:
Ezio Melottidde5b942010-02-03 05:37:26 +0000337 self.assertTrue(os.path.isabs(module.__file__), repr(module))
Brett Cannon0096e262004-06-05 01:12:51 +0000338 except AttributeError:
339 continue
Raymond Hettingerebd95222004-06-27 03:02:18 +0000340 # We could try everything in sys.modules; however, when regrtest.py
341 # runs something like test_frozen before test_site, then we will
342 # be testing things loaded *after* test_site did path normalization
Brett Cannon0096e262004-06-05 01:12:51 +0000343
344 def test_no_duplicate_paths(self):
345 # No duplicate paths should exist in sys.path
346 # Handled by removeduppaths()
347 site.removeduppaths()
348 seen_paths = set()
349 for path in sys.path:
Ezio Melottiaa980582010-01-23 23:04:36 +0000350 self.assertNotIn(path, seen_paths)
Brett Cannon0096e262004-06-05 01:12:51 +0000351 seen_paths.add(path)
352
Zachary Ware1f702212013-12-10 14:09:20 -0600353 @unittest.skip('test not implemented')
Brett Cannon0096e262004-06-05 01:12:51 +0000354 def test_add_build_dir(self):
355 # Test that the build directory's Modules directory is used when it
356 # should be.
357 # XXX: implement
358 pass
359
Brett Cannon0096e262004-06-05 01:12:51 +0000360 def test_setting_quit(self):
361 # 'quit' and 'exit' should be injected into __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000362 self.assertTrue(hasattr(__builtin__, "quit"))
363 self.assertTrue(hasattr(__builtin__, "exit"))
Brett Cannon0096e262004-06-05 01:12:51 +0000364
365 def test_setting_copyright(self):
366 # 'copyright' and 'credits' should be in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000367 self.assertTrue(hasattr(__builtin__, "copyright"))
368 self.assertTrue(hasattr(__builtin__, "credits"))
Brett Cannon0096e262004-06-05 01:12:51 +0000369
370 def test_setting_help(self):
371 # 'help' should be set in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000372 self.assertTrue(hasattr(__builtin__, "help"))
Brett Cannon0096e262004-06-05 01:12:51 +0000373
374 def test_aliasing_mbcs(self):
375 if sys.platform == "win32":
376 import locale
377 if locale.getdefaultlocale()[1].startswith('cp'):
378 for value in encodings.aliases.aliases.itervalues():
379 if value == "mbcs":
380 break
381 else:
382 self.fail("did not alias mbcs")
383
384 def test_setdefaultencoding_removed(self):
385 # Make sure sys.setdefaultencoding is gone
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000386 self.assertTrue(not hasattr(sys, "setdefaultencoding"))
Brett Cannon0096e262004-06-05 01:12:51 +0000387
388 def test_sitecustomize_executed(self):
389 # If sitecustomize is available, it should have been imported.
Ezio Melottidde5b942010-02-03 05:37:26 +0000390 if "sitecustomize" not in sys.modules:
Brett Cannon0096e262004-06-05 01:12:51 +0000391 try:
392 import sitecustomize
393 except ImportError:
394 pass
395 else:
396 self.fail("sitecustomize not imported automatically")
397
Brett Cannon0096e262004-06-05 01:12:51 +0000398def test_main():
399 run_unittest(HelperFunctionsTests, ImportSideEffectTests)
400
Brett Cannon0096e262004-06-05 01:12:51 +0000401if __name__ == "__main__":
402 test_main()