Show More
@@ -942,7 +942,11 b' def get_home_dir():' | |||
|
942 | 942 | if not isdir(homedir): |
|
943 | 943 | # in case a user stuck some string which does NOT resolve to a |
|
944 | 944 | # valid path, it's as good as if we hadn't foud it |
|
945 | raise KeyError | |
|
945 | ||
|
946 | #raise KeyError # dbg | |
|
947 | # dbg - figuring out what's going on here | |
|
948 | pp = os.listdir(homedir+'/..') | |
|
949 | raise ValueError('Wrong dir: %s\n%s' % (homedir,pp)) # dbg | |
|
946 | 950 | return homedir |
|
947 | 951 | except KeyError: |
|
948 | 952 | if os.name == 'posix': |
@@ -1371,6 +1371,7 b' want to merge them back into the new files.""" % locals()' | |||
|
1371 | 1371 | # not run as the syntax for libedit is different. |
|
1372 | 1372 | if not readline.uses_libedit: |
|
1373 | 1373 | for rlcommand in self.rc.readline_parse_and_bind: |
|
1374 | #print "loading rl:",rlcommand # dbg | |
|
1374 | 1375 | readline.parse_and_bind(rlcommand) |
|
1375 | 1376 | |
|
1376 | 1377 | # remove some chars from the delimiters list |
@@ -15,17 +15,26 b' __docformat__ = "restructuredtext en"' | |||
|
15 | 15 | # Imports |
|
16 | 16 | #----------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | from IPython import genutils | |
|
19 | from IPython.testing.decorators import skipif, skip_if_not_win32 | |
|
20 | from nose import with_setup | |
|
21 | from nose.tools import raises | |
|
18 | # stdlib | |
|
19 | import os | |
|
20 | import shutil | |
|
21 | import sys | |
|
22 | import tempfile | |
|
22 | 23 | |
|
23 | 24 | from os.path import join, abspath, split |
|
24 | import os, sys, IPython | |
|
25 | ||
|
26 | # third-party | |
|
25 | 27 | import nose.tools as nt |
|
26 | 28 | |
|
27 | env = os.environ | |
|
29 | from nose import with_setup | |
|
30 | from nose.tools import raises | |
|
28 | 31 | |
|
32 | # Our own | |
|
33 | import IPython | |
|
34 | from IPython import genutils | |
|
35 | from IPython.testing.decorators import skipif, skip_if_not_win32 | |
|
36 | ||
|
37 | # Platform-dependent imports | |
|
29 | 38 | try: |
|
30 | 39 | import _winreg as wreg |
|
31 | 40 | except ImportError: |
@@ -36,32 +45,36 b' except ImportError:' | |||
|
36 | 45 | #Add entries that needs to be stubbed by the testing code |
|
37 | 46 | (wreg.OpenKey, wreg.QueryValueEx,) = (None, None) |
|
38 | 47 | |
|
39 | test_file_path = split(abspath(__file__))[0] | |
|
40 | ||
|
48 | #----------------------------------------------------------------------------- | |
|
49 | # Globals | |
|
50 | #----------------------------------------------------------------------------- | |
|
51 | env = os.environ | |
|
52 | TEST_FILE_PATH = split(abspath(__file__))[0] | |
|
53 | TMP_TEST_DIR = tempfile.mkdtemp() | |
|
54 | HOME_TEST_DIR = join(TMP_TEST_DIR, "home_test_dir") | |
|
55 | IP_TEST_DIR = join(HOME_TEST_DIR,'_ipython') | |
|
41 | 56 | # |
|
42 | 57 | # Setup/teardown functions/decorators |
|
43 | 58 | # |
|
44 | 59 | |
|
45 | ||
|
46 | 60 | def setup(): |
|
47 | 61 | """Setup testenvironment for the module: |
|
48 | 62 | |
|
49 | 63 | - Adds dummy home dir tree |
|
50 | 64 | """ |
|
51 | try: | |
|
52 | os.makedirs("home_test_dir/_ipython") | |
|
53 | except WindowsError: | |
|
54 | pass #Or should we complain that the test directory already exists?? | |
|
65 | # Do not mask exceptions here. In particular, catching WindowsError is a | |
|
66 | # problem because that exception is only defined on Windows... | |
|
67 | os.makedirs(IP_TEST_DIR) | |
|
55 | 68 | |
|
56 | 69 | def teardown(): |
|
57 | 70 | """Teardown testenvironment for the module: |
|
58 | 71 | |
|
59 | 72 | - Remove dummy home dir tree |
|
60 | 73 | """ |
|
61 | try: | |
|
62 | os.removedirs("home_test_dir/_ipython") | |
|
63 | except WindowsError: | |
|
64 | pass #Or should we complain that the test directory already exists?? | |
|
74 | # Note: we remove the parent test dir, which is the root of all test | |
|
75 | # subdirs we may have created. Use shutil instead of os.removedirs, so | |
|
76 | # that non-empty directories are all recursively removed. | |
|
77 | shutil.rmtree(TMP_TEST_DIR) | |
|
65 | 78 | |
|
66 | 79 | |
|
67 | 80 | def setup_environment(): |
@@ -109,10 +122,10 b' def test_get_home_dir_1():' | |||
|
109 | 122 | sys.frozen = True |
|
110 | 123 | |
|
111 | 124 | #fake filename for IPython.__init__ |
|
112 |
IPython.__file__ = abspath(join( |
|
|
125 | IPython.__file__ = abspath(join(TEST_FILE_PATH, "home_test_dir/Lib/IPython/__init__.py")) | |
|
113 | 126 | |
|
114 | 127 | home_dir = genutils.get_home_dir() |
|
115 |
nt.assert_equal(home_dir, abspath( |
|
|
128 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
|
116 | 129 | |
|
117 | 130 | @skip_if_not_win32 |
|
118 | 131 | @with_enivronment |
@@ -121,15 +134,15 b' def test_get_home_dir_2():' | |||
|
121 | 134 | """ |
|
122 | 135 | sys.frozen = True |
|
123 | 136 | #fake filename for IPython.__init__ |
|
124 |
IPython.__file__ = abspath(join( |
|
|
137 | IPython.__file__ = abspath(join(TEST_FILE_PATH, "home_test_dir/Library.zip/IPython/__init__.py")).lower() | |
|
125 | 138 | |
|
126 | 139 | home_dir = genutils.get_home_dir() |
|
127 |
nt.assert_equal(home_dir, abspath( |
|
|
140 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower()) | |
|
128 | 141 | |
|
129 | 142 | @with_enivronment |
|
130 | 143 | def test_get_home_dir_3(): |
|
131 | 144 | """Testcase $HOME is set, then use its value as home directory.""" |
|
132 | env["HOME"] = join(test_file_path, "home_test_dir") | |
|
145 | env["HOME"] = HOME_TEST_DIR | |
|
133 | 146 | home_dir = genutils.get_home_dir() |
|
134 | 147 | nt.assert_equal(home_dir, env["HOME"]) |
|
135 | 148 | |
@@ -150,10 +163,10 b' def test_get_home_dir_5():' | |||
|
150 | 163 | |
|
151 | 164 | os.name = 'nt' |
|
152 | 165 | if 'HOME' in env: del env['HOME'] |
|
153 |
env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath( |
|
|
166 | env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "home_test_dir" | |
|
154 | 167 | |
|
155 | 168 | home_dir = genutils.get_home_dir() |
|
156 |
nt.assert_equal(home_dir, abspath( |
|
|
169 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
|
157 | 170 | |
|
158 | 171 | @skip_if_not_win32 |
|
159 | 172 | @with_enivronment |
@@ -165,11 +178,11 b' def test_get_home_dir_6():' | |||
|
165 | 178 | |
|
166 | 179 | os.name = 'nt' |
|
167 | 180 | if 'HOME' in env: del env['HOME'] |
|
168 |
env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath( |
|
|
169 |
env["USERPROFILE"] = abspath( |
|
|
181 | env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST" | |
|
182 | env["USERPROFILE"] = abspath(HOME_TEST_DIR) | |
|
170 | 183 | |
|
171 | 184 | home_dir = genutils.get_home_dir() |
|
172 |
nt.assert_equal(home_dir, abspath( |
|
|
185 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
|
173 | 186 | |
|
174 | 187 | # Should we stub wreg fully so we can run the test on all platforms? |
|
175 | 188 | @skip_if_not_win32 |
@@ -189,13 +202,13 b' def test_get_home_dir_7():' | |||
|
189 | 202 | pass |
|
190 | 203 | return key() |
|
191 | 204 | def QueryValueEx(x, y): |
|
192 | return [abspath(join(test_file_path, "home_test_dir"))] | |
|
205 | return [abspath(HOME_TEST_DIR)] | |
|
193 | 206 | |
|
194 | 207 | wreg.OpenKey = OpenKey |
|
195 | 208 | wreg.QueryValueEx = QueryValueEx |
|
196 | 209 | |
|
197 | 210 | home_dir = genutils.get_home_dir() |
|
198 |
nt.assert_equal(home_dir, abspath( |
|
|
211 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
|
199 | 212 | |
|
200 | 213 | |
|
201 | 214 | # |
General Comments 0
You need to be logged in to leave comments.
Login now