Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_site.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 82c4f094f811 |
| children |
| 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 |
|
67145
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
9 from test.test_support import captured_output |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
10 import __builtin__ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
11 import os |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
12 import sys |
|
67148
d4d3c89ab388
Merged revisions 87501 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67145
diff
changeset
|
13 import re |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
14 import encodings |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
15 import subprocess |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
16 import sysconfig |
|
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
17 from copy import copy |
|
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
18 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
19 # 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
|
20 # 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
|
21 # already. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
22 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
|
23 import site |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
24 else: |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
25 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
|
26 |
|
73266
1689b9cf6b1c
Issue #13304: Skip test case if user site-packages disabled (-s or
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
27 if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE): |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
28 # need to add user site directory for tests |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
29 os.makedirs(site.USER_SITE) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
30 site.addsitedir(site.USER_SITE) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
31 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
32 class HelperFunctionsTests(unittest.TestCase): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
33 """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
|
34 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
35 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
|
36 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
|
37 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
38 """ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
39 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
40 def setUp(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
41 """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
|
42 self.sys_path = sys.path[:] |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
43 self.old_base = site.USER_BASE |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
44 self.old_site = site.USER_SITE |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
45 self.old_prefixes = site.PREFIXES |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
46 self.old_vars = copy(sysconfig._CONFIG_VARS) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
47 |
|
46992
7b6e222eada7
Fix "refleak" by restoring the tearDown method removed by accident (AFAICT)
Neal Norwitz <nnorwitz@gmail.com>
parents:
46698
diff
changeset
|
48 def tearDown(self): |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
49 """Restore sys.path""" |
|
56568
007505cc1e2c
Don't replace sys.path in test_site
Nick Coghlan <ncoghlan@gmail.com>
parents:
55705
diff
changeset
|
50 sys.path[:] = self.sys_path |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
51 site.USER_BASE = self.old_base |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
52 site.USER_SITE = self.old_site |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
53 site.PREFIXES = self.old_prefixes |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
54 sysconfig._CONFIG_VARS = self.old_vars |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
55 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
56 def test_makepath(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
57 # 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
|
58 # 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
|
59 # second value. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
60 path_parts = ("Beginning", "End") |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
61 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
|
62 abs_dir, norm_dir = site.makepath(*path_parts) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
63 self.assertEqual(os.path.abspath(original_dir), abs_dir) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
64 if original_dir == os.path.normcase(original_dir): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
65 self.assertEqual(abs_dir, norm_dir) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
66 else: |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
67 self.assertEqual(os.path.normcase(abs_dir), norm_dir) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
68 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 if path and os.path.isdir(path)]: |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58450
diff
changeset
|
73 self.assertIn(entry, dir_set, |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58450
diff
changeset
|
74 "%s from sys.path not found in set returned " |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58450
diff
changeset
|
75 "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
|
76 |
|
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 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
|
78 """Contain common code for testing results of reading a .pth file""" |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58450
diff
changeset
|
79 self.assertIn(pth_file.imported, sys.modules, |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58450
diff
changeset
|
80 "%s not in sys.modules" % pth_file.imported) |
|
57062
f01302e6acd5
Fix and improve some assertions in test_site
Antoine Pitrou <solipsis@pitrou.net>
parents:
56901
diff
changeset
|
81 self.assertIn(site.makepath(pth_file.good_dir_path)[0], sys.path) |
|
f01302e6acd5
Fix and improve some assertions in test_site
Antoine Pitrou <solipsis@pitrou.net>
parents:
56901
diff
changeset
|
82 self.assertFalse(os.path.exists(pth_file.bad_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
|
83 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
84 def test_addpackage(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
85 # 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
|
86 # 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
|
87 # 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
|
88 # 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
|
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) # 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
|
91 # 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
|
92 try: |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
93 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
|
94 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
|
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() |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
98 |
|
67145
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
99 def make_pth(self, contents, pth_dir='.', pth_name=TESTFN): |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
100 # Create a .pth file and return its (abspath, basename). |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
101 pth_dir = os.path.abspath(pth_dir) |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
102 pth_basename = pth_name + '.pth' |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
103 pth_fn = os.path.join(pth_dir, pth_basename) |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
104 pth_file = open(pth_fn, 'w') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
105 self.addCleanup(lambda: os.remove(pth_fn)) |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
106 pth_file.write(contents) |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
107 pth_file.close() |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
108 return pth_dir, pth_basename |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
109 |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
110 def test_addpackage_import_bad_syntax(self): |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
111 # Issue 10642 |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
112 pth_dir, pth_fn = self.make_pth("import bad)syntax\n") |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
113 with captured_output("stderr") as err_out: |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
114 site.addpackage(pth_dir, pth_fn, set()) |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
115 self.assertRegexpMatches(err_out.getvalue(), "line 1") |
|
67148
d4d3c89ab388
Merged revisions 87501 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67145
diff
changeset
|
116 self.assertRegexpMatches(err_out.getvalue(), |
|
d4d3c89ab388
Merged revisions 87501 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67145
diff
changeset
|
117 re.escape(os.path.join(pth_dir, pth_fn))) |
|
67145
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
118 # XXX: the previous two should be independent checks so that the |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
119 # order doesn't matter. The next three could be a single check |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
120 # but my regex foo isn't good enough to write it. |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
121 self.assertRegexpMatches(err_out.getvalue(), 'Traceback') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
122 self.assertRegexpMatches(err_out.getvalue(), r'import bad\)syntax') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
123 self.assertRegexpMatches(err_out.getvalue(), 'SyntaxError') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
124 |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
125 def test_addpackage_import_bad_exec(self): |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
126 # Issue 10642 |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
127 pth_dir, pth_fn = self.make_pth("randompath\nimport nosuchmodule\n") |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
128 with captured_output("stderr") as err_out: |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
129 site.addpackage(pth_dir, pth_fn, set()) |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
130 self.assertRegexpMatches(err_out.getvalue(), "line 2") |
|
67148
d4d3c89ab388
Merged revisions 87501 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67145
diff
changeset
|
131 self.assertRegexpMatches(err_out.getvalue(), |
|
d4d3c89ab388
Merged revisions 87501 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67145
diff
changeset
|
132 re.escape(os.path.join(pth_dir, pth_fn))) |
|
67145
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
133 # XXX: ditto previous XXX comment. |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
134 self.assertRegexpMatches(err_out.getvalue(), 'Traceback') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
135 self.assertRegexpMatches(err_out.getvalue(), 'ImportError') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
136 |
|
67155
c694685b75e2
Merged revisions 87508 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67148
diff
changeset
|
137 @unittest.skipIf(sys.platform == "win32", "Windows does not raise an " |
|
c694685b75e2
Merged revisions 87508 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67148
diff
changeset
|
138 "error for file paths containing null characters") |
|
67145
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
139 def test_addpackage_import_bad_pth_file(self): |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
140 # Issue 5258 |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
141 pth_dir, pth_fn = self.make_pth("abc\x00def\n") |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
142 with captured_output("stderr") as err_out: |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
143 site.addpackage(pth_dir, pth_fn, set()) |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
144 self.assertRegexpMatches(err_out.getvalue(), "line 1") |
|
67148
d4d3c89ab388
Merged revisions 87501 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67145
diff
changeset
|
145 self.assertRegexpMatches(err_out.getvalue(), |
|
d4d3c89ab388
Merged revisions 87501 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
67145
diff
changeset
|
146 re.escape(os.path.join(pth_dir, pth_fn))) |
|
67145
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
147 # XXX: ditto previous XXX comment. |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
148 self.assertRegexpMatches(err_out.getvalue(), 'Traceback') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
149 self.assertRegexpMatches(err_out.getvalue(), 'TypeError') |
|
dd6d1ecbeb56
Merged revisions 87497 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
150 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
151 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
|
152 # 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
|
153 # 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
|
154 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
|
155 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
|
156 # 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 finally: |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
162 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
|
163 |
|
73266
1689b9cf6b1c
Issue #13304: Skip test case if user site-packages disabled (-s or
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
164 @unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 " |
|
1689b9cf6b1c
Issue #13304: Skip test case if user site-packages disabled (-s or
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
165 "user-site (site.ENABLE_USER_SITE)") |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
166 def test_s_option(self): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
167 usersite = site.USER_SITE |
|
57062
f01302e6acd5
Fix and improve some assertions in test_site
Antoine Pitrou <solipsis@pitrou.net>
parents:
56901
diff
changeset
|
168 self.assertIn(usersite, sys.path) |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
169 |
|
67309
a33e1f02091f
Merged revisions 87691 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
67155
diff
changeset
|
170 env = os.environ.copy() |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
171 rc = subprocess.call([sys.executable, '-c', |
|
67309
a33e1f02091f
Merged revisions 87691 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
67155
diff
changeset
|
172 'import sys; sys.exit(%r in sys.path)' % usersite], |
|
a33e1f02091f
Merged revisions 87691 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
67155
diff
changeset
|
173 env=env) |
|
51839
45b44bd32f41
Expand upon test_site.test_s_option to try to debug its failure.
Brett Cannon <bcannon@gmail.com>
parents:
51791
diff
changeset
|
174 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
|
175 % (usersite, rc)) |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
176 |
|
67309
a33e1f02091f
Merged revisions 87691 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
67155
diff
changeset
|
177 env = os.environ.copy() |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
178 rc = subprocess.call([sys.executable, '-s', '-c', |
|
67309
a33e1f02091f
Merged revisions 87691 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
67155
diff
changeset
|
179 'import sys; sys.exit(%r in sys.path)' % usersite], |
|
a33e1f02091f
Merged revisions 87691 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
67155
diff
changeset
|
180 env=env) |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
181 self.assertEqual(rc, 0) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
182 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
183 env = os.environ.copy() |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
184 env["PYTHONNOUSERSITE"] = "1" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
185 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
|
186 'import sys; sys.exit(%r in sys.path)' % usersite], |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
187 env=env) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
188 self.assertEqual(rc, 0) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
189 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
190 env = os.environ.copy() |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
191 env["PYTHONUSERBASE"] = "/tmp" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
192 rc = subprocess.call([sys.executable, '-c', |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
193 'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'], |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
194 env=env) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
195 self.assertEqual(rc, 1) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
45468
diff
changeset
|
196 |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
197 def test_getuserbase(self): |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
198 site.USER_BASE = None |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
199 user_base = site.getuserbase() |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
200 |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
201 # the call sets site.USER_BASE |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64105
diff
changeset
|
202 self.assertEqual(site.USER_BASE, user_base) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
203 |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
204 # let's set PYTHONUSERBASE and see if it uses it |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
205 site.USER_BASE = None |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
206 import sysconfig |
|
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
207 sysconfig._CONFIG_VARS = None |
|
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58198
diff
changeset
|
208 |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
209 with EnvironmentVarGuard() as environ: |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
210 environ['PYTHONUSERBASE'] = 'xoxo' |
|
57062
f01302e6acd5
Fix and improve some assertions in test_site
Antoine Pitrou <solipsis@pitrou.net>
parents:
56901
diff
changeset
|
211 self.assertTrue(site.getuserbase().startswith('xoxo'), |
|
f01302e6acd5
Fix and improve some assertions in test_site
Antoine Pitrou <solipsis@pitrou.net>
parents:
56901
diff
changeset
|
212 site.getuserbase()) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
213 |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
214 def test_getusersitepackages(self): |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
215 site.USER_SITE = None |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
216 site.USER_BASE = None |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
217 user_site = site.getusersitepackages() |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
218 |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
219 # the call sets USER_BASE *and* USER_SITE |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64105
diff
changeset
|
220 self.assertEqual(site.USER_SITE, user_site) |
|
57062
f01302e6acd5
Fix and improve some assertions in test_site
Antoine Pitrou <solipsis@pitrou.net>
parents:
56901
diff
changeset
|
221 self.assertTrue(user_site.startswith(site.USER_BASE), user_site) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
222 |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
223 def test_getsitepackages(self): |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
224 site.PREFIXES = ['xoxo'] |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
225 dirs = site.getsitepackages() |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
226 |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
227 if sys.platform in ('os2emx', 'riscos'): |
|
57062
f01302e6acd5
Fix and improve some assertions in test_site
Antoine Pitrou <solipsis@pitrou.net>
parents:
56901
diff
changeset
|
228 self.assertEqual(len(dirs), 1) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
229 wanted = os.path.join('xoxo', 'Lib', 'site-packages') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64105
diff
changeset
|
230 self.assertEqual(dirs[0], wanted) |
|
74802
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
231 elif (sys.platform == "darwin" and |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
232 sysconfig.get_config_var("PYTHONFRAMEWORK")): |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
233 # OS X framework builds |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
234 site.PREFIXES = ['Python.framework'] |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
235 dirs = site.getsitepackages() |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
236 self.assertEqual(len(dirs), 3) |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
237 wanted = os.path.join('/Library', |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
238 sysconfig.get_config_var("PYTHONFRAMEWORK"), |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
239 sys.version[:3], |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
240 'site-packages') |
|
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
241 self.assertEqual(dirs[2], wanted) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
242 elif os.sep == '/': |
|
74802
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
243 # OS X non-framwework builds, Linux, FreeBSD, etc |
|
64105
6cc655416d63
Merged revisions 84134 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61562
diff
changeset
|
244 self.assertEqual(len(dirs), 2) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
245 wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3], |
|
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
246 'site-packages') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64105
diff
changeset
|
247 self.assertEqual(dirs[0], wanted) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
248 wanted = os.path.join('xoxo', 'lib', 'site-python') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64105
diff
changeset
|
249 self.assertEqual(dirs[1], wanted) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
250 else: |
|
74802
82c4f094f811
Issue #10881: Fix test_site failures with OS X framework builds.
Ned Deily <nad@acm.org>
parents:
73266
diff
changeset
|
251 # other platforms |
|
64105
6cc655416d63
Merged revisions 84134 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61562
diff
changeset
|
252 self.assertEqual(len(dirs), 2) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64105
diff
changeset
|
253 self.assertEqual(dirs[0], 'xoxo') |
|
56901
3ae4d3667920
Issue #7218: Fix test_site for win32
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
56568
diff
changeset
|
254 wanted = os.path.join('xoxo', 'lib', 'site-packages') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64105
diff
changeset
|
255 self.assertEqual(dirs[1], wanted) |
|
55705
974553fb59dc
#6693: New functions in site.py to get user/global site packages paths.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55002
diff
changeset
|
256 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
257 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
|
258 """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
|
259 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
260 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
|
261 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
|
262 """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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
272 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
|
273 """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
|
274 <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
|
275 self.bad_dirname. |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
32644
diff
changeset
|
276 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
277 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
|
278 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
|
279 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
280 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
|
281 |
|
32568
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
282 """ |
|
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
|
283 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
|
284 try: |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 finally: |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
291 FILE.close() |
|
844d99c888bb
Restructure testing of .pth files. Move previous functions into a class and
Brett Cannon <bcannon@gmail.com>
parents:
32419
diff
changeset
|
292 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
|
293 |
|
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
|
294 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
|
295 """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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
312 class ImportSideEffectTests(unittest.TestCase): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
313 """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
|
314 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
315 def setUp(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
316 """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
|
317 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
|
318 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
319 def tearDown(self): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
320 """Restore sys.path""" |
|
56568
007505cc1e2c
Don't replace sys.path in test_site
Nick Coghlan <ncoghlan@gmail.com>
parents:
55705
diff
changeset
|
321 sys.path[:] = self.sys_path |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
322 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
323 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
|
324 # 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
|
325 # as an absolute path. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
326 # Handled by abs__file__() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
327 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
|
328 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
|
329 try: |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
53485
diff
changeset
|
330 self.assertTrue(os.path.isabs(module.__file__), repr(module)) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
331 except AttributeError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
332 continue |
|
32419
84e5b585d201
* Silence a test failure that resulted when test_site was run by
Raymond Hettinger <python@rcn.com>
parents:
32304
diff
changeset
|
333 # 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
|
334 # 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
|
335 # 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
|
336 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
337 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
|
338 # 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
|
339 # Handled by removeduppaths() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
340 site.removeduppaths() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
341 seen_paths = set() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
342 for path in sys.path: |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58450
diff
changeset
|
343 self.assertNotIn(path, seen_paths) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
344 seen_paths.add(path) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
345 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
346 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
|
347 # 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
|
348 # should be. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
349 # XXX: implement |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
350 pass |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
351 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
352 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
|
353 # 'quit' and 'exit' should be injected into __builtin__ |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
354 self.assertTrue(hasattr(__builtin__, "quit")) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
355 self.assertTrue(hasattr(__builtin__, "exit")) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
356 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
357 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
|
358 # 'copyright' and 'credits' should be in __builtin__ |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
359 self.assertTrue(hasattr(__builtin__, "copyright")) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
360 self.assertTrue(hasattr(__builtin__, "credits")) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
361 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
362 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
|
363 # 'help' should be set in __builtin__ |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
364 self.assertTrue(hasattr(__builtin__, "help")) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
365 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
366 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
|
367 if sys.platform == "win32": |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
368 import locale |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
369 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
|
370 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
|
371 if value == "mbcs": |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
372 break |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
373 else: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
374 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
|
375 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
376 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
|
377 # Make sure sys.setdefaultencoding is gone |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53484
diff
changeset
|
378 self.assertTrue(not hasattr(sys, "setdefaultencoding")) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
379 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
380 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
|
381 # If sitecustomize is available, it should have been imported. |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
53485
diff
changeset
|
382 if "sitecustomize" not in sys.modules: |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
383 try: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
384 import sitecustomize |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
385 except ImportError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
386 pass |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
387 else: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
388 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
|
389 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
390 def test_main(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
391 run_unittest(HelperFunctionsTests, ImportSideEffectTests) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
392 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
393 if __name__ == "__main__": |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
394 test_main() |
