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