##// END OF EJS Templates
Work around a bug in Python's shlex module with unicode input....
Fernando Perez -
Show More
@@ -267,8 +267,35 b' def doctest_time():'
267 267 Wall time: 0.00 s
268 268 """
269 269
270
270 271 def test_doctest_mode():
271 272 "Toggle doctest_mode twice, it should be a no-op and run without error"
272 273 _ip.magic('doctest_mode')
273 274 _ip.magic('doctest_mode')
274 275
276
277 def test_parse_options():
278 """Tests for basic options parsing in magics."""
279 # These are only the most minimal of tests, more should be added later. At
280 # the very least we check that basic text/unicode calls work OK.
281 nt.assert_equal(_ip.parse_options('foo', '')[1], 'foo')
282 nt.assert_equal(_ip.parse_options(u'foo', '')[1], u'foo')
283
284
285 def test_dirops():
286 """Test various directory handling operations."""
287 curpath = lambda :os.path.splitdrive(os.getcwd())[1].replace('\\','/')
288
289 startdir = os.getcwd()
290 ipdir = _ip.ipython_dir
291 try:
292 _ip.magic('cd "%s"' % ipdir)
293 nt.assert_equal(curpath(), ipdir)
294 _ip.magic('cd -')
295 nt.assert_equal(curpath(), startdir)
296 _ip.magic('pushd "%s"' % ipdir)
297 nt.assert_equal(curpath(), ipdir)
298 _ip.magic('popd')
299 nt.assert_equal(curpath(), startdir)
300 finally:
301 os.chdir(startdir)
@@ -136,13 +136,12 b' def arg_split(s, posix=False):'
136 136 function, but with a default of posix=False for splitting, so that quotes
137 137 in inputs are respected."""
138 138
139 # XXX - there may be unicode-related problems here!!! I'm not sure that
140 # shlex is truly unicode-safe, so it might be necessary to do
141 #
142 # s = s.encode(sys.stdin.encoding)
143 #
144 # first, to ensure that shlex gets a normal string. Input from anyone who
145 # knows more about unicode and shlex than I would be good to have here...
139 # Unfortunately, python's shlex module is buggy with unicode input:
140 # http://bugs.python.org/issue1170
141 # At least encoding the input when it's unicode seems to help, but there
142 # may be more problems lurking. Apparently this is fixed in python3.
143 if isinstance(s, unicode):
144 s = s.encode(sys.stdin.encoding)
146 145 lex = shlex.shlex(s, posix=posix)
147 146 lex.whitespace_split = True
148 147 return list(lex)
@@ -18,7 +18,7 b' import sys'
18 18
19 19 import nose.tools as nt
20 20
21 from IPython.utils.process import find_cmd, FindCmdError
21 from IPython.utils.process import find_cmd, FindCmdError, arg_split
22 22 from IPython.testing import decorators as dec
23 23
24 24 #-----------------------------------------------------------------------------
@@ -59,4 +59,10 b' def test_find_cmd_fail():'
59 59 nt.assert_raises(FindCmdError,find_cmd,'asdfasdf')
60 60
61 61
62
62 def test_arg_split():
63 """Ensure that argument lines are correctly split like in a shell."""
64 tests = [['hi', ['hi']],
65 [u'hi', [u'hi']],
66 ]
67 for argstr, argv in tests:
68 nt.assert_equal(arg_split(argstr), argv)
General Comments 0
You need to be logged in to leave comments. Login now