##// END OF EJS Templates
Merging upstream changes from trunk (after fixing small conflicts).
Fernando Perez -
r1872:d21e2734 merge
parent child Browse files
Show More
@@ -922,12 +922,15 b' def get_home_dir():'
922 # first, check py2exe distribution root directory for _ipython.
922 # first, check py2exe distribution root directory for _ipython.
923 # This overrides all. Normally does not exist.
923 # This overrides all. Normally does not exist.
924
924
925 if '\\library.zip\\' in IPython.__file__.lower():
925 if hasattr(sys, "frozen"): #Is frozen by py2exe
926 root, rest = IPython.__file__.lower().split('library.zip')
926 if '\\library.zip\\' in IPython.__file__.lower():#libraries compressed to zip-file
927 if isdir(root + '_ipython'):
927 root, rest = IPython.__file__.lower().split('library.zip')
928 os.environ["IPYKITROOT"] = root.rstrip('\\')
928 else:
929 return root
929 root=os.path.join(os.path.split(IPython.__file__)[0],"../../")
930
930 root=os.path.abspath(root).rstrip('\\')
931 if isdir(os.path.join(root, '_ipython')):
932 os.environ["IPYKITROOT"] = root
933 return root
931 try:
934 try:
932 homedir = env['HOME']
935 homedir = env['HOME']
933 if not isdir(homedir):
936 if not isdir(homedir):
@@ -947,7 +950,7 b' def get_home_dir():'
947 if not isdir(homedir):
950 if not isdir(homedir):
948 raise HomeDirError
951 raise HomeDirError
949 return homedir
952 return homedir
950 except:
953 except KeyError:
951 try:
954 try:
952 # Use the registry to get the 'My Documents' folder.
955 # Use the registry to get the 'My Documents' folder.
953 import _winreg as wreg
956 import _winreg as wreg
@@ -986,8 +989,8 b' def get_ipython_dir():'
986 ipdir_def = '_ipython'
989 ipdir_def = '_ipython'
987 home_dir = get_home_dir()
990 home_dir = get_home_dir()
988 ipdir = os.path.abspath(os.environ.get('IPYTHONDIR',
991 ipdir = os.path.abspath(os.environ.get('IPYTHONDIR',
989 os.path.join(home_dir,ipdir_def)))
992 os.path.join(home_dir, ipdir_def)))
990 return ipdir
993 return ipdir.decode(sys.getfilesystemencoding())
991
994
992 def get_security_dir():
995 def get_security_dir():
993 """Get the IPython security directory.
996 """Get the IPython security directory.
@@ -1414,6 +1414,7 b' want to merge them back into the new files.""" % locals()'
1414 # not run as the syntax for libedit is different.
1414 # not run as the syntax for libedit is different.
1415 if not readline.uses_libedit:
1415 if not readline.uses_libedit:
1416 for rlcommand in self.rc.readline_parse_and_bind:
1416 for rlcommand in self.rc.readline_parse_and_bind:
1417 #print "loading rl:",rlcommand # dbg
1417 readline.parse_and_bind(rlcommand)
1418 readline.parse_and_bind(rlcommand)
1418
1419
1419 # remove some chars from the delimiters list
1420 # remove some chars from the delimiters list
@@ -128,20 +128,15 b" object? -> Details about 'object'. ?object also works, ?? prints more."
128
128
129 IP.usage = interactive_usage
129 IP.usage = interactive_usage
130
130
131 # Platform-dependent suffix and directory names. We use _ipython instead
131 # Platform-dependent suffix.
132 # of .ipython under win32 b/c there's software that breaks with .named
133 # directories on that platform.
134 if os.name == 'posix':
132 if os.name == 'posix':
135 rc_suffix = ''
133 rc_suffix = ''
136 ipdir_def = '.ipython'
137 else:
134 else:
138 rc_suffix = '.ini'
135 rc_suffix = '.ini'
139 ipdir_def = '_ipython'
140
136
141 # default directory for configuration
137 # default directory for configuration
142 ipythondir_def = os.path.abspath(os.environ.get('IPYTHONDIR',
138 ipythondir_def = get_ipython_dir()
143 os.path.join(IP.home_dir,ipdir_def)))
139
144
145 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
140 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
146
141
147 # we need the directory where IPython itself is installed
142 # we need the directory where IPython itself is installed
@@ -233,12 +233,22 b" skip_doctest = make_label_dec('skip_doctest',"
233 etc.""")
233 etc.""")
234
234
235 # Decorators to skip certain tests on specific platforms.
235 # Decorators to skip certain tests on specific platforms.
236 skip_win32 = skipif(sys.platform=='win32',
236 skip_win32 = skipif(sys.platform == 'win32',
237 "This test does not run under Windows")
237 "This test does not run under Windows")
238 skip_linux = skipif(sys.platform=='linux2',"This test does not run under Linux")
238 skip_linux = skipif(sys.platform == 'linux2',
239 skip_osx = skipif(sys.platform=='darwin',"This test does not run under OS X")
239 "This test does not run under Linux")
240 skip_osx = skipif(sys.platform == 'darwin',"This test does not run under OS X")
240
241
241
242
243 # Decorators to skip tests if not on specific platforms.
244 skip_if_not_win32 = skipif(sys.platform != 'win32',
245 "This test only runs under Windows")
246 skip_if_not_linux = skipif(sys.platform != 'linux2',
247 "This test only runs under Linux")
248 skip_if_not_osx = skipif(sys.platform != 'darwin',
249 "This test only runs under OSX")
250
251 # Other skip decorators
242 skipif_not_numpy = skipif(numpy_not_available,"This test requires numpy")
252 skipif_not_numpy = skipif(numpy_not_available,"This test requires numpy")
243
253
244 skipknownfailure = skip('This test is known to fail')
254 skipknownfailure = skip('This test is known to fail')
@@ -15,18 +15,277 b' __docformat__ = "restructuredtext en"'
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 # stdlib
19 import os
20 import shutil
21 import sys
22 import tempfile
23
24 from os.path import join, abspath, split
25
26 # third-party
27 import nose.tools as nt
28
29 from nose import with_setup
30 from nose.tools import raises
31
32 # Our own
33 import IPython
18 from IPython import genutils
34 from IPython import genutils
35 from IPython.testing.decorators import skipif, skip_if_not_win32
36
37 # Platform-dependent imports
38 try:
39 import _winreg as wreg
40 except ImportError:
41 #Fake _winreg module on none windows platforms
42 import new
43 sys.modules["_winreg"] = new.module("_winreg")
44 import _winreg as wreg
45 #Add entries that needs to be stubbed by the testing code
46 (wreg.OpenKey, wreg.QueryValueEx,) = (None, None)
47
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')
56 #
57 # Setup/teardown functions/decorators
58 #
59
60 def setup():
61 """Setup testenvironment for the module:
62
63 - Adds dummy home dir tree
64 """
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)
68
69 def teardown():
70 """Teardown testenvironment for the module:
71
72 - Remove dummy home dir tree
73 """
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)
78
79
80 def setup_environment():
81 """Setup testenvironment for some functions that are tested
82 in this module. In particular this functions stores attributes
83 and other things that we need to stub in some test functions.
84 This needs to be done on a function level and not module level because
85 each testfunction needs a pristine environment.
86 """
87 global oldstuff, platformstuff
88 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
89
90 if os.name == 'nt':
91 platformstuff = (wreg.OpenKey, wreg.QueryValueEx,)
92
93 if 'IPYTHONDIR' in env:
94 del env['IPYTHONDIR']
95
96 def teardown_environment():
97 """Restore things that were remebered by the setup_environment function
98 """
99 (oldenv, os.name, genutils.get_home_dir, IPython.__file__,) = oldstuff
100 for key in env.keys():
101 if key not in oldenv:
102 del env[key]
103 env.update(oldenv)
104 if hasattr(sys, 'frozen'):
105 del sys.frozen
106 if os.name == 'nt':
107 (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
108
109 # Build decorator that uses the setup_environment/setup_environment
110 with_enivronment = with_setup(setup_environment, teardown_environment)
111
112
113 #
114 # Tests for get_home_dir
115 #
116
117 @skip_if_not_win32
118 @with_enivronment
119 def test_get_home_dir_1():
120 """Testcase for py2exe logic, un-compressed lib
121 """
122 sys.frozen = True
123
124 #fake filename for IPython.__init__
125 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
126
127 home_dir = genutils.get_home_dir()
128 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
129
130 @skip_if_not_win32
131 @with_enivronment
132 def test_get_home_dir_2():
133 """Testcase for py2exe logic, compressed lib
134 """
135 sys.frozen = True
136 #fake filename for IPython.__init__
137 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
138
139 home_dir = genutils.get_home_dir()
140 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower())
141
142 @with_enivronment
143 def test_get_home_dir_3():
144 """Testcase $HOME is set, then use its value as home directory."""
145 env["HOME"] = HOME_TEST_DIR
146 home_dir = genutils.get_home_dir()
147 nt.assert_equal(home_dir, env["HOME"])
148
149 @with_enivronment
150 def test_get_home_dir_4():
151 """Testcase $HOME is not set, os=='poix'.
152 This should fail with HomeDirError"""
153
154 os.name = 'posix'
155 if 'HOME' in env: del env['HOME']
156 nt.assert_raises(genutils.HomeDirError, genutils.get_home_dir)
157
158 @skip_if_not_win32
159 @with_enivronment
160 def test_get_home_dir_5():
161 """Testcase $HOME is not set, os=='nt'
162 env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
163
164 os.name = 'nt'
165 if 'HOME' in env: del env['HOME']
166 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR)
19
167
168 home_dir = genutils.get_home_dir()
169 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
170
171 @skip_if_not_win32
172 @with_enivronment
173 def test_get_home_dir_6():
174 """Testcase $HOME is not set, os=='nt'
175 env['HOMEDRIVE'],env['HOMEPATH'] do not point to path.
176 env['USERPROFILE'] points to path
177 """
178
179 os.name = 'nt'
180 if 'HOME' in env: del env['HOME']
181 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST"
182 env["USERPROFILE"] = abspath(HOME_TEST_DIR)
183
184 home_dir = genutils.get_home_dir()
185 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
186
187 # Should we stub wreg fully so we can run the test on all platforms?
188 @skip_if_not_win32
189 @with_enivronment
190 def test_get_home_dir_7():
191 """Testcase $HOME is not set, os=='nt'
192 env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing
193 """
194 os.name = 'nt'
195 if 'HOME' in env: del env['HOME']
196 if 'HOMEDRIVE' in env: del env['HOMEDRIVE']
197
198 #Stub windows registry functions
199 def OpenKey(x, y):
200 class key:
201 def Close(self):
202 pass
203 return key()
204 def QueryValueEx(x, y):
205 return [abspath(HOME_TEST_DIR)]
206
207 wreg.OpenKey = OpenKey
208 wreg.QueryValueEx = QueryValueEx
20
209
21 def test_get_home_dir():
22 """Make sure we can get the home directory."""
23 home_dir = genutils.get_home_dir()
210 home_dir = genutils.get_home_dir()
211 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
212
213
214 #
215 # Tests for get_ipython_dir
216 #
217
218 @with_enivronment
219 def test_get_ipython_dir_1():
220 """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions."""
221 env['IPYTHONDIR'] = "someplace/.ipython"
222 ipdir = genutils.get_ipython_dir()
223 nt.assert_equal(ipdir, os.path.abspath("someplace/.ipython"))
24
224
25 def test_get_ipython_dir():
225
26 """Make sure we can get the ipython directory."""
226 @with_enivronment
227 def test_get_ipython_dir_2():
228 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
229 genutils.get_home_dir = lambda : "someplace"
230 os.name = "posix"
231 ipdir = genutils.get_ipython_dir()
232 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", ".ipython")))
233
234 @with_enivronment
235 def test_get_ipython_dir_3():
236 """test_get_ipython_dir_3, Testcase to see if we can call get_ipython_dir without Exceptions."""
237 genutils.get_home_dir = lambda : "someplace"
238 os.name = "nt"
27 ipdir = genutils.get_ipython_dir()
239 ipdir = genutils.get_ipython_dir()
240 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", "_ipython")))
241
242
243 #
244 # Tests for get_security_dir
245 #
28
246
247 @with_enivronment
29 def test_get_security_dir():
248 def test_get_security_dir():
30 """Make sure we can get the ipython/security directory."""
249 """Testcase to see if we can call get_security_dir without Exceptions."""
31 sdir = genutils.get_security_dir()
250 sdir = genutils.get_security_dir()
32 No newline at end of file
251
252
253 #
254 # Tests for popkey
255 #
256
257 def test_popkey_1():
258 """test_popkey_1, Basic usage test of popkey
259 """
260 dct = dict(a=1, b=2, c=3)
261 nt.assert_equal(genutils.popkey(dct, "a"), 1)
262 nt.assert_equal(dct, dict(b=2, c=3))
263 nt.assert_equal(genutils.popkey(dct, "b"), 2)
264 nt.assert_equal(dct, dict(c=3))
265 nt.assert_equal(genutils.popkey(dct, "c"), 3)
266 nt.assert_equal(dct, dict())
267
268 def test_popkey_2():
269 """test_popkey_2, Test to see that popkey of non occuring keys
270 generates a KeyError exception
271 """
272 dct = dict(a=1, b=2, c=3)
273 nt.assert_raises(KeyError, genutils.popkey, dct, "d")
274
275 def test_popkey_3():
276 """test_popkey_3, Tests to see that popkey calls returns the correct value
277 and that the key/value was removed from the dict.
278 """
279 dct = dict(a=1, b=2, c=3)
280 nt.assert_equal(genutils.popkey(dct, "A", 13), 13)
281 nt.assert_equal(dct, dict(a=1, b=2, c=3))
282 nt.assert_equal(genutils.popkey(dct, "B", 14), 14)
283 nt.assert_equal(dct, dict(a=1, b=2, c=3))
284 nt.assert_equal(genutils.popkey(dct, "C", 15), 15)
285 nt.assert_equal(dct, dict(a=1, b=2, c=3))
286 nt.assert_equal(genutils.popkey(dct, "a"), 1)
287 nt.assert_equal(dct, dict(b=2, c=3))
288 nt.assert_equal(genutils.popkey(dct, "b"), 2)
289 nt.assert_equal(dct, dict(c=3))
290 nt.assert_equal(genutils.popkey(dct, "c"), 3)
291 nt.assert_equal(dct, dict())
@@ -338,6 +338,19 b' Most of the release process is automated by the :file:`release` script in the'
338
338
339 #. Celebrate!
339 #. Celebrate!
340
340
341 Porting to 3.0
342 ==============
343 There are no definite plans for porting of IPython to python 3. The major
344 issue is the dependency on twisted framework for the networking/threading
345 stuff. It is possible that it the traditional IPython interactive console
346 could be ported more easily since it has no such dependency. Here are a few
347 things that will need to be considered when doing such a port especially
348 if we want to have a codebase that works directly on both 2.x and 3.x.
349
350 1. The syntax for exceptions changed (PEP 3110). The old
351 `except exc, var` changed to `except exc as var`. At last
352 count there was 78 occurences of this usage in the codebase
353
341 .. [Bazaar] Bazaar. http://bazaar-vcs.org/
354 .. [Bazaar] Bazaar. http://bazaar-vcs.org/
342 .. [Launchpad] Launchpad. http://www.launchpad.net/ipython
355 .. [Launchpad] Launchpad. http://www.launchpad.net/ipython
343 .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html
356 .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html
General Comments 0
You need to be logged in to leave comments. Login now