blob: 69349e185708dd733e2bfd36b181542257db5ad1 [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
Christian Heimesaf748c32008-05-06 22:41: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.
Raymond Hettingerebd95222004-06-27 03:02:18 +000034
Brett Cannon0096e262004-06-05 01:12:51 +000035 The setting of the encoding (set using sys.setdefaultencoding) used by
36 the Unicode implementation is not tested.
Raymond Hettingerebd95222004-06-27 03:02:18 +000037
Brett Cannon0096e262004-06-05 01:12:51 +000038 """
39
40 def setUp(self):
41 """Save a copy of sys.path"""
42 self.sys_path = sys.path[:]
Tarek Ziadé764fc232009-08-20 21:23:13 +000043 self.old_base = site.USER_BASE
44 self.old_site = site.USER_SITE
45 self.old_prefixes = site.PREFIXES
Tarek Ziadé5633a802010-01-23 09:23:15 +000046 self.old_vars = copy(sysconfig._CONFIG_VARS)
Brett Cannon0096e262004-06-05 01:12:51 +000047
Neal Norwitz40388cc2008-05-14 06:47:56 +000048 def tearDown(self):
Brett Cannon0096e262004-06-05 01:12:51 +000049 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +000050 sys.path[:] = self.sys_path
Tarek Ziadé764fc232009-08-20 21:23:13 +000051 site.USER_BASE = self.old_base
52 site.USER_SITE = self.old_site
53 site.PREFIXES = self.old_prefixes
Tarek Ziadé5633a802010-01-23 09:23:15 +000054 sysconfig._CONFIG_VARS = self.old_vars
Raymond Hettingerebd95222004-06-27 03:02:18 +000055
Brett Cannon0096e262004-06-05 01:12:51 +000056 def test_makepath(self):
57 # Test makepath() have an absolute path for its first return value
58 # and a case-normalized version of the absolute path for its
59 # second value.
60 path_parts = ("Beginning", "End")
61 original_dir = os.path.join(*path_parts)
62 abs_dir, norm_dir = site.makepath(*path_parts)
Benjamin Peterson5c8da862009-06-30 22:57:08 +000063 self.assertEqual(os.path.abspath(original_dir), abs_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000064 if original_dir == os.path.normcase(original_dir):
Benjamin Peterson5c8da862009-06-30 22:57:08 +000065 self.assertEqual(abs_dir, norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000066 else:
Benjamin Peterson5c8da862009-06-30 22:57:08 +000067 self.assertEqual(os.path.normcase(abs_dir), norm_dir)
Brett Cannon0096e262004-06-05 01:12:51 +000068
69 def test_init_pathinfo(self):
70 dir_set = site._init_pathinfo()
71 for entry in [site.makepath(path)[1] for path in sys.path
72 if path and os.path.isdir(path)]:
Ezio Melottiaa980582010-01-23 23:04:36 +000073 self.assertIn(entry, dir_set,
74 "%s from sys.path not found in set returned "
75 "by _init_pathinfo(): %s" % (entry, dir_set))
Raymond Hettingerebd95222004-06-27 03:02:18 +000076
Brett Cannonee86a662004-07-13 07:12:25 +000077 def pth_file_tests(self, pth_file):
78 """Contain common code for testing results of reading a .pth file"""
Ezio Melottiaa980582010-01-23 23:04:36 +000079 self.assertIn(pth_file.imported, sys.modules,
80 "%s not in sys.modules" % pth_file.imported)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +000081 self.assertIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
82 self.assertFalse(os.path.exists(pth_file.bad_dir_path))
Brett Cannonee86a662004-07-13 07:12:25 +000083
Brett Cannon0096e262004-06-05 01:12:51 +000084 def test_addpackage(self):
85 # Make sure addpackage() imports if the line starts with 'import',
Brett Cannon64a84702004-07-10 02:10:45 +000086 # adds directories to sys.path for any line in the file that is not a
87 # comment or import that is a valid directory name for where the .pth
88 # file resides; invalid directories are not added
89 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +000090 pth_file.cleanup(prep=True) # to make sure that nothing is
91 # pre-existing that shouldn't be
Brett Cannon0096e262004-06-05 01:12:51 +000092 try:
Brett Cannon64a84702004-07-10 02:10:45 +000093 pth_file.create()
94 site.addpackage(pth_file.base_dir, pth_file.filename, set())
Brett Cannonee86a662004-07-13 07:12:25 +000095 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +000096 finally:
Brett Cannon64a84702004-07-10 02:10:45 +000097 pth_file.cleanup()
Raymond Hettingerebd95222004-06-27 03:02:18 +000098
R. David Murray5874ed62010-12-26 22:29:53 +000099 def make_pth(self, contents, pth_dir='.', pth_name=TESTFN):
100 # Create a .pth file and return its (abspath, basename).
101 pth_dir = os.path.abspath(pth_dir)
102 pth_basename = pth_name + '.pth'
103 pth_fn = os.path.join(pth_dir, pth_basename)
104 pth_file = open(pth_fn, 'w')
105 self.addCleanup(lambda: os.remove(pth_fn))
106 pth_file.write(contents)
107 pth_file.close()
108 return pth_dir, pth_basename
109
110 def test_addpackage_import_bad_syntax(self):
111 # Issue 10642
112 pth_dir, pth_fn = self.make_pth("import bad)syntax\n")
113 with captured_output("stderr") as err_out:
114 site.addpackage(pth_dir, pth_fn, set())
115 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000116 self.assertRegexpMatches(err_out.getvalue(),
117 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000118 # XXX: the previous two should be independent checks so that the
119 # order doesn't matter. The next three could be a single check
120 # but my regex foo isn't good enough to write it.
121 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
122 self.assertRegexpMatches(err_out.getvalue(), r'import bad\)syntax')
123 self.assertRegexpMatches(err_out.getvalue(), 'SyntaxError')
124
125 def test_addpackage_import_bad_exec(self):
126 # Issue 10642
127 pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n")
128 with captured_output("stderr") as err_out:
129 site.addpackage(pth_dir, pth_fn, set())
130 self.assertRegexpMatches(err_out.getvalue(), "line 2")
R. David Murray82f58462010-12-27 00:09:41 +0000131 self.assertRegexpMatches(err_out.getvalue(),
132 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000133 # XXX: ditto previous XXX comment.
134 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
135 self.assertRegexpMatches(err_out.getvalue(), 'ImportError')
136
R. David Murray49ee82c2010-12-27 04:37:25 +0000137 @unittest.skipIf(sys.platform == "win32", "Windows does not raise an "
138 "error for file paths containing null characters")
R. David Murray5874ed62010-12-26 22:29:53 +0000139 def test_addpackage_import_bad_pth_file(self):
140 # Issue 5258
141 pth_dir, pth_fn = self.make_pth("abc\x00def\n")
142 with captured_output("stderr") as err_out:
143 site.addpackage(pth_dir, pth_fn, set())
144 self.assertRegexpMatches(err_out.getvalue(), "line 1")
R. David Murray82f58462010-12-27 00:09:41 +0000145 self.assertRegexpMatches(err_out.getvalue(),
146 re.escape(os.path.join(pth_dir, pth_fn)))
R. David Murray5874ed62010-12-26 22:29:53 +0000147 # XXX: ditto previous XXX comment.
148 self.assertRegexpMatches(err_out.getvalue(), 'Traceback')
149 self.assertRegexpMatches(err_out.getvalue(), 'TypeError')
150
Brett Cannon0096e262004-06-05 01:12:51 +0000151 def test_addsitedir(self):
Brett Cannon64a84702004-07-10 02:10:45 +0000152 # Same tests for test_addpackage since addsitedir() essentially just
153 # calls addpackage() for every .pth file in the directory
154 pth_file = PthFile()
Brett Cannonee86a662004-07-13 07:12:25 +0000155 pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
156 # that is tested for
Brett Cannon0096e262004-06-05 01:12:51 +0000157 try:
Brett Cannonee86a662004-07-13 07:12:25 +0000158 pth_file.create()
Brett Cannon64a84702004-07-10 02:10:45 +0000159 site.addsitedir(pth_file.base_dir, set())
Brett Cannonee86a662004-07-13 07:12:25 +0000160 self.pth_file_tests(pth_file)
Brett Cannon0096e262004-06-05 01:12:51 +0000161 finally:
Brett Cannon64a84702004-07-10 02:10:45 +0000162 pth_file.cleanup()
Brett Cannon0096e262004-06-05 01:12:51 +0000163
Christian Heimesaf748c32008-05-06 22:41:46 +0000164 def test_s_option(self):
165 usersite = site.USER_SITE
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000166 self.assertIn(usersite, sys.path)
Christian Heimesaf748c32008-05-06 22:41:46 +0000167
168 rc = subprocess.call([sys.executable, '-c',
Antoine Pitroub03f5322009-02-22 18:20:46 +0000169 'import sys; sys.exit(%r in sys.path)' % usersite])
Brett Cannonb7019d82009-02-24 22:01:02 +0000170 self.assertEqual(rc, 1, "%r is not in sys.path (sys.exit returned %r)"
171 % (usersite, rc))
Christian Heimesaf748c32008-05-06 22:41:46 +0000172
173 rc = subprocess.call([sys.executable, '-s', '-c',
Amaury Forgeot d'Arc9b69ed92008-06-19 21:17:12 +0000174 'import sys; sys.exit(%r in sys.path)' % usersite])
Christian Heimesaf748c32008-05-06 22:41:46 +0000175 self.assertEqual(rc, 0)
176
177 env = os.environ.copy()
178 env["PYTHONNOUSERSITE"] = "1"
179 rc = subprocess.call([sys.executable, '-c',
Amaury Forgeot d'Arc9b69ed92008-06-19 21:17:12 +0000180 'import sys; sys.exit(%r in sys.path)' % usersite],
Christian Heimesaf748c32008-05-06 22:41:46 +0000181 env=env)
182 self.assertEqual(rc, 0)
183
184 env = os.environ.copy()
185 env["PYTHONUSERBASE"] = "/tmp"
186 rc = subprocess.call([sys.executable, '-c',
187 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
188 env=env)
189 self.assertEqual(rc, 1)
190
Tarek Ziadé764fc232009-08-20 21:23:13 +0000191 def test_getuserbase(self):
192 site.USER_BASE = None
193 user_base = site.getuserbase()
194
195 # the call sets site.USER_BASE
Ezio Melotti2623a372010-11-21 13:34:58 +0000196 self.assertEqual(site.USER_BASE, user_base)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000197
198 # let's set PYTHONUSERBASE and see if it uses it
199 site.USER_BASE = None
Tarek Ziadé5633a802010-01-23 09:23:15 +0000200 import sysconfig
201 sysconfig._CONFIG_VARS = None
202
Tarek Ziadé764fc232009-08-20 21:23:13 +0000203 with EnvironmentVarGuard() as environ:
204 environ['PYTHONUSERBASE'] = 'xoxo'
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000205 self.assertTrue(site.getuserbase().startswith('xoxo'),
206 site.getuserbase())
Tarek Ziadé764fc232009-08-20 21:23:13 +0000207
208 def test_getusersitepackages(self):
209 site.USER_SITE = None
210 site.USER_BASE = None
211 user_site = site.getusersitepackages()
212
213 # the call sets USER_BASE *and* USER_SITE
Ezio Melotti2623a372010-11-21 13:34:58 +0000214 self.assertEqual(site.USER_SITE, user_site)
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000215 self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000216
217 def test_getsitepackages(self):
218 site.PREFIXES = ['xoxo']
219 dirs = site.getsitepackages()
220
221 if sys.platform in ('os2emx', 'riscos'):
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000222 self.assertEqual(len(dirs), 1)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000223 wanted = os.path.join('xoxo', 'Lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000224 self.assertEqual(dirs[0], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000225 elif os.sep == '/':
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000226 self.assertEqual(len(dirs), 2)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000227 wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
228 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000229 self.assertEqual(dirs[0], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000230 wanted = os.path.join('xoxo', 'lib', 'site-python')
Ezio Melotti2623a372010-11-21 13:34:58 +0000231 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000232 else:
Ezio Melottid9ed62c2010-08-17 08:38:05 +0000233 self.assertEqual(len(dirs), 2)
Ezio Melotti2623a372010-11-21 13:34:58 +0000234 self.assertEqual(dirs[0], 'xoxo')
Tarek Ziadéd24cab82009-10-27 21:20:27 +0000235 wanted = os.path.join('xoxo', 'lib', 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000236 self.assertEqual(dirs[1], wanted)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000237
238 # let's try the specific Apple location
Brett Cannonda9af752010-05-13 23:59:41 +0000239 if (sys.platform == "darwin" and
240 sysconfig.get_config_var("PYTHONFRAMEWORK")):
Tarek Ziadé764fc232009-08-20 21:23:13 +0000241 site.PREFIXES = ['Python.framework']
242 dirs = site.getsitepackages()
Antoine Pitroud8b16ab2009-11-01 23:54:20 +0000243 self.assertEqual(len(dirs), 4)
Tarek Ziadé764fc232009-08-20 21:23:13 +0000244 wanted = os.path.join('~', 'Library', 'Python',
245 sys.version[:3], 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000246 self.assertEqual(dirs[2], os.path.expanduser(wanted))
Tarek Ziadé764fc232009-08-20 21:23:13 +0000247 wanted = os.path.join('/Library', 'Python', sys.version[:3],
248 'site-packages')
Ezio Melotti2623a372010-11-21 13:34:58 +0000249 self.assertEqual(dirs[3], wanted)
Christian Heimesaf748c32008-05-06 22:41:46 +0000250
Brett Cannon64a84702004-07-10 02:10:45 +0000251class PthFile(object):
252 """Helper class for handling testing of .pth files"""
Brett Cannon0096e262004-06-05 01:12:51 +0000253
Brett Cannon64a84702004-07-10 02:10:45 +0000254 def __init__(self, filename_base=TESTFN, imported="time",
255 good_dirname="__testdir__", bad_dirname="__bad"):
256 """Initialize instance variables"""
257 self.filename = filename_base + ".pth"
258 self.base_dir = os.path.abspath('')
259 self.file_path = os.path.join(self.base_dir, self.filename)
Brett Cannonee86a662004-07-13 07:12:25 +0000260 self.imported = imported
Brett Cannon64a84702004-07-10 02:10:45 +0000261 self.good_dirname = good_dirname
262 self.bad_dirname = bad_dirname
263 self.good_dir_path = os.path.join(self.base_dir, self.good_dirname)
264 self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname)
Brett Cannon0096e262004-06-05 01:12:51 +0000265
Brett Cannon64a84702004-07-10 02:10:45 +0000266 def create(self):
267 """Create a .pth file with a comment, blank lines, an ``import
268 <self.imported>``, a line with self.good_dirname, and a line with
269 self.bad_dirname.
Tim Peters182b5ac2004-07-18 06:16:08 +0000270
Brett Cannon64a84702004-07-10 02:10:45 +0000271 Creation of the directory for self.good_dir_path (based off of
272 self.good_dirname) is also performed.
Brett Cannon0096e262004-06-05 01:12:51 +0000273
Brett Cannon64a84702004-07-10 02:10:45 +0000274 Make sure to call self.cleanup() to undo anything done by this method.
Tim Peters182b5ac2004-07-18 06:16:08 +0000275
Brett Cannon64a84702004-07-10 02:10:45 +0000276 """
Michael W. Hudsonff522862005-05-27 14:58:06 +0000277 FILE = open(self.file_path, 'w')
Brett Cannon64a84702004-07-10 02:10:45 +0000278 try:
279 print>>FILE, "#import @bad module name"
280 print>>FILE, "\n"
281 print>>FILE, "import %s" % self.imported
282 print>>FILE, self.good_dirname
283 print>>FILE, self.bad_dirname
284 finally:
285 FILE.close()
286 os.mkdir(self.good_dir_path)
287
Brett Cannonee86a662004-07-13 07:12:25 +0000288 def cleanup(self, prep=False):
Brett Cannon64a84702004-07-10 02:10:45 +0000289 """Make sure that the .pth file is deleted, self.imported is not in
290 sys.modules, and that both self.good_dirname and self.bad_dirname are
291 not existing directories."""
Brett Cannonee86a662004-07-13 07:12:25 +0000292 if os.path.exists(self.file_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000293 os.remove(self.file_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000294 if prep:
295 self.imported_module = sys.modules.get(self.imported)
296 if self.imported_module:
297 del sys.modules[self.imported]
298 else:
299 if self.imported_module:
300 sys.modules[self.imported] = self.imported_module
301 if os.path.exists(self.good_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000302 os.rmdir(self.good_dir_path)
Brett Cannonee86a662004-07-13 07:12:25 +0000303 if os.path.exists(self.bad_dir_path):
Brett Cannon64a84702004-07-10 02:10:45 +0000304 os.rmdir(self.bad_dir_path)
Brett Cannon0096e262004-06-05 01:12:51 +0000305
306class ImportSideEffectTests(unittest.TestCase):
307 """Test side-effects from importing 'site'."""
308
309 def setUp(self):
310 """Make a copy of sys.path"""
311 self.sys_path = sys.path[:]
312
313 def tearDown(self):
314 """Restore sys.path"""
Nick Coghlana0e0f9e2009-10-17 16:19:51 +0000315 sys.path[:] = self.sys_path
Brett Cannon0096e262004-06-05 01:12:51 +0000316
317 def test_abs__file__(self):
318 # Make sure all imported modules have their __file__ attribute
319 # as an absolute path.
320 # Handled by abs__file__()
321 site.abs__file__()
Raymond Hettingerebd95222004-06-27 03:02:18 +0000322 for module in (sys, os, __builtin__):
Brett Cannon0096e262004-06-05 01:12:51 +0000323 try:
Ezio Melottidde5b942010-02-03 05:37:26 +0000324 self.assertTrue(os.path.isabs(module.__file__), repr(module))
Brett Cannon0096e262004-06-05 01:12:51 +0000325 except AttributeError:
326 continue
Raymond Hettingerebd95222004-06-27 03:02:18 +0000327 # We could try everything in sys.modules; however, when regrtest.py
328 # runs something like test_frozen before test_site, then we will
329 # be testing things loaded *after* test_site did path normalization
Brett Cannon0096e262004-06-05 01:12:51 +0000330
331 def test_no_duplicate_paths(self):
332 # No duplicate paths should exist in sys.path
333 # Handled by removeduppaths()
334 site.removeduppaths()
335 seen_paths = set()
336 for path in sys.path:
Ezio Melottiaa980582010-01-23 23:04:36 +0000337 self.assertNotIn(path, seen_paths)
Brett Cannon0096e262004-06-05 01:12:51 +0000338 seen_paths.add(path)
339
340 def test_add_build_dir(self):
341 # Test that the build directory's Modules directory is used when it
342 # should be.
343 # XXX: implement
344 pass
345
Brett Cannon0096e262004-06-05 01:12:51 +0000346 def test_setting_quit(self):
347 # 'quit' and 'exit' should be injected into __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000348 self.assertTrue(hasattr(__builtin__, "quit"))
349 self.assertTrue(hasattr(__builtin__, "exit"))
Brett Cannon0096e262004-06-05 01:12:51 +0000350
351 def test_setting_copyright(self):
352 # 'copyright' and 'credits' should be in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000353 self.assertTrue(hasattr(__builtin__, "copyright"))
354 self.assertTrue(hasattr(__builtin__, "credits"))
Brett Cannon0096e262004-06-05 01:12:51 +0000355
356 def test_setting_help(self):
357 # 'help' should be set in __builtin__
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000358 self.assertTrue(hasattr(__builtin__, "help"))
Brett Cannon0096e262004-06-05 01:12:51 +0000359
360 def test_aliasing_mbcs(self):
361 if sys.platform == "win32":
362 import locale
363 if locale.getdefaultlocale()[1].startswith('cp'):
364 for value in encodings.aliases.aliases.itervalues():
365 if value == "mbcs":
366 break
367 else:
368 self.fail("did not alias mbcs")
369
370 def test_setdefaultencoding_removed(self):
371 # Make sure sys.setdefaultencoding is gone
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000372 self.assertTrue(not hasattr(sys, "setdefaultencoding"))
Brett Cannon0096e262004-06-05 01:12:51 +0000373
374 def test_sitecustomize_executed(self):
375 # If sitecustomize is available, it should have been imported.
Ezio Melottidde5b942010-02-03 05:37:26 +0000376 if "sitecustomize" not in sys.modules:
Brett Cannon0096e262004-06-05 01:12:51 +0000377 try:
378 import sitecustomize
379 except ImportError:
380 pass
381 else:
382 self.fail("sitecustomize not imported automatically")
383
Brett Cannon0096e262004-06-05 01:12:51 +0000384def test_main():
385 run_unittest(HelperFunctionsTests, ImportSideEffectTests)
386
Brett Cannon0096e262004-06-05 01:12:51 +0000387if __name__ == "__main__":
388 test_main()