Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_site.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | abdc1764d8e5 |
| children | 6768b2350c57 |
| rev | line source |
|---|---|
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
1 """Tests for 'site'. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
3 Tests assume the initial paths in sys.path once the interpreter has begun |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
4 executing have not been removed. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
5 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
6 """ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
7 import unittest |
|
53484
abdc1764d8e5
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Walter Dörwald <walter@livinglogic.de>
parents:
52355
diff
changeset
|
8 from test.test_support import run_unittest, TESTFN, EnvironmentVarGuard |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
9 import __builtin__ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
10 import os |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
11 import sys |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
12 import encodings |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
13 import subprocess |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
14 # Need to make sure to not import 'site' if someone specified ``-S`` at the |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
15 # command-line. Detect this by just making sure 'site' has not been imported |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
16 # already. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
17 if "site" in sys.modules: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
18 import site |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
19 else: |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
20 raise unittest.SkipTest("importation of site.py suppressed") |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
21 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
22 if not os.path.isdir(site.USER_SITE): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
23 # need to add user site directory for tests |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
24 os.makedirs(site.USER_SITE) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
25 site.addsitedir(site.USER_SITE) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
26 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
27 class HelperFunctionsTests(unittest.TestCase): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
28 """Tests for helper functions. |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
29 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
30 The setting of the encoding (set using sys.setdefaultencoding) used by |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
31 the Unicode implementation is not tested. |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
32 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
33 """ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
34 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
35 def setUp(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
36 """Save a copy of sys.path""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
37 self.sys_path = sys.path[:] |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
38 |
|
46992
7b6e222eada7
Fix "refleak" by restoring the tearDown method removed by accident (AFAICT)
Neal Norwitz <nnorwitz@gmail.com>
parents:
46698
diff
changeset
|
39 def tearDown(self): |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
40 """Restore sys.path""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
41 sys.path = self.sys_path |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
42 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
43 def test_makepath(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
44 # Test makepath() have an absolute path for its first return value |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
45 # and a case-normalized version of the absolute path for its |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
46 # second value. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
47 path_parts = ("Beginning", "End") |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
48 original_dir = os.path.join(*path_parts) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
49 abs_dir, norm_dir = site.makepath(*path_parts) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
50 self.failUnlessEqual(os.path.abspath(original_dir), abs_dir) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
51 if original_dir == os.path.normcase(original_dir): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
52 self.failUnlessEqual(abs_dir, norm_dir) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
53 else: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
54 self.failUnlessEqual(os.path.normcase(abs_dir), norm_dir) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
55 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
56 def test_init_pathinfo(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
57 dir_set = site._init_pathinfo() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
58 for entry in [site.makepath(path)[1] for path in sys.path |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
59 if path and os.path.isdir(path)]: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
60 self.failUnless(entry in dir_set, |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
61 "%s from sys.path not found in set returned " |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
62 "by _init_pathinfo(): %s" % (entry, dir_set)) |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
63 |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
64 def pth_file_tests(self, pth_file): |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
65 """Contain common code for testing results of reading a .pth file""" |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
66 self.failUnless(pth_file.imported in sys.modules, |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
67 "%s not in sys.path" % pth_file.imported) |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
68 self.failUnless(site.makepath(pth_file.good_dir_path)[0] in sys.path) |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
69 self.failUnless(not os.path.exists(pth_file.bad_dir_path)) |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
70 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
71 def test_addpackage(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
72 # Make sure addpackage() imports if the line starts with 'import', |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
73 # adds directories to sys.path for any line in the file that is not a |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
74 # comment or import that is a valid directory name for where the .pth |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
75 # file resides; invalid directories are not added |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
76 pth_file = PthFile() |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
77 pth_file.cleanup(prep=True) # to make sure that nothing is |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
78 # pre-existing that shouldn't be |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
79 try: |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
80 pth_file.create() |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
81 site.addpackage(pth_file.base_dir, pth_file.filename, set()) |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
82 self.pth_file_tests(pth_file) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
83 finally: |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
84 pth_file.cleanup() |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
85 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
86 def test_addsitedir(self): |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
87 # Same tests for test_addpackage since addsitedir() essentially just |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
88 # calls addpackage() for every .pth file in the directory |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
89 pth_file = PthFile() |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
90 pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
91 # that is tested for |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
92 try: |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
93 pth_file.create() |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
94 site.addsitedir(pth_file.base_dir, set()) |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
95 self.pth_file_tests(pth_file) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
96 finally: |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
97 pth_file.cleanup() |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
98 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
99 def test_s_option(self): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
100 usersite = site.USER_SITE |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
101 self.assert_(usersite in sys.path) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
102 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
103 rc = subprocess.call([sys.executable, '-c', |
|
51791
c201c8cf3cb4
Revert debugging statements, culprit is possibly test_distutils (see #5316)
Antoine Pitrou <solipsis@pitrou.net>
parents:
51790
diff
changeset
|
104 'import sys; sys.exit(%r in sys.path)' % usersite]) |
|
51839
45b44bd32f41
Expand upon test_site.test_s_option to try to debug its failure.
Brett Cannon <bcannon@gmail.com>
parents:
51791
diff
changeset
|
105 self.assertEqual(rc, 1, "%r is not in sys.path (sys.exit returned %r)" |
|
45b44bd32f41
Expand upon test_site.test_s_option to try to debug its failure.
Brett Cannon <bcannon@gmail.com>
parents:
51791
diff
changeset
|
106 % (usersite, rc)) |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
107 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
108 rc = subprocess.call([sys.executable, '-s', '-c', |
|
47772
0aeeb2b48341
In test_site, correctly escape backslashes in path names.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46992
diff
changeset
|
109 'import sys; sys.exit(%r in sys.path)' % usersite]) |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
110 self.assertEqual(rc, 0) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
111 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
112 env = os.environ.copy() |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
113 env["PYTHONNOUSERSITE"] = "1" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
114 rc = subprocess.call([sys.executable, '-c', |
|
47772
0aeeb2b48341
In test_site, correctly escape backslashes in path names.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46992
diff
changeset
|
115 'import sys; sys.exit(%r in sys.path)' % usersite], |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
116 env=env) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
117 self.assertEqual(rc, 0) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
118 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
119 env = os.environ.copy() |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
120 env["PYTHONUSERBASE"] = "/tmp" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
121 rc = subprocess.call([sys.executable, '-c', |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
122 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'], |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
123 env=env) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
124 self.assertEqual(rc, 1) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
125 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
126 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
127 class PthFile(object): |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
128 """Helper class for handling testing of .pth files""" |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
129 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
130 def __init__(self, filename_base=TESTFN, imported="time", |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
131 good_dirname="__testdir__", bad_dirname="__bad"): |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
132 """Initialize instance variables""" |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
133 self.filename = filename_base + ".pth" |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
134 self.base_dir = os.path.abspath('') |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
135 self.file_path = os.path.join(self.base_dir, self.filename) |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
136 self.imported = imported |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
137 self.good_dirname = good_dirname |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
138 self.bad_dirname = bad_dirname |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
139 self.good_dir_path = os.path.join(self.base_dir, self.good_dirname) |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
140 self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
141 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
142 def create(self): |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
143 """Create a .pth file with a comment, blank lines, an ``import |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
144 <self.imported>``, a line with self.good_dirname, and a line with |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
145 self.bad_dirname. |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
32644
diff
changeset
|
146 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
147 Creation of the directory for self.good_dir_path (based off of |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
148 self.good_dirname) is also performed. |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
149 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
150 Make sure to call self.cleanup() to undo anything done by this method. |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
32644
diff
changeset
|
151 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
152 """ |
|
34971
0905812df4a5
Fix test_site to not call open('...', 'wU'), as that now raises an error.
Michael W. Hudson <mwh@python.net>
parents:
32736
diff
changeset
|
153 FILE = open(self.file_path, 'w') |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
154 try: |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
155 print>>FILE, "#import @bad module name" |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
156 print>>FILE, "\n" |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
157 print>>FILE, "import %s" % self.imported |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
158 print>>FILE, self.good_dirname |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
159 print>>FILE, self.bad_dirname |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
160 finally: |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
161 FILE.close() |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
162 os.mkdir(self.good_dir_path) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
163 |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
164 def cleanup(self, prep=False): |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
165 """Make sure that the .pth file is deleted, self.imported is not in |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
166 sys.modules, and that both self.good_dirname and self.bad_dirname are |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
167 not existing directories.""" |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
168 if os.path.exists(self.file_path): |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
169 os.remove(self.file_path) |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
170 if prep: |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
171 self.imported_module = sys.modules.get(self.imported) |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
172 if self.imported_module: |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
173 del sys.modules[self.imported] |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
174 else: |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
175 if self.imported_module: |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
176 sys.modules[self.imported] = self.imported_module |
|
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
177 if os.path.exists(self.good_dir_path): |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
178 os.rmdir(self.good_dir_path) |
|
32644
fbb901d6297b
Fixes a bug in testing code handling .pth files that did not restore the original
Brett Cannon <bcannon@gmail.com>
parents:
32568
diff
changeset
|
179 if os.path.exists(self.bad_dir_path): |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
180 os.rmdir(self.bad_dir_path) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
181 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
182 class ImportSideEffectTests(unittest.TestCase): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
183 """Test side-effects from importing 'site'.""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
184 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
185 def setUp(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
186 """Make a copy of sys.path""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
187 self.sys_path = sys.path[:] |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
188 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
189 def tearDown(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
190 """Restore sys.path""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
191 sys.path = self.sys_path |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
192 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
193 def test_abs__file__(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
194 # Make sure all imported modules have their __file__ attribute |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
195 # as an absolute path. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
196 # Handled by abs__file__() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
197 site.abs__file__() |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
198 for module in (sys, os, __builtin__): |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
199 try: |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
200 self.failUnless(os.path.isabs(module.__file__), `module`) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
201 except AttributeError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
202 continue |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
203 # We could try everything in sys.modules; however, when regrtest.py |
|
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
204 # runs something like test_frozen before test_site, then we will |
|
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
205 # be testing things loaded *after* test_site did path normalization |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
206 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
207 def test_no_duplicate_paths(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
208 # No duplicate paths should exist in sys.path |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
209 # Handled by removeduppaths() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
210 site.removeduppaths() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
211 seen_paths = set() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
212 for path in sys.path: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
213 self.failUnless(path not in seen_paths) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
214 seen_paths.add(path) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
215 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
216 def test_add_build_dir(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
217 # Test that the build directory's Modules directory is used when it |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
218 # should be. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
219 # XXX: implement |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
220 pass |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
221 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
222 def test_setting_quit(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
223 # 'quit' and 'exit' should be injected into __builtin__ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
224 self.failUnless(hasattr(__builtin__, "quit")) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
225 self.failUnless(hasattr(__builtin__, "exit")) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
226 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
227 def test_setting_copyright(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
228 # 'copyright' and 'credits' should be in __builtin__ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
229 self.failUnless(hasattr(__builtin__, "copyright")) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
230 self.failUnless(hasattr(__builtin__, "credits")) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
231 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
232 def test_setting_help(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
233 # 'help' should be set in __builtin__ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
234 self.failUnless(hasattr(__builtin__, "help")) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
235 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
236 def test_aliasing_mbcs(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
237 if sys.platform == "win32": |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
238 import locale |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
239 if locale.getdefaultlocale()[1].startswith('cp'): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
240 for value in encodings.aliases.aliases.itervalues(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
241 if value == "mbcs": |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
242 break |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
243 else: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
244 self.fail("did not alias mbcs") |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
245 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
246 def test_setdefaultencoding_removed(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
247 # Make sure sys.setdefaultencoding is gone |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
248 self.failUnless(not hasattr(sys, "setdefaultencoding")) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
249 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
250 def test_sitecustomize_executed(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
251 # If sitecustomize is available, it should have been imported. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
252 if not sys.modules.has_key("sitecustomize"): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
253 try: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
254 import sitecustomize |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
255 except ImportError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
256 pass |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
257 else: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
258 self.fail("sitecustomize not imported automatically") |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
259 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
260 def test_main(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
261 run_unittest(HelperFunctionsTests, ImportSideEffectTests) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
262 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
263 if __name__ == "__main__": |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
264 test_main() |
