blob: dae2739d051f5f6587d9922e97b4f1134f9e8b9e [file] [log] [blame]
Bram Moolenaara58883b2017-01-29 21:31:09 +01001" Test for python 2 commands.
Bram Moolenaara58883b2017-01-29 21:31:09 +01002
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature python
Bram Moolenaar92fdd1e2020-07-03 18:00:05 +02005CheckFeature quickfix
6
7" NOTE: This will cause errors when run under valgrind.
8" This would require recompiling Python with:
9" ./configure --without-pymalloc
10" See http://svn.python.org/view/python/trunk/Misc/README.valgrind?view=markup
11"
12
13" This function should be called first. This sets up python functions used by
14" the other tests.
15func Test_AAA_python_setup()
16 py << trim EOF
17 import vim
18 import sys
19
20 def emsg(ei):
21 return ei[0].__name__ + ':' + repr(ei[1].args)
22
23 def ee(expr, g=globals(), l=locals()):
24 try:
25 exec(expr, g, l)
26 except:
27 ei = sys.exc_info()
28 msg = emsg(ei)
29 msg = msg.replace('TypeError:(\'argument 1 ', 'TypeError:(\'')
30 if expr.find('None') > -1:
31 msg = msg.replace('TypeError:(\'iteration over non-sequence\',)',
32 'TypeError:("\'NoneType\' object is not iterable",)')
33 if expr.find('FailingNumber') > -1:
34 msg = msg.replace(', not \'FailingNumber\'', '').replace('"', '\'')
35 msg = msg.replace('TypeError:(\'iteration over non-sequence\',)',
36 'TypeError:("\'FailingNumber\' object is not iterable",)')
37 if msg.find('(\'\'') > -1 or msg.find('(\'can\'t') > -1:
38 msg = msg.replace('(\'', '("').replace('\',)', '",)')
39 # Some Python versions say can't, others cannot.
40 if msg.find('can\'t') > -1:
41 msg = msg.replace('can\'t', 'cannot')
42 # Some Python versions use single quote, some double quote
43 if msg.find('"cannot ') > -1:
44 msg = msg.replace('"cannot ', '\'cannot ')
45 if msg.find(' attributes"') > -1:
46 msg = msg.replace(' attributes"', ' attributes\'')
47 if expr == 'fd(self=[])':
48 # HACK: PyMapping_Check changed meaning
49 msg = msg.replace('AttributeError:(\'keys\',)',
50 'TypeError:(\'unable to convert list to vim dictionary\',)')
51 vim.current.buffer.append(expr + ':' + msg)
52 else:
53 vim.current.buffer.append(expr + ':NOT FAILED')
54 EOF
55endfunc
Bram Moolenaara58883b2017-01-29 21:31:09 +010056
57func Test_pydo()
58 " Check deleting lines does not trigger ml_get error.
Bram Moolenaara58883b2017-01-29 21:31:09 +010059 new
60 call setline(1, ['one', 'two', 'three'])
61 pydo vim.command("%d_")
62 bwipe!
63
64 " Check switching to another buffer does not trigger ml_get error.
65 new
66 let wincount = winnr('$')
67 call setline(1, ['one', 'two', 'three'])
68 pydo vim.command("new")
69 call assert_equal(wincount + 1, winnr('$'))
70 bwipe!
71 bwipe!
72endfunc
Bram Moolenaar53901442018-07-25 22:02:36 +020073
74func Test_set_cursor()
75 " Check that setting the cursor position works.
Bram Moolenaar53901442018-07-25 22:02:36 +020076 new
77 call setline(1, ['first line', 'second line'])
78 normal gg
79 pydo vim.current.window.cursor = (1, 5)
80 call assert_equal([1, 6], [line('.'), col('.')])
81
82 " Check that movement after setting cursor position keeps current column.
83 normal j
84 call assert_equal([2, 6], [line('.'), col('.')])
85endfunc
Bram Moolenaar9123c0b2018-12-22 18:59:06 +010086
87func Test_vim_function()
88 " Check creating vim.Function object
Bram Moolenaar9123c0b2018-12-22 18:59:06 +010089
90 func s:foo()
91 return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$')
92 endfunc
93 let name = '<SNR>' . s:foo()
94
95 try
96 py f = vim.bindeval('function("s:foo")')
97 call assert_equal(name, pyeval('f.name'))
98 catch
99 call assert_false(v:exception)
100 endtry
101
102 try
103 py f = vim.Function('\x80\xfdR' + vim.eval('s:foo()'))
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +0200104 call assert_equal(name, 'f.name'->pyeval())
Bram Moolenaar9123c0b2018-12-22 18:59:06 +0100105 catch
106 call assert_false(v:exception)
107 endtry
108
Bram Moolenaar92fdd1e2020-07-03 18:00:05 +0200109 let caught_vim_err = v:false
110 try
111 let x = pyeval('f.abc')
112 catch
113 call assert_match('AttributeError: abc', v:exception)
114 let caught_vim_err = v:true
115 endtry
116 call assert_equal(v:true, caught_vim_err)
117
Bram Moolenaar9123c0b2018-12-22 18:59:06 +0100118 py del f
119 delfunc s:foo
120endfunc
Bram Moolenaar14816ad2019-02-18 22:04:56 +0100121
122func Test_skipped_python_command_does_not_affect_pyxversion()
123 set pyxversion=0
124 if 0
125 python import vim
126 endif
127 call assert_equal(0, &pyxversion) " This assertion would have failed with Vim 8.0.0251. (pyxversion was introduced in 8.0.0251.)
128endfunc
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100129
130func _SetUpHiddenBuffer()
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100131 new
132 edit hidden
133 setlocal bufhidden=hide
134
135 enew
136 let lnum = 0
137 while lnum < 10
138 call append( 1, string( lnum ) )
139 let lnum = lnum + 1
140 endwhile
141 normal G
142
143 call assert_equal( line( '.' ), 11 )
144endfunc
145
Bram Moolenaarbfd36032019-03-30 12:33:13 +0100146func _CleanUpHiddenBuffer()
147 bwipe! hidden
148 bwipe!
149endfunc
150
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100151func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear()
152 call _SetUpHiddenBuffer()
153 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = None
154 call assert_equal( line( '.' ), 11 )
Bram Moolenaarbfd36032019-03-30 12:33:13 +0100155 call _CleanUpHiddenBuffer()
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100156endfunc
157
158func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List()
159 call _SetUpHiddenBuffer()
160 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ]
161 call assert_equal( line( '.' ), 11 )
Bram Moolenaarbfd36032019-03-30 12:33:13 +0100162 call _CleanUpHiddenBuffer()
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100163endfunc
164
165func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str()
166 call _SetUpHiddenBuffer()
167 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = 'test'
168 call assert_equal( line( '.' ), 11 )
Bram Moolenaarbfd36032019-03-30 12:33:13 +0100169 call _CleanUpHiddenBuffer()
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100170endfunc
171
172func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine()
173 call _SetUpHiddenBuffer()
174 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = None
175 call assert_equal( line( '.' ), 11 )
Bram Moolenaarbfd36032019-03-30 12:33:13 +0100176 call _CleanUpHiddenBuffer()
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100177endfunc
178
179func _SetUpVisibleBuffer()
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100180 new
181 let lnum = 0
182 while lnum < 10
183 call append( 1, string( lnum ) )
184 let lnum = lnum + 1
185 endwhile
186 normal G
187 call assert_equal( line( '.' ), 11 )
188endfunc
189
190func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear()
191 call _SetUpVisibleBuffer()
192
193 py vim.current.buffer[:] = None
194 call assert_equal( line( '.' ), 1 )
195
196 bwipe!
197endfunc
198
199func Test_Write_To_Current_Buffer_Fixes_Cursor_List()
200 call _SetUpVisibleBuffer()
201
202 py vim.current.buffer[:] = [ 'test' ]
203 call assert_equal( line( '.' ), 1 )
204
205 bwipe!
Bram Moolenaar92fdd1e2020-07-03 18:00:05 +0200206endfunc
Bram Moolenaar63dbfd32019-03-23 17:41:59 +0100207
208func Test_Write_To_Current_Buffer_Fixes_Cursor_Str()
209 call _SetUpVisibleBuffer()
210
211 py vim.current.buffer[-1] = None
212 call assert_equal( line( '.' ), 10 )
213
214 bwipe!
Bram Moolenaar92fdd1e2020-07-03 18:00:05 +0200215endfunc
Bram Moolenaar7f3a2842019-05-18 15:02:25 +0200216
217func Test_Catch_Exception_Message()
218 try
219 py raise RuntimeError( 'TEST' )
220 catch /.*/
221 call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception )
222 endtry
223endfunc
Bram Moolenaar6c2b7b82020-04-14 20:15:49 +0200224
225" Test for various heredoc syntax
226func Test_python_heredoc()
227 python << END
228s='A'
229END
230 python <<
231s+='B'
232.
233 python << trim END
234 s+='C'
235 END
236 python << trim
237 s+='D'
238 .
Bram Moolenaar6ab09532020-05-01 14:10:13 +0200239 python << trim eof
240 s+='E'
241 eof
242 call assert_equal('ABCDE', pyxeval('s'))
Bram Moolenaar6c2b7b82020-04-14 20:15:49 +0200243endfunc
244
Bram Moolenaar92fdd1e2020-07-03 18:00:05 +0200245" Test for the buffer range object
246func Test_python_range()
247 new
248 call setline(1, ['one', 'two', 'three'])
249 py b = vim.current.buffer
250 py r = b.range(1, 3)
251 call assert_equal(0, pyeval('r.start'))
252 call assert_equal(2, pyeval('r.end'))
253 call assert_equal(['two', 'three'], pyeval('r[1:]'))
254 py r[0] = 'green'
255 call assert_equal(['green', 'two', 'three'], getline(1, '$'))
256 py r[0:2] = ['red', 'blue']
257 call assert_equal(['red', 'blue', 'three'], getline(1, '$'))
258 call assert_equal(['start', 'end', '__members__'], pyeval('r.__members__'))
259
260 let caught_vim_err = v:false
261 try
262 let x = pyeval('r.abc')
263 catch
264 call assert_match('AttributeError: abc', v:exception)
265 let caught_vim_err = v:true
266 endtry
267 call assert_equal(v:true, caught_vim_err)
268
269 close!
270endfunc
271
272" Test for the python tabpage object
273func Test_python_tabpage()
274 tabnew
275 py t = vim.tabpages[1]
276 tabclose
277 let caught_vim_err = v:false
278 try
279 let n = pyeval('t.number')
280 catch
281 call assert_match('vim.error: attempt to refer to deleted tab page',
282 \ v:exception)
283 let caught_vim_err = v:true
284 endtry
285 call assert_equal(v:true, caught_vim_err)
286 %bw!
287endfunc
288
289" Test for the python window object
290func Test_python_window()
291 new
292 py w = vim.current.window
293 close
294 let caught_vim_err = v:false
295 try
296 let n = pyeval('w.number')
297 catch
298 call assert_match('vim.error: attempt to refer to deleted window',
299 \ v:exception)
300 let caught_vim_err = v:true
301 endtry
302 call assert_equal(v:true, caught_vim_err)
303endfunc
304
305" Test for the python List object
306func Test_python_list()
307 let l = [1, 2]
308 py pl = vim.bindeval('l')
309 call assert_equal(['locked', '__members__'], pyeval('pl.__members__'))
310
311 let l = []
312 py l = vim.bindeval('l')
313 py f = vim.bindeval('function("strlen")')
314 " Extending List directly with different types
315 py l.extend([1, "as'd", [1, 2, f, {'a': 1}]])
316 call assert_equal([1, "as'd", [1, 2, function("strlen"), {'a': 1}]], l)
317 call assert_equal([1, 2, function("strlen"), {'a': 1}], l[-1])
318 call assert_fails('echo l[-4]', 'E684:')
319
320 " List assignment
321 py l[0] = 0
322 call assert_equal([0, "as'd", [1, 2, function("strlen"), {'a': 1}]], l)
323 py l[-2] = f
324 call assert_equal([0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]], l)
325endfunc
326
327" Test for the python Dict object
328func Test_python_dict()
329 let d = {}
330 py pd = vim.bindeval('d')
331 call assert_equal(['locked', 'scope', '__members__'],
332 \ pyeval('pd.__members__'))
333endfunc
334
335" Extending Dictionary directly with different types
336func Test_python_dict_extend()
337 let d = {}
338 func d.f()
339 return 1
340 endfunc
341
342 py f = vim.bindeval('function("strlen")')
343 py << trim EOF
344 d = vim.bindeval('d')
345 d['1'] = 'asd'
346 d.update() # Must not do anything, including throwing errors
347 d.update(b = [1, 2, f])
348 d.update((('-1', {'a': 1}),))
349 d.update({'0': -1})
350 dk = d.keys()
351 dv = d.values()
352 di = d.items()
353 cmpfun = lambda a, b: cmp(repr(a), repr(b))
354 dk.sort(cmpfun)
355 dv.sort(cmpfun)
356 di.sort(cmpfun)
357 EOF
358
359 call assert_equal(1, pyeval("d['f'](self={})"))
360 call assert_equal("['-1', '0', '1', 'b', 'f']", pyeval('repr(dk)'))
361 call assert_equal("['asd', -1L, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >]", substitute(pyeval('repr(dv)'),'0x\x\+','','g'))
362 call assert_equal("[('-1', <vim.dictionary object at >), ('0', -1L), ('1', 'asd'), ('b', <vim.list object at >), ('f', <vim.Function '1'>)]", substitute(pyeval('repr(di)'),'0x\x\+','','g'))
363 call assert_equal(['0', '1', 'b', 'f', '-1'], keys(d))
364 call assert_equal("[-1, 'asd', [1, 2, function('strlen')], function('1'), {'a': 1}]", string(values(d)))
365 py del dk
366 py del di
367 py del dv
368endfunc
369
370func Test_python_list_del_items()
371 " removing items with del
372 let l = [0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]]
373 py l = vim.bindeval('l')
374 py del l[2]
375 call assert_equal("[0, function('strlen')]", string(l))
376
377 let l = range(8)
378 py l = vim.bindeval('l')
379 py del l[:3]
380 py del l[1:]
381 call assert_equal([3], l)
382
383 " removing items out of range: silently skip items that don't exist
384
385 " The following two ranges delete nothing as they match empty list:
386 let l = [0, 1, 2, 3]
387 py l = vim.bindeval('l')
388 py del l[2:1]
389 call assert_equal([0, 1, 2, 3], l)
390 py del l[2:2]
391 call assert_equal([0, 1, 2, 3], l)
392 py del l[2:3]
393 call assert_equal([0, 1, 3], l)
394
395 let l = [0, 1, 2, 3]
396 py l = vim.bindeval('l')
397 py del l[2:4]
398 call assert_equal([0, 1], l)
399
400 let l = [0, 1, 2, 3]
401 py l = vim.bindeval('l')
402 py del l[2:5]
403 call assert_equal([0, 1], l)
404
405 let l = [0, 1, 2, 3]
406 py l = vim.bindeval('l')
407 py del l[2:6]
408 call assert_equal([0, 1], l)
409
410 " The following two ranges delete nothing as they match empty list:
411 let l = [0, 1, 2, 3]
412 py l = vim.bindeval('l')
413 py del l[-1:2]
414 call assert_equal([0, 1, 2, 3], l)
415 py del l[-2:2]
416 call assert_equal([0, 1, 2, 3], l)
417 py del l[-3:2]
418 call assert_equal([0, 2, 3], l)
419
420 let l = [0, 1, 2, 3]
421 py l = vim.bindeval('l')
422 py del l[-4:2]
423 call assert_equal([2, 3], l)
424
425 let l = [0, 1, 2, 3]
426 py l = vim.bindeval('l')
427 py del l[-5:2]
428 call assert_equal([2, 3], l)
429
430 let l = [0, 1, 2, 3]
431 py l = vim.bindeval('l')
432 py del l[-6:2]
433 call assert_equal([2, 3], l)
434
435 let l = [0, 1, 2, 3]
436 py l = vim.bindeval('l')
437 py del l[::2]
438 call assert_equal([1, 3], l)
439
440 let l = [0, 1, 2, 3]
441 py l = vim.bindeval('l')
442 py del l[3:0:-2]
443 call assert_equal([0, 2], l)
444
445 let l = [0, 1, 2, 3]
446 py l = vim.bindeval('l')
447 py del l[2:4:-2]
448 let l = [0, 1, 2, 3]
449endfunc
450
451func Test_python_dict_del_items()
452 let d = eval("{'0' : -1, '1' : 'asd', 'b' : [1, 2, function('strlen')], 'f' : function('min'), '-1' : {'a': 1}}")
453 py d = vim.bindeval('d')
454 py del d['-1']
455 py del d['f']
456 call assert_equal([1, 2, function('strlen')], pyeval('d.get(''b'', 1)'))
457 call assert_equal([1, 2, function('strlen')], pyeval('d.pop(''b'')'))
458 call assert_equal(1, pyeval('d.get(''b'', 1)'))
459 call assert_equal('asd', pyeval('d.pop(''1'', 2)'))
460 call assert_equal(2, pyeval('d.pop(''1'', 2)'))
461 call assert_equal('True', pyeval('repr(d.has_key(''0''))'))
462 call assert_equal('False', pyeval('repr(d.has_key(''1''))'))
463 call assert_equal('True', pyeval('repr(''0'' in d)'))
464 call assert_equal('False', pyeval('repr(''1'' in d)'))
465 call assert_equal("['0']", pyeval('repr(list(iter(d)))'))
466 call assert_equal({'0' : -1}, d)
467 call assert_equal("('0', -1L)", pyeval('repr(d.popitem())'))
468 call assert_equal('None', pyeval('repr(d.get(''0''))'))
469 call assert_equal('[]', pyeval('repr(list(iter(d)))'))
470endfunc
471
472" Slice assignment to a list
473func Test_python_slice_assignment()
474 let l = [0, 1, 2, 3]
475 py l = vim.bindeval('l')
476 py l[0:0] = ['a']
477 call assert_equal(['a', 0, 1, 2, 3], l)
478
479 let l = [0, 1, 2, 3]
480 py l = vim.bindeval('l')
481 py l[1:2] = ['b']
482 call assert_equal([0, 'b', 2, 3], l)
483
484 let l = [0, 1, 2, 3]
485 py l = vim.bindeval('l')
486 py l[2:4] = ['c']
487 call assert_equal([0, 1, 'c'], l)
488
489 let l = [0, 1, 2, 3]
490 py l = vim.bindeval('l')
491 py l[4:4] = ['d']
492 call assert_equal([0, 1, 2, 3, 'd'], l)
493
494 let l = [0, 1, 2, 3]
495 py l = vim.bindeval('l')
496 py l[-1:2] = ['e']
497 call assert_equal([0, 1, 2, 'e', 3], l)
498
499 let l = [0, 1, 2, 3]
500 py l = vim.bindeval('l')
501 py l[-10:2] = ['f']
502 call assert_equal(['f', 2, 3], l)
503
504 let l = [0, 1, 2, 3]
505 py l = vim.bindeval('l')
506 py l[2:-10] = ['g']
507 call assert_equal([0, 1, 'g', 2, 3], l)
508
509 let l = []
510 py l = vim.bindeval('l')
511 py l[0:0] = ['h']
512 call assert_equal(['h'], l)
513
514 let l = range(8)
515 py l = vim.bindeval('l')
516 py l[2:6:2] = [10, 20]
517 call assert_equal([0, 1, 10, 3, 20, 5, 6, 7], l)
518
519 let l = range(8)
520 py l = vim.bindeval('l')
521 py l[6:2:-2] = [10, 20]
522 call assert_equal([0, 1, 2, 3, 20, 5, 10, 7], l)
523
524 let l = range(8)
525 py l = vim.bindeval('l')
526 py l[6:2] = ()
527 call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l)
528
529 let l = range(8)
530 py l = vim.bindeval('l')
531 py l[6:2:1] = ()
532 call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l)
533
534 let l = range(8)
535 py l = vim.bindeval('l')
536 py l[2:2:1] = ()
537 call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l)
538endfunc
539
540" Locked variables
541func Test_python_lockedvar()
542 new
543 py cb = vim.current.buffer
544 let l = [0, 1, 2, 3]
545 py l = vim.bindeval('l')
546 lockvar! l
547 py << trim EOF
548 try:
549 l[2]='i'
550 except vim.error:
551 cb.append('l[2] threw vim.error: ' + emsg(sys.exc_info()))
552 EOF
553 call assert_equal(['', "l[2] threw vim.error: error:('list is locked',)"],
554 \ getline(1, '$'))
555 call assert_equal([0, 1, 2, 3], l)
556 unlockvar! l
557 close!
558endfunc
559
560" Test for calling a function
561func Test_python_function_call()
562 func New(...)
563 return ['NewStart'] + a:000 + ['NewEnd']
564 endfunc
565
566 func DictNew(...) dict
567 return ['DictNewStart'] + a:000 + ['DictNewEnd', self]
568 endfunc
569
570 new
571 let l = [function('New'), function('DictNew')]
572 py l = vim.bindeval('l')
573 py l.extend(list(l[0](1, 2, 3)))
574 call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd'], l)
575 py l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
576 call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}], l)
577 py l.extend([l[0].name])
578 call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New'], l)
579 py ee('l[1](1, 2, 3)')
580 call assert_equal("l[1](1, 2, 3):error:('Vim:E725: Calling dict function without Dictionary: DictNew',)", getline(2))
581 %d
582 py f = l[0]
583 delfunction New
584 py ee('f(1, 2, 3)')
585 call assert_equal("f(1, 2, 3):error:('Vim:E117: Unknown function: New',)", getline(2))
586 close!
587 delfunction DictNew
588endfunc
589
590func Test_python_float()
591 CheckFeature float
592 let l = [0.0]
593 py l = vim.bindeval('l')
594 py l.extend([0.0])
595 call assert_equal([0.0, 0.0], l)
596endfunc
597
598" Test for Dict key errors
599func Test_python_dict_key_error()
600 let messages = []
601 py << trim EOF
602 d = vim.bindeval('{}')
603 m = vim.bindeval('messages')
604 def em(expr, g=globals(), l=locals()):
605 try:
606 exec(expr, g, l)
607 except:
608 m.extend([sys.exc_type.__name__])
609
610 em('d["abc1"]')
611 em('d["abc1"]="\\0"')
612 em('d["abc1"]=vim')
613 em('d[""]=1')
614 em('d["a\\0b"]=1')
615 em('d[u"a\\0b"]=1')
616 em('d.pop("abc1")')
617 em('d.popitem()')
618 del em
619 del m
620 EOF
621
622 call assert_equal(['KeyError', 'TypeError', 'TypeError', 'ValueError',
623 \ 'TypeError', 'TypeError', 'KeyError', 'KeyError'], messages)
624 unlet messages
625endfunc
626
627" Test for locked and scope attributes
628func Test_python_lock_scope_attr()
629 let d = {} | let dl = {} | lockvar dl
630 let res = []
631 for s in split("d dl v: g:")
632 let name = tr(s, ':', 's')
633 execute 'py ' .. name .. ' = vim.bindeval("' .. s .. '")'
634 call add(res, s .. ' : ' .. join(map(['locked', 'scope'],
635 \ 'v:val .. ":" .. pyeval(name .. "." .. v:val)'), ';'))
636 endfor
637 call assert_equal(['d : locked:0;scope:0', 'dl : locked:1;scope:0',
638 \ 'v: : locked:2;scope:1', 'g: : locked:0;scope:2'], res)
639
640 silent! let d.abc2 = 1
641 silent! let dl.abc3 = 1
642 py d.locked = True
643 py dl.locked = False
644 silent! let d.def = 1
645 silent! let dl.def = 1
646 call assert_equal({'abc2': 1}, d)
647 call assert_equal({'def': 1}, dl)
648 unlet d dl
649
650 let l = [] | let ll = [] | lockvar ll
651 let res = []
652 for s in split("l ll")
653 let name = tr(s, ':', 's')
654 execute 'py ' .. name .. '=vim.bindeval("' .. s .. '")'
655 call add(res, s .. ' : locked:' .. pyeval(name .. '.locked'))
656 endfor
657 call assert_equal(['l : locked:0', 'll : locked:1'], res)
658
659 silent! call extend(l, [0])
660 silent! call extend(ll, [0])
661 py l.locked = True
662 py ll.locked = False
663 silent! call extend(l, [1])
664 silent! call extend(ll, [1])
665 call assert_equal([0], l)
666 call assert_equal([1], ll)
667 unlet l ll
668endfunc
669
670" Test for pyeval()
671func Test_python_pyeval()
672 let l = pyeval('range(3)')
673 call assert_equal([0, 1, 2], l)
674
675 let d = pyeval('{"a": "b", "c": 1, "d": ["e"]}')
676 call assert_equal([['a', 'b'], ['c', 1], ['d', ['e']]], sort(items(d)))
677
678 let v:errmsg = ''
679 call assert_equal(v:none, pyeval('None'))
680 call assert_equal('', v:errmsg)
681
682 if has('float')
683 call assert_equal(0.0, pyeval('0.0'))
684 endif
685
686 " Invalid values:
687 let caught_859 = 0
688 try
689 let v = pyeval('"\0"')
690 catch /E859:/
691 let caught_859 = 1
692 endtry
693 call assert_equal(1, caught_859)
694
695 let caught_859 = 0
696 try
697 let v = pyeval('{"\0" : 1}')
698 catch /E859:/
699 let caught_859 = 1
700 endtry
701 call assert_equal(1, caught_859)
702
703 let caught_nameerr = 0
704 try
705 let v = pyeval("undefined_name")
706 catch /NameError: name 'undefined_name'/
707 let caught_nameerr = 1
708 endtry
709 call assert_equal(1, caught_nameerr)
710
711 let caught_859 = 0
712 try
713 let v = pyeval("vim")
714 catch /E859:/
715 let caught_859 = 1
716 endtry
717 call assert_equal(1, caught_859)
718endfunc
719
720" threading
721" Running pydo command (Test_pydo) before this test, stops the python thread
722" from running. So this test should be run before the pydo test
723func Test_aaa_python_threading()
724 let l = [0]
725 py l = vim.bindeval('l')
726 py << trim EOF
727 import threading
728 import time
729
730 class T(threading.Thread):
731 def __init__(self):
732 threading.Thread.__init__(self)
733 self.t = 0
734 self.running = True
735
736 def run(self):
737 while self.running:
738 self.t += 1
739 time.sleep(0.1)
740
741 t = T()
742 del T
743 t.start()
744 EOF
745
746 sleep 1
747 py t.running = False
748 py t.join()
749
750 " Check if the background thread is working. Count should be 10, but on a
751 " busy system (AppVeyor) it can be much lower.
752 py l[0] = t.t > 4
753 py del time
754 py del threading
755 py del t
756 call assert_equal([1], l)
757endfunc
758
759" settrace
760func Test_python_settrace()
761 let l = []
762 py l = vim.bindeval('l')
763 py << trim EOF
764 import sys
765
766 def traceit(frame, event, arg):
767 global l
768 if event == "line":
769 l.extend([frame.f_lineno])
770 return traceit
771
772 def trace_main():
773 for i in range(5):
774 pass
775 EOF
776 py sys.settrace(traceit)
777 py trace_main()
778 py sys.settrace(None)
779 py del traceit
780 py del trace_main
781 call assert_equal([1, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 1], l)
782endfunc
783
784" Slice
785func Test_python_list_slice()
786 py ll = vim.bindeval('[0, 1, 2, 3, 4, 5]')
787 py l = ll[:4]
788 call assert_equal([0, 1, 2, 3], pyeval('l'))
789 py l = ll[2:]
790 call assert_equal([2, 3, 4, 5], pyeval('l'))
791 py l = ll[:-4]
792 call assert_equal([0, 1], pyeval('l'))
793 py l = ll[-2:]
794 call assert_equal([4, 5], pyeval('l'))
795 py l = ll[2:4]
796 call assert_equal([2, 3], pyeval('l'))
797 py l = ll[4:2]
798 call assert_equal([], pyeval('l'))
799 py l = ll[-4:-2]
800 call assert_equal([2, 3], pyeval('l'))
801 py l = ll[-2:-4]
802 call assert_equal([], pyeval('l'))
803 py l = ll[:]
804 call assert_equal([0, 1, 2, 3, 4, 5], pyeval('l'))
805 py l = ll[0:6]
806 call assert_equal([0, 1, 2, 3, 4, 5], pyeval('l'))
807 py l = ll[-10:10]
808 call assert_equal([0, 1, 2, 3, 4, 5], pyeval('l'))
809 py l = ll[4:2:-1]
810 call assert_equal([4, 3], pyeval('l'))
811 py l = ll[::2]
812 call assert_equal([0, 2, 4], pyeval('l'))
813 py l = ll[4:2:1]
814 call assert_equal([], pyeval('l'))
815 py del l
816endfunc
817
818" Vars
819func Test_python_vars()
820 let g:foo = 'bac'
821 let w:abc3 = 'def'
822 let b:baz = 'bar'
823 let t:bar = 'jkl'
824 try
825 throw "Abc"
826 catch /Abc/
827 call assert_equal('Abc', pyeval('vim.vvars[''exception'']'))
828 endtry
829 call assert_equal('bac', pyeval('vim.vars[''foo'']'))
830 call assert_equal('def', pyeval('vim.current.window.vars[''abc3'']'))
831 call assert_equal('bar', pyeval('vim.current.buffer.vars[''baz'']'))
832 call assert_equal('jkl', pyeval('vim.current.tabpage.vars[''bar'']'))
833endfunc
834
835" Options
836" paste: boolean, global
837" previewheight number, global
838" operatorfunc: string, global
839" number: boolean, window-local
840" numberwidth: number, window-local
841" colorcolumn: string, window-local
842" statusline: string, window-local/global
843" autoindent: boolean, buffer-local
844" shiftwidth: number, buffer-local
845" omnifunc: string, buffer-local
846" preserveindent: boolean, buffer-local/global
847" path: string, buffer-local/global
848func Test_python_opts()
849 let g:res = []
850 let g:bufs = [bufnr('%')]
851 new
852 let g:bufs += [bufnr('%')]
853 vnew
854 let g:bufs += [bufnr('%')]
855 wincmd j
856 vnew
857 let g:bufs += [bufnr('%')]
858 wincmd l
859
860 func RecVars(opt)
861 let gval = string(eval('&g:' .. a:opt))
862 let wvals = join(map(range(1, 4),
863 \ 'v:val .. ":" .. string(getwinvar(v:val, "&" .. a:opt))'))
864 let bvals = join(map(copy(g:bufs),
865 \ 'v:val .. ":" .. string(getbufvar(v:val, "&" .. a:opt))'))
866 call add(g:res, ' G: ' .. gval)
867 call add(g:res, ' W: ' .. wvals)
868 call add(g:res, ' B: ' .. wvals)
869 endfunc
870
871 py << trim EOF
872 def e(s, g=globals(), l=locals()):
873 try:
874 exec(s, g, l)
875 except:
876 vim.command('return ' + repr(sys.exc_type.__name__))
877
878 def ev(s, g=globals(), l=locals()):
879 try:
880 return eval(s, g, l)
881 except:
882 vim.command('let exc=' + repr(sys.exc_type.__name__))
883 return 0
884 EOF
885
886 func E(s)
887 python e(vim.eval('a:s'))
888 endfunc
889
890 func Ev(s)
891 let r = pyeval('ev(vim.eval("a:s"))')
892 if exists('exc')
893 throw exc
894 endif
895 return r
896 endfunc
897
898 py gopts1 = vim.options
899 py wopts1 = vim.windows[2].options
900 py wopts2 = vim.windows[0].options
901 py wopts3 = vim.windows[1].options
902 py bopts1 = vim.buffers[vim.bindeval("g:bufs")[2]].options
903 py bopts2 = vim.buffers[vim.bindeval("g:bufs")[1]].options
904 py bopts3 = vim.buffers[vim.bindeval("g:bufs")[0]].options
905 call add(g:res, 'wopts iters equal: ' ..
906 \ pyeval('list(wopts1) == list(wopts2)'))
907 call add(g:res, 'bopts iters equal: ' ..
908 \ pyeval('list(bopts1) == list(bopts2)'))
909 py gset = set(iter(gopts1))
910 py wset = set(iter(wopts1))
911 py bset = set(iter(bopts1))
912
913 set path=.,..,,
914 let lst = []
915 let lst += [['paste', 1, 0, 1, 2, 1, 1, 0]]
916 let lst += [['previewheight', 5, 1, 6, 'a', 0, 1, 0]]
917 let lst += [['operatorfunc', 'A', 'B', 'C', 2, 0, 1, 0]]
918 let lst += [['number', 0, 1, 1, 0, 1, 0, 1]]
919 let lst += [['numberwidth', 2, 3, 5, -100, 0, 0, 1]]
920 let lst += [['colorcolumn', '+1', '+2', '+3', 'abc4', 0, 0, 1]]
921 let lst += [['statusline', '1', '2', '4', 0, 0, 1, 1]]
922 let lst += [['autoindent', 0, 1, 1, 2, 1, 0, 2]]
923 let lst += [['shiftwidth', 0, 2, 1, 3, 0, 0, 2]]
924 let lst += [['omnifunc', 'A', 'B', 'C', 1, 0, 0, 2]]
925 let lst += [['preserveindent', 0, 1, 1, 2, 1, 1, 2]]
926 let lst += [['path', '.,,', ',,', '.', 0, 0, 1, 2]]
927 for [oname, oval1, oval2, oval3, invval, bool, global, local] in lst
928 py oname = vim.eval('oname')
929 py oval1 = vim.bindeval('oval1')
930 py oval2 = vim.bindeval('oval2')
931 py oval3 = vim.bindeval('oval3')
932 if invval is 0 || invval is 1
933 py invval = bool(vim.bindeval('invval'))
934 else
935 py invval = vim.bindeval('invval')
936 endif
937 if bool
938 py oval1 = bool(oval1)
939 py oval2 = bool(oval2)
940 py oval3 = bool(oval3)
941 endif
942 call add(g:res, '>>> ' .. oname)
943 call add(g:res, ' g/w/b:' .. pyeval('oname in gset') .. '/' ..
944 \ pyeval('oname in wset') .. '/' .. pyeval('oname in bset'))
945 call add(g:res, ' g/w/b (in):' .. pyeval('oname in gopts1') .. '/' ..
946 \ pyeval('oname in wopts1') .. '/' .. pyeval('oname in bopts1'))
947 for v in ['gopts1', 'wopts1', 'bopts1']
948 try
949 call add(g:res, ' p/' .. v .. ': ' .. Ev('repr(' .. v .. '[''' .. oname .. '''])'))
950 catch
951 call add(g:res, ' p/' .. v .. '! ' .. v:exception)
952 endtry
953 let r = E(v .. '[''' .. oname .. ''']=invval')
954 if r isnot 0
955 call add(g:res, ' inv: ' .. string(invval) .. '! ' .. r)
956 endif
957 for vv in (v is# 'gopts1' ? [v] : [v, v[:-2] .. '2', v[:-2] .. '3'])
958 let val = substitute(vv, '^.opts', 'oval', '')
959 let r = E(vv .. '[''' .. oname .. ''']=' .. val)
960 if r isnot 0
961 call add(g:res, ' ' .. vv .. '! ' .. r)
962 endif
963 endfor
964 endfor
965 call RecVars(oname)
966 for v in ['wopts3', 'bopts3']
967 let r = E('del ' .. v .. '["' .. oname .. '"]')
968 if r isnot 0
969 call add(g:res, ' del ' .. v .. '! ' .. r)
970 endif
971 endfor
972 call RecVars(oname)
973 endfor
974 delfunction RecVars
975 delfunction E
976 delfunction Ev
977 py del ev
978 py del e
979 only
980 for buf in g:bufs[1:]
981 execute 'bwipeout!' buf
982 endfor
983 py del gopts1
984 py del wopts1
985 py del wopts2
986 py del wopts3
987 py del bopts1
988 py del bopts2
989 py del bopts3
990 py del oval1
991 py del oval2
992 py del oval3
993 py del oname
994 py del invval
995
996 let expected =<< trim END
997 wopts iters equal: 1
998 bopts iters equal: 1
999 >>> paste
1000 g/w/b:1/0/0
1001 g/w/b (in):1/0/0
1002 p/gopts1: False
1003 p/wopts1! KeyError
1004 inv: 2! KeyError
1005 wopts1! KeyError
1006 wopts2! KeyError
1007 wopts3! KeyError
1008 p/bopts1! KeyError
1009 inv: 2! KeyError
1010 bopts1! KeyError
1011 bopts2! KeyError
1012 bopts3! KeyError
1013 G: 1
1014 W: 1:1 2:1 3:1 4:1
1015 B: 1:1 2:1 3:1 4:1
1016 del wopts3! KeyError
1017 del bopts3! KeyError
1018 G: 1
1019 W: 1:1 2:1 3:1 4:1
1020 B: 1:1 2:1 3:1 4:1
1021 >>> previewheight
1022 g/w/b:1/0/0
1023 g/w/b (in):1/0/0
1024 p/gopts1: 12
1025 inv: 'a'! TypeError
1026 p/wopts1! KeyError
1027 inv: 'a'! KeyError
1028 wopts1! KeyError
1029 wopts2! KeyError
1030 wopts3! KeyError
1031 p/bopts1! KeyError
1032 inv: 'a'! KeyError
1033 bopts1! KeyError
1034 bopts2! KeyError
1035 bopts3! KeyError
1036 G: 5
1037 W: 1:5 2:5 3:5 4:5
1038 B: 1:5 2:5 3:5 4:5
1039 del wopts3! KeyError
1040 del bopts3! KeyError
1041 G: 5
1042 W: 1:5 2:5 3:5 4:5
1043 B: 1:5 2:5 3:5 4:5
1044 >>> operatorfunc
1045 g/w/b:1/0/0
1046 g/w/b (in):1/0/0
1047 p/gopts1: ''
1048 inv: 2! TypeError
1049 p/wopts1! KeyError
1050 inv: 2! KeyError
1051 wopts1! KeyError
1052 wopts2! KeyError
1053 wopts3! KeyError
1054 p/bopts1! KeyError
1055 inv: 2! KeyError
1056 bopts1! KeyError
1057 bopts2! KeyError
1058 bopts3! KeyError
1059 G: 'A'
1060 W: 1:'A' 2:'A' 3:'A' 4:'A'
1061 B: 1:'A' 2:'A' 3:'A' 4:'A'
1062 del wopts3! KeyError
1063 del bopts3! KeyError
1064 G: 'A'
1065 W: 1:'A' 2:'A' 3:'A' 4:'A'
1066 B: 1:'A' 2:'A' 3:'A' 4:'A'
1067 >>> number
1068 g/w/b:0/1/0
1069 g/w/b (in):0/1/0
1070 p/gopts1! KeyError
1071 inv: 0! KeyError
1072 gopts1! KeyError
1073 p/wopts1: False
1074 p/bopts1! KeyError
1075 inv: 0! KeyError
1076 bopts1! KeyError
1077 bopts2! KeyError
1078 bopts3! KeyError
1079 G: 0
1080 W: 1:1 2:1 3:0 4:0
1081 B: 1:1 2:1 3:0 4:0
1082 del wopts3! ValueError
1083 del bopts3! KeyError
1084 G: 0
1085 W: 1:1 2:1 3:0 4:0
1086 B: 1:1 2:1 3:0 4:0
1087 >>> numberwidth
1088 g/w/b:0/1/0
1089 g/w/b (in):0/1/0
1090 p/gopts1! KeyError
1091 inv: -100! KeyError
1092 gopts1! KeyError
1093 p/wopts1: 4
1094 inv: -100! error
1095 p/bopts1! KeyError
1096 inv: -100! KeyError
1097 bopts1! KeyError
1098 bopts2! KeyError
1099 bopts3! KeyError
1100 G: 4
1101 W: 1:3 2:5 3:2 4:4
1102 B: 1:3 2:5 3:2 4:4
1103 del wopts3! ValueError
1104 del bopts3! KeyError
1105 G: 4
1106 W: 1:3 2:5 3:2 4:4
1107 B: 1:3 2:5 3:2 4:4
1108 >>> colorcolumn
1109 g/w/b:0/1/0
1110 g/w/b (in):0/1/0
1111 p/gopts1! KeyError
1112 inv: 'abc4'! KeyError
1113 gopts1! KeyError
1114 p/wopts1: ''
1115 inv: 'abc4'! error
1116 p/bopts1! KeyError
1117 inv: 'abc4'! KeyError
1118 bopts1! KeyError
1119 bopts2! KeyError
1120 bopts3! KeyError
1121 G: ''
1122 W: 1:'+2' 2:'+3' 3:'+1' 4:''
1123 B: 1:'+2' 2:'+3' 3:'+1' 4:''
1124 del wopts3! ValueError
1125 del bopts3! KeyError
1126 G: ''
1127 W: 1:'+2' 2:'+3' 3:'+1' 4:''
1128 B: 1:'+2' 2:'+3' 3:'+1' 4:''
1129 >>> statusline
1130 g/w/b:1/1/0
1131 g/w/b (in):1/1/0
1132 p/gopts1: ''
1133 inv: 0! TypeError
1134 p/wopts1: None
1135 inv: 0! TypeError
1136 p/bopts1! KeyError
1137 inv: 0! KeyError
1138 bopts1! KeyError
1139 bopts2! KeyError
1140 bopts3! KeyError
1141 G: '1'
1142 W: 1:'2' 2:'4' 3:'1' 4:'1'
1143 B: 1:'2' 2:'4' 3:'1' 4:'1'
1144 del bopts3! KeyError
1145 G: '1'
1146 W: 1:'2' 2:'1' 3:'1' 4:'1'
1147 B: 1:'2' 2:'1' 3:'1' 4:'1'
1148 >>> autoindent
1149 g/w/b:0/0/1
1150 g/w/b (in):0/0/1
1151 p/gopts1! KeyError
1152 inv: 2! KeyError
1153 gopts1! KeyError
1154 p/wopts1! KeyError
1155 inv: 2! KeyError
1156 wopts1! KeyError
1157 wopts2! KeyError
1158 wopts3! KeyError
1159 p/bopts1: False
1160 G: 0
1161 W: 1:0 2:1 3:0 4:1
1162 B: 1:0 2:1 3:0 4:1
1163 del wopts3! KeyError
1164 del bopts3! ValueError
1165 G: 0
1166 W: 1:0 2:1 3:0 4:1
1167 B: 1:0 2:1 3:0 4:1
1168 >>> shiftwidth
1169 g/w/b:0/0/1
1170 g/w/b (in):0/0/1
1171 p/gopts1! KeyError
1172 inv: 3! KeyError
1173 gopts1! KeyError
1174 p/wopts1! KeyError
1175 inv: 3! KeyError
1176 wopts1! KeyError
1177 wopts2! KeyError
1178 wopts3! KeyError
1179 p/bopts1: 8
1180 G: 8
1181 W: 1:0 2:2 3:8 4:1
1182 B: 1:0 2:2 3:8 4:1
1183 del wopts3! KeyError
1184 del bopts3! ValueError
1185 G: 8
1186 W: 1:0 2:2 3:8 4:1
1187 B: 1:0 2:2 3:8 4:1
1188 >>> omnifunc
1189 g/w/b:0/0/1
1190 g/w/b (in):0/0/1
1191 p/gopts1! KeyError
1192 inv: 1! KeyError
1193 gopts1! KeyError
1194 p/wopts1! KeyError
1195 inv: 1! KeyError
1196 wopts1! KeyError
1197 wopts2! KeyError
1198 wopts3! KeyError
1199 p/bopts1: ''
1200 inv: 1! TypeError
1201 G: ''
1202 W: 1:'A' 2:'B' 3:'' 4:'C'
1203 B: 1:'A' 2:'B' 3:'' 4:'C'
1204 del wopts3! KeyError
1205 del bopts3! ValueError
1206 G: ''
1207 W: 1:'A' 2:'B' 3:'' 4:'C'
1208 B: 1:'A' 2:'B' 3:'' 4:'C'
1209 >>> preserveindent
1210 g/w/b:0/0/1
1211 g/w/b (in):0/0/1
1212 p/gopts1! KeyError
1213 inv: 2! KeyError
1214 gopts1! KeyError
1215 p/wopts1! KeyError
1216 inv: 2! KeyError
1217 wopts1! KeyError
1218 wopts2! KeyError
1219 wopts3! KeyError
1220 p/bopts1: False
1221 G: 0
1222 W: 1:0 2:1 3:0 4:1
1223 B: 1:0 2:1 3:0 4:1
1224 del wopts3! KeyError
1225 del bopts3! ValueError
1226 G: 0
1227 W: 1:0 2:1 3:0 4:1
1228 B: 1:0 2:1 3:0 4:1
1229 >>> path
1230 g/w/b:1/0/1
1231 g/w/b (in):1/0/1
1232 p/gopts1: '.,..,,'
1233 inv: 0! TypeError
1234 p/wopts1! KeyError
1235 inv: 0! KeyError
1236 wopts1! KeyError
1237 wopts2! KeyError
1238 wopts3! KeyError
1239 p/bopts1: None
1240 inv: 0! TypeError
1241 G: '.,,'
1242 W: 1:'.,,' 2:',,' 3:'.,,' 4:'.'
1243 B: 1:'.,,' 2:',,' 3:'.,,' 4:'.'
1244 del wopts3! KeyError
1245 G: '.,,'
1246 W: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,'
1247 B: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,'
1248 END
1249
1250 call assert_equal(expected, g:res)
1251 unlet g:res
1252endfunc
1253
1254" Test for vim.buffer object
1255func Test_python_buffer()
1256 new
1257 call setline(1, "Hello\nWorld")
1258 call assert_fails("let x = pyeval('vim.current.buffer[0]')", 'E859:')
1259 %bw!
1260
1261 edit Xfile1
1262 let bnr1 = bufnr()
1263 py cb = vim.current.buffer
1264 vnew Xfile2
1265 let bnr2 = bufnr()
1266 call setline(1, ['First line', 'Second line', 'Third line'])
1267 py b = vim.current.buffer
1268 wincmd w
1269
1270 " Tests BufferAppend and BufferItem
1271 py cb.append(b[0])
1272 call assert_equal(['First line'], getbufline(bnr1, 2))
1273 %d
1274
1275 " Tests BufferSlice and BufferAssSlice
1276 py cb.append('abc5') # Will be overwritten
1277 py cb[-1:] = b[:-2]
1278 call assert_equal(['First line'], getbufline(bnr1, 2))
1279 %d
1280
1281 " Test BufferLength and BufferAssSlice
1282 py cb.append('def') # Will not be overwritten
1283 py cb[len(cb):] = b[:]
1284 call assert_equal(['def', 'First line', 'Second line', 'Third line'],
1285 \ getbufline(bnr1, 2, '$'))
1286 %d
1287
1288 " Test BufferAssItem and BufferMark
1289 call setbufline(bnr1, 1, ['one', 'two', 'three'])
1290 call cursor(1, 3)
1291 normal ma
1292 py cb.append('ghi') # Will be overwritten
1293 py cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
1294 call assert_equal(['(3, 2)'], getbufline(bnr1, 4))
1295 %d
1296
1297 " Test BufferRepr
1298 py cb.append(repr(cb) + repr(b))
1299 call assert_equal(['<buffer Xfile1><buffer Xfile2>'], getbufline(bnr1, 2))
1300 %d
1301
1302 " Modify foreign buffer
1303 py << trim EOF
1304 b.append('foo')
1305 b[0]='bar'
1306 b[0:0]=['baz']
1307 vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
1308 EOF
1309 call assert_equal(['baz', 'bar', 'Second line', 'Third line', 'foo'],
1310 \ getbufline(bnr2, 1, '$'))
1311 %d
1312
1313 " Test assigning to name property
1314 augroup BUFS
1315 autocmd BufFilePost * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePost:' + vim.eval('bufnr("%")'))
1316 autocmd BufFilePre * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePre:' + vim.eval('bufnr("%")'))
1317 augroup END
1318 py << trim EOF
1319 import os
1320 old_name = cb.name
1321 cb.name = 'foo'
1322 cb.append(cb.name[-11:].replace(os.path.sep, '/'))
1323 b.name = 'bar'
1324 cb.append(b.name[-11:].replace(os.path.sep, '/'))
1325 cb.name = old_name
1326 cb.append(cb.name[-14:].replace(os.path.sep, '/'))
1327 del old_name
1328 EOF
1329 call assert_equal([bnr1 .. ':BufFilePre:' .. bnr1,
1330 \ bnr1 .. ':BufFilePost:' .. bnr1,
1331 \ 'testdir/foo',
1332 \ bnr2 .. ':BufFilePre:' .. bnr2,
1333 \ bnr2 .. ':BufFilePost:' .. bnr2,
1334 \ 'testdir/bar',
1335 \ bnr1 .. ':BufFilePre:' .. bnr1,
1336 \ bnr1 .. ':BufFilePost:' .. bnr1,
1337 \ 'testdir/Xfile1'], getbufline(bnr1, 2, '$'))
1338 %d
1339
1340 " Test CheckBuffer
1341 py << trim EOF
1342 for _b in vim.buffers:
1343 if _b is not cb:
1344 vim.command('bwipeout! ' + str(_b.number))
1345 del _b
1346 cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
1347 EOF
1348 call assert_equal('valid: b:False, cb:True', getline(2))
1349 %d
1350
1351 py << trim EOF
1352 for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc6")', 'b.name = "!"'):
1353 try:
1354 exec(expr)
1355 except vim.error:
1356 pass
1357 else:
1358 # Usually a SEGV here
1359 # Should not happen in any case
1360 cb.append('No exception for ' + expr)
1361 vim.command('cd .')
1362 del b
1363 EOF
1364 call assert_equal([''], getline(1, '$'))
1365
1366 augroup BUFS
1367 autocmd!
1368 augroup END
1369 augroup! BUFS
1370 %bw!
1371endfunc
1372
1373" Test vim.buffers object
1374func Test_python_buffers()
1375 %bw!
1376 edit Xfile
1377 py cb = vim.current.buffer
1378 set hidden
1379 edit a
1380 buffer #
1381 edit b
1382 buffer #
1383 edit c
1384 buffer #
1385 py << trim EOF
1386 try:
1387 from __builtin__ import next
1388 except ImportError:
1389 next = lambda o: o.next()
1390 # Check GCing iterator that was not fully exhausted
1391 i = iter(vim.buffers)
1392 cb.append('i:' + str(next(i)))
1393 # and also check creating more than one iterator at a time
1394 i2 = iter(vim.buffers)
1395 cb.append('i2:' + str(next(i2)))
1396 cb.append('i:' + str(next(i)))
1397 # The following should trigger GC and not cause any problems
1398 del i
1399 del i2
1400 i3 = iter(vim.buffers)
1401 cb.append('i3:' + str(next(i3)))
1402 del i3
1403 EOF
1404 call assert_equal(['i:<buffer Xfile>',
1405 \ 'i2:<buffer Xfile>', 'i:<buffer a>', 'i3:<buffer Xfile>'],
1406 \ getline(2, '$'))
1407 %d
1408
1409 py << trim EOF
1410 prevnum = 0
1411 for b in vim.buffers:
1412 # Check buffer order
1413 if prevnum >= b.number:
1414 cb.append('!!! Buffer numbers not in strictly ascending order')
1415 # Check indexing: vim.buffers[number].number == number
1416 cb.append(str(b.number) + ':' + repr(vim.buffers[b.number]) + \
1417 '=' + repr(b))
1418 prevnum = b.number
1419 del prevnum
1420
1421 cb.append(str(len(vim.buffers)))
1422 EOF
1423 call assert_equal([bufnr('Xfile') .. ':<buffer Xfile>=<buffer Xfile>',
1424 \ bufnr('a') .. ':<buffer a>=<buffer a>',
1425 \ bufnr('b') .. ':<buffer b>=<buffer b>',
1426 \ bufnr('c') .. ':<buffer c>=<buffer c>', '4'], getline(2, '$'))
1427 %d
1428
1429 py << trim EOF
1430 bnums = list(map(lambda b: b.number, vim.buffers))[1:]
1431
1432 # Test wiping out buffer with existing iterator
1433 i4 = iter(vim.buffers)
1434 cb.append('i4:' + str(next(i4)))
1435 vim.command('bwipeout! ' + str(bnums.pop(0)))
1436 try:
1437 next(i4)
1438 except vim.error:
1439 pass
1440 else:
1441 cb.append('!!!! No vim.error')
1442 i4 = iter(vim.buffers)
1443 vim.command('bwipeout! ' + str(bnums.pop(-1)))
1444 vim.command('bwipeout! ' + str(bnums.pop(-1)))
1445 cb.append('i4:' + str(next(i4)))
1446 try:
1447 next(i4)
1448 except StopIteration:
1449 cb.append('StopIteration')
1450 del i4
1451 del bnums
1452 EOF
1453 call assert_equal(['i4:<buffer Xfile>',
1454 \ 'i4:<buffer Xfile>', 'StopIteration'], getline(2, '$'))
1455 %bw!
1456endfunc
1457
1458" Test vim.{tabpage,window}list and vim.{tabpage,window} objects
1459func Test_python_tabpage_window()
1460 %bw
1461 edit Xfile
1462 py cb = vim.current.buffer
1463 tabnew 0
1464 tabnew 1
1465 vnew a.1
1466 tabnew 2
1467 vnew a.2
1468 vnew b.2
1469 vnew c.2
1470
1471 py << trim EOF
1472 cb.append('Number of tabs: ' + str(len(vim.tabpages)))
1473 cb.append('Current tab pages:')
1474 def W(w):
1475 if repr(w).find('(unknown)') != -1:
1476 return '<window object (unknown)>'
1477 else:
1478 return repr(w)
1479
1480 start = len(cb)
1481
1482 def Cursor(w):
1483 if w.buffer is cb:
1484 return repr((start - w.cursor[0], w.cursor[1]))
1485 else:
1486 return repr(w.cursor)
1487
1488 for t in vim.tabpages:
1489 cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + \
1490 str(len(t.windows)) + ' windows, current is ' + W(t.window))
1491 cb.append(' Windows:')
1492 for w in t.windows:
1493 cb.append(' ' + W(w) + '(' + str(w.number) + ')' + \
1494 ': displays buffer ' + repr(w.buffer) + \
1495 '; cursor is at ' + Cursor(w))
1496 # Other values depend on the size of the terminal, so they are checked
1497 # partly:
1498 for attr in ('height', 'row', 'width', 'col'):
1499 try:
1500 aval = getattr(w, attr)
1501 if type(aval) is not long:
1502 raise TypeError
1503 if aval < 0:
1504 raise ValueError
1505 except Exception:
1506 cb.append('!!!!!! Error while getting attribute ' + attr + \
1507 ': ' + sys.exc_type.__name__)
1508 del aval
1509 del attr
1510 w.cursor = (len(w.buffer), 0)
1511 del W
1512 del Cursor
1513 cb.append('Number of windows in current tab page: ' + \
1514 str(len(vim.windows)))
1515 if list(vim.windows) != list(vim.current.tabpage.windows):
1516 cb.append('!!!!!! Windows differ')
1517 EOF
1518
1519 let expected =<< trim END
1520 Number of tabs: 4
1521 Current tab pages:
1522 <tabpage 0>(1): 1 windows, current is <window object (unknown)>
1523 Windows:
1524 <window object (unknown)>(1): displays buffer <buffer Xfile>; cursor is at (2, 0)
1525 <tabpage 1>(2): 1 windows, current is <window object (unknown)>
1526 Windows:
1527 <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
1528 <tabpage 2>(3): 2 windows, current is <window object (unknown)>
1529 Windows:
1530 <window object (unknown)>(1): displays buffer <buffer a.1>; cursor is at (1, 0)
1531 <window object (unknown)>(2): displays buffer <buffer 1>; cursor is at (1, 0)
1532 <tabpage 3>(4): 4 windows, current is <window 0>
1533 Windows:
1534 <window 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0)
1535 <window 1>(2): displays buffer <buffer b.2>; cursor is at (1, 0)
1536 <window 2>(3): displays buffer <buffer a.2>; cursor is at (1, 0)
1537 <window 3>(4): displays buffer <buffer 2>; cursor is at (1, 0)
1538 Number of windows in current tab page: 4
1539 END
1540 call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
1541 %bw!
1542endfunc
1543
1544" Test vim.current
1545func Test_python_vim_current()
1546 %bw
1547 edit Xfile
1548 py cb = vim.current.buffer
1549 tabnew 0
1550 tabnew 1
1551 vnew a.1
1552 tabnew 2
1553 vnew a.2
1554 vnew b.2
1555 vnew c.2
1556
1557 py << trim EOF
1558 def H(o):
1559 return repr(o)
1560 cb.append('Current tab page: ' + repr(vim.current.tabpage))
1561 cb.append('Current window: ' + repr(vim.current.window) + ': ' + \
1562 H(vim.current.window) + ' is ' + H(vim.current.tabpage.window))
1563 cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + \
1564 H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ \
1565 ' is ' + H(vim.current.tabpage.window.buffer))
1566 del H
1567 EOF
1568 let expected =<< trim END
1569 Current tab page: <tabpage 3>
1570 Current window: <window 0>: <window 0> is <window 0>
1571 Current buffer: <buffer c.2>: <buffer c.2> is <buffer c.2> is <buffer c.2>
1572 END
1573 call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
1574 call deletebufline(bufnr('Xfile'), 1, '$')
1575
1576 " Assigning: fails
1577 py << trim EOF
1578 try:
1579 vim.current.window = vim.tabpages[0].window
1580 except ValueError:
1581 cb.append('ValueError at assigning foreign tab window')
1582
1583 for attr in ('window', 'tabpage', 'buffer'):
1584 try:
1585 setattr(vim.current, attr, None)
1586 except TypeError:
1587 cb.append('Type error at assigning None to vim.current.' + attr)
1588 del attr
1589 EOF
1590
1591 let expected =<< trim END
1592 ValueError at assigning foreign tab window
1593 Type error at assigning None to vim.current.window
1594 Type error at assigning None to vim.current.tabpage
1595 Type error at assigning None to vim.current.buffer
1596 END
1597 call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
1598 call deletebufline(bufnr('Xfile'), 1, '$')
1599
1600 call setbufline(bufnr('Xfile'), 1, 'python interface')
1601 py << trim EOF
1602 # Assigning: success
1603 vim.current.tabpage = vim.tabpages[-2]
1604 vim.current.buffer = cb
1605 vim.current.window = vim.windows[0]
1606 vim.current.window.cursor = (len(vim.current.buffer), 0)
1607 cb.append('Current tab page: ' + repr(vim.current.tabpage))
1608 cb.append('Current window: ' + repr(vim.current.window))
1609 cb.append('Current buffer: ' + repr(vim.current.buffer))
1610 cb.append('Current line: ' + repr(vim.current.line))
1611 EOF
1612
1613 let expected =<< trim END
1614 Current tab page: <tabpage 2>
1615 Current window: <window 0>
1616 Current buffer: <buffer Xfile>
1617 Current line: 'python interface'
1618 END
1619 call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
1620 call deletebufline(bufnr('Xfile'), 1, '$')
1621
1622 py << trim EOF
1623 ws = list(vim.windows)
1624 ts = list(vim.tabpages)
1625 for b in vim.buffers:
1626 if b is not cb:
1627 vim.command('bwipeout! ' + str(b.number))
1628 del b
1629 cb.append('w.valid: ' + repr([w.valid for w in ws]))
1630 cb.append('t.valid: ' + repr([t.valid for t in ts]))
1631 del w
1632 del t
1633 del ts
1634 del ws
1635 EOF
1636 let expected =<< trim END
1637 w.valid: [True, False]
1638 t.valid: [True, False, True, False]
1639 END
1640 call assert_equal(expected, getbufline(bufnr('Xfile'), 2, '$'))
1641 %bw!
1642endfunc
1643
1644" Test types
1645func Test_python_types()
1646 %d
1647 py cb = vim.current.buffer
1648 py << trim EOF
1649 for expr, attr in (
1650 ('vim.vars', 'Dictionary'),
1651 ('vim.options', 'Options'),
1652 ('vim.bindeval("{}")', 'Dictionary'),
1653 ('vim.bindeval("[]")', 'List'),
1654 ('vim.bindeval("function(\'tr\')")', 'Function'),
1655 ('vim.current.buffer', 'Buffer'),
1656 ('vim.current.range', 'Range'),
1657 ('vim.current.window', 'Window'),
1658 ('vim.current.tabpage', 'TabPage'),
1659 ):
1660 cb.append(expr + ':' + attr + ':' + \
1661 repr(type(eval(expr)) is getattr(vim, attr)))
1662 del expr
1663 del attr
1664 EOF
1665 let expected =<< trim END
1666 vim.vars:Dictionary:True
1667 vim.options:Options:True
1668 vim.bindeval("{}"):Dictionary:True
1669 vim.bindeval("[]"):List:True
1670 vim.bindeval("function('tr')"):Function:True
1671 vim.current.buffer:Buffer:True
1672 vim.current.range:Range:True
1673 vim.current.window:Window:True
1674 vim.current.tabpage:TabPage:True
1675 END
1676 call assert_equal(expected, getline(2, '$'))
1677endfunc
1678
1679" Test __dir__() method
1680func Test_python_dir_method()
1681 %d
1682 py cb = vim.current.buffer
1683 py << trim EOF
1684 for name, o in (
1685 ('current', vim.current),
1686 ('buffer', vim.current.buffer),
1687 ('window', vim.current.window),
1688 ('tabpage', vim.current.tabpage),
1689 ('range', vim.current.range),
1690 ('dictionary', vim.bindeval('{}')),
1691 ('list', vim.bindeval('[]')),
1692 ('function', vim.bindeval('function("tr")')),
1693 ('output', sys.stdout),
1694 ):
1695 cb.append(name + ':' + ','.join(dir(o)))
1696 del name
1697 del o
1698 EOF
1699 let expected =<< trim END
1700 current:__dir__,__members__,buffer,line,range,tabpage,window
1701 buffer:__dir__,__members__,append,mark,name,number,options,range,valid,vars
1702 window:__dir__,__members__,buffer,col,cursor,height,number,options,row,tabpage,valid,vars,width
1703 tabpage:__dir__,__members__,number,valid,vars,window,windows
1704 range:__dir__,__members__,append,end,start
1705 dictionary:__dir__,__members__,get,has_key,items,keys,locked,pop,popitem,scope,update,values
1706 list:__dir__,__members__,extend,locked
1707 function:__dir__,__members__,args,auto_rebind,self,softspace
1708 output:__dir__,__members__,close,closed,flush,isatty,readable,seekable,softspace,writable,write,writelines
1709 END
1710 call assert_equal(expected, getline(2, '$'))
1711endfunc
1712
1713" Test vim.*.__new__
1714func Test_python_new()
1715 call assert_equal({}, pyeval('vim.Dictionary({})'))
1716 call assert_equal({'a': 1}, pyeval('vim.Dictionary(a=1)'))
1717 call assert_equal({'a': 1}, pyeval('vim.Dictionary(((''a'', 1),))'))
1718 call assert_equal([], pyeval('vim.List()'))
1719 call assert_equal(['a', 'b', 'c', '7'], pyeval('vim.List(iter(''abc7''))'))
1720 call assert_equal(function('tr'), pyeval('vim.Function(''tr'')'))
1721 call assert_equal(function('tr', [123, 3, 4]),
1722 \ pyeval('vim.Function(''tr'', args=[123, 3, 4])'))
1723 call assert_equal(function('tr'), pyeval('vim.Function(''tr'', args=[])'))
1724 call assert_equal(function('tr', {}),
1725 \ pyeval('vim.Function(''tr'', self={})'))
1726 call assert_equal(function('tr', [123, 3, 4], {}),
1727 \ pyeval('vim.Function(''tr'', args=[123, 3, 4], self={})'))
1728 call assert_equal(function('tr'),
1729 \ pyeval('vim.Function(''tr'', auto_rebind=False)'))
1730 call assert_equal(function('tr', [123, 3, 4]),
1731 \ pyeval('vim.Function(''tr'', args=[123, 3, 4], auto_rebind=False)'))
1732 call assert_equal(function('tr'),
1733 \ pyeval('vim.Function(''tr'', args=[], auto_rebind=False)'))
1734 call assert_equal(function('tr', {}),
1735 \ pyeval('vim.Function(''tr'', self={}, auto_rebind=False)'))
1736 call assert_equal(function('tr', [123, 3, 4], {}),
1737 \ pyeval('vim.Function(''tr'', args=[123, 3, 4], self={}, auto_rebind=False)'))
1738endfunc
1739
1740" Test vim.Function
1741func Test_python_vim_func()
1742 function Args(...)
1743 return a:000
1744 endfunction
1745
1746 function SelfArgs(...) dict
1747 return [a:000, self]
1748 endfunction
1749
1750 " The following four lines should not crash
1751 let Pt = function('tr', [[]], {'l': []})
1752 py Pt = vim.bindeval('Pt')
1753 unlet Pt
1754 py del Pt
1755
1756 %bw!
1757 py cb = vim.current.buffer
1758 py << trim EOF
1759 def ecall(out_prefix, func, *args, **kwargs):
1760 line = out_prefix + ': '
1761 try:
1762 ret = func(*args, **kwargs)
1763 except Exception:
1764 line += '!exception: ' + emsg(sys.exc_info())
1765 else:
1766 line += '!result: ' + vim.Function('string')(ret)
1767 cb.append(line)
1768 a = vim.Function('Args')
1769 pa1 = vim.Function('Args', args=['abcArgsPA1'])
1770 pa2 = vim.Function('Args', args=[])
1771 pa3 = vim.Function('Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'})
1772 pa4 = vim.Function('Args', self={'abcSelfPA4': 'abcSelfPA4Val'})
1773 cb.append('a: ' + repr(a))
1774 cb.append('pa1: ' + repr(pa1))
1775 cb.append('pa2: ' + repr(pa2))
1776 cb.append('pa3: ' + repr(pa3))
1777 cb.append('pa4: ' + repr(pa4))
1778 sa = vim.Function('SelfArgs')
1779 psa1 = vim.Function('SelfArgs', args=['abcArgsPSA1'])
1780 psa2 = vim.Function('SelfArgs', args=[])
1781 psa3 = vim.Function('SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'})
1782 psa4 = vim.Function('SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'})
1783 psa5 = vim.Function('SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}, auto_rebind=0)
1784 psa6 = vim.Function('SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}, auto_rebind=())
1785 psa7 = vim.Function('SelfArgs', args=['abcArgsPSA7'], auto_rebind=[])
1786 psa8 = vim.Function('SelfArgs', auto_rebind=False)
1787 psa9 = vim.Function('SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True)
1788 psaA = vim.Function('SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=1)
1789 psaB = vim.Function('SelfArgs', args=['abcArgsPSAB'], auto_rebind={'abcARPSAB': 'abcARPSABVal'})
1790 psaC = vim.Function('SelfArgs', auto_rebind=['abcARPSAC'])
1791 cb.append('sa: ' + repr(sa))
1792 cb.append('psa1: ' + repr(psa1))
1793 cb.append('psa2: ' + repr(psa2))
1794 cb.append('psa3: ' + repr(psa3))
1795 cb.append('psa4: ' + repr(psa4))
1796 cb.append('psa5: ' + repr(psa5))
1797 cb.append('psa6: ' + repr(psa6))
1798 cb.append('psa7: ' + repr(psa7))
1799 cb.append('psa8: ' + repr(psa8))
1800 cb.append('psa9: ' + repr(psa9))
1801 cb.append('psaA: ' + repr(psaA))
1802 cb.append('psaB: ' + repr(psaB))
1803 cb.append('psaC: ' + repr(psaC))
1804
1805 psar = vim.Function('SelfArgs', args=[{'abcArgsPSAr': 'abcArgsPSArVal'}], self={'abcSelfPSAr': 'abcSelfPSArVal'})
1806 psar.args[0]['abcArgsPSAr2'] = [psar.self, psar.args[0]]
1807 psar.self['rec'] = psar
1808 psar.self['self'] = psar.self
1809 psar.self['args'] = psar.args
1810
1811 try:
1812 cb.append('psar: ' + repr(psar))
1813 except Exception:
1814 cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info()))
1815 EOF
1816
1817 let expected =<< trim END
1818 a: <vim.Function 'Args'>
1819 pa1: <vim.Function 'Args', args=['abcArgsPA1']>
1820 pa2: <vim.Function 'Args'>
1821 pa3: <vim.Function 'Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'}>
1822 pa4: <vim.Function 'Args', self={'abcSelfPA4': 'abcSelfPA4Val'}>
1823 sa: <vim.Function 'SelfArgs'>
1824 psa1: <vim.Function 'SelfArgs', args=['abcArgsPSA1']>
1825 psa2: <vim.Function 'SelfArgs'>
1826 psa3: <vim.Function 'SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'}>
1827 psa4: <vim.Function 'SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'}>
1828 psa5: <vim.Function 'SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}>
1829 psa6: <vim.Function 'SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}>
1830 psa7: <vim.Function 'SelfArgs', args=['abcArgsPSA7']>
1831 psa8: <vim.Function 'SelfArgs'>
1832 psa9: <vim.Function 'SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True>
1833 psaA: <vim.Function 'SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=True>
1834 psaB: <vim.Function 'SelfArgs', args=['abcArgsPSAB']>
1835 psaC: <vim.Function 'SelfArgs'>
1836 psar: <vim.Function 'SelfArgs', args=[{'abcArgsPSAr2': [{'rec': function('SelfArgs', [{...}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{...}]}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], self={'rec': function('SelfArgs', [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}]}>
1837 END
1838 call assert_equal(expected, getline(2, '$'))
1839 %d
1840
1841 call assert_equal(function('Args'), pyeval('a'))
1842 call assert_equal(function('Args', ['abcArgsPA1']), pyeval('pa1'))
1843 call assert_equal(function('Args'), pyeval('pa2'))
1844 call assert_equal(function('Args', ['abcArgsPA3'], {'abcSelfPA3': 'abcSelfPA3Val'}), pyeval('pa3'))
1845 call assert_equal(function('Args', {'abcSelfPA4': 'abcSelfPA4Val'}), pyeval('pa4'))
1846 call assert_equal(function('SelfArgs'), pyeval('sa'))
1847 call assert_equal(function('SelfArgs', ['abcArgsPSA1']), pyeval('psa1'))
1848 call assert_equal(function('SelfArgs'), pyeval('psa2'))
1849 call assert_equal(function('SelfArgs', ['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}), pyeval('psa3'))
1850 call assert_equal(function('SelfArgs', {'abcSelfPSA4': 'abcSelfPSA4Val'}), pyeval('psa4'))
1851 call assert_equal(function('SelfArgs', {'abcSelfPSA5': 'abcSelfPSA5Val'}), pyeval('psa5'))
1852 call assert_equal(function('SelfArgs', ['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}), pyeval('psa6'))
1853 call assert_equal(function('SelfArgs', ['abcArgsPSA7']), pyeval('psa7'))
1854 call assert_equal(function('SelfArgs'), pyeval('psa8'))
1855 call assert_equal(function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'}), pyeval('psa9'))
1856 call assert_equal(function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'}), pyeval('psaA'))
1857 call assert_equal(function('SelfArgs', ['abcArgsPSAB']), pyeval('psaB'))
1858 call assert_equal(function('SelfArgs'), pyeval('psaC'))
1859
1860 let res = []
1861 for v in ['sa', 'psa1', 'psa2', 'psa3', 'psa4', 'psa5', 'psa6', 'psa7',
1862 \ 'psa8', 'psa9', 'psaA', 'psaB', 'psaC']
1863 let d = {'f': pyeval(v)}
1864 call add(res, 'd.' .. v .. '(): ' .. string(d.f()))
1865 endfor
1866
1867 let expected =<< trim END
1868 d.sa(): [[], {'f': function('SelfArgs')}]
1869 d.psa1(): [['abcArgsPSA1'], {'f': function('SelfArgs', ['abcArgsPSA1'])}]
1870 d.psa2(): [[], {'f': function('SelfArgs')}]
1871 d.psa3(): [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}]
1872 d.psa4(): [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}]
1873 d.psa5(): [[], {'abcSelfPSA5': 'abcSelfPSA5Val'}]
1874 d.psa6(): [['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}]
1875 d.psa7(): [['abcArgsPSA7'], {'f': function('SelfArgs', ['abcArgsPSA7'])}]
1876 d.psa8(): [[], {'f': function('SelfArgs')}]
1877 d.psa9(): [[], {'f': function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'})}]
1878 d.psaA(): [['abcArgsPSAA'], {'f': function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'})}]
1879 d.psaB(): [['abcArgsPSAB'], {'f': function('SelfArgs', ['abcArgsPSAB'])}]
1880 d.psaC(): [[], {'f': function('SelfArgs')}]
1881 END
1882 call assert_equal(expected, res)
1883
1884 py ecall('a()', a, )
1885 py ecall('pa1()', pa1, )
1886 py ecall('pa2()', pa2, )
1887 py ecall('pa3()', pa3, )
1888 py ecall('pa4()', pa4, )
1889 py ecall('sa()', sa, )
1890 py ecall('psa1()', psa1, )
1891 py ecall('psa2()', psa2, )
1892 py ecall('psa3()', psa3, )
1893 py ecall('psa4()', psa4, )
1894
1895 py ecall('a(42, 43)', a, 42, 43)
1896 py ecall('pa1(42, 43)', pa1, 42, 43)
1897 py ecall('pa2(42, 43)', pa2, 42, 43)
1898 py ecall('pa3(42, 43)', pa3, 42, 43)
1899 py ecall('pa4(42, 43)', pa4, 42, 43)
1900 py ecall('sa(42, 43)', sa, 42, 43)
1901 py ecall('psa1(42, 43)', psa1, 42, 43)
1902 py ecall('psa2(42, 43)', psa2, 42, 43)
1903 py ecall('psa3(42, 43)', psa3, 42, 43)
1904 py ecall('psa4(42, 43)', psa4, 42, 43)
1905
1906 py ecall('a(42, self={"20": 1})', a, 42, self={'20': 1})
1907 py ecall('pa1(42, self={"20": 1})', pa1, 42, self={'20': 1})
1908 py ecall('pa2(42, self={"20": 1})', pa2, 42, self={'20': 1})
1909 py ecall('pa3(42, self={"20": 1})', pa3, 42, self={'20': 1})
1910 py ecall('pa4(42, self={"20": 1})', pa4, 42, self={'20': 1})
1911 py ecall('sa(42, self={"20": 1})', sa, 42, self={'20': 1})
1912 py ecall('psa1(42, self={"20": 1})', psa1, 42, self={'20': 1})
1913 py ecall('psa2(42, self={"20": 1})', psa2, 42, self={'20': 1})
1914 py ecall('psa3(42, self={"20": 1})', psa3, 42, self={'20': 1})
1915 py ecall('psa4(42, self={"20": 1})', psa4, 42, self={'20': 1})
1916
1917 py ecall('a(self={"20": 1})', a, self={'20': 1})
1918 py ecall('pa1(self={"20": 1})', pa1, self={'20': 1})
1919 py ecall('pa2(self={"20": 1})', pa2, self={'20': 1})
1920 py ecall('pa3(self={"20": 1})', pa3, self={'20': 1})
1921 py ecall('pa4(self={"20": 1})', pa4, self={'20': 1})
1922 py ecall('sa(self={"20": 1})', sa, self={'20': 1})
1923 py ecall('psa1(self={"20": 1})', psa1, self={'20': 1})
1924 py ecall('psa2(self={"20": 1})', psa2, self={'20': 1})
1925 py ecall('psa3(self={"20": 1})', psa3, self={'20': 1})
1926 py ecall('psa4(self={"20": 1})', psa4, self={'20': 1})
1927
1928 py << trim EOF
1929 def s(v):
1930 if v is None:
1931 return repr(v)
1932 else:
1933 return vim.Function('string')(v)
1934
1935 cb.append('a.args: ' + s(a.args))
1936 cb.append('pa1.args: ' + s(pa1.args))
1937 cb.append('pa2.args: ' + s(pa2.args))
1938 cb.append('pa3.args: ' + s(pa3.args))
1939 cb.append('pa4.args: ' + s(pa4.args))
1940 cb.append('sa.args: ' + s(sa.args))
1941 cb.append('psa1.args: ' + s(psa1.args))
1942 cb.append('psa2.args: ' + s(psa2.args))
1943 cb.append('psa3.args: ' + s(psa3.args))
1944 cb.append('psa4.args: ' + s(psa4.args))
1945
1946 cb.append('a.self: ' + s(a.self))
1947 cb.append('pa1.self: ' + s(pa1.self))
1948 cb.append('pa2.self: ' + s(pa2.self))
1949 cb.append('pa3.self: ' + s(pa3.self))
1950 cb.append('pa4.self: ' + s(pa4.self))
1951 cb.append('sa.self: ' + s(sa.self))
1952 cb.append('psa1.self: ' + s(psa1.self))
1953 cb.append('psa2.self: ' + s(psa2.self))
1954 cb.append('psa3.self: ' + s(psa3.self))
1955 cb.append('psa4.self: ' + s(psa4.self))
1956
1957 cb.append('a.name: ' + s(a.name))
1958 cb.append('pa1.name: ' + s(pa1.name))
1959 cb.append('pa2.name: ' + s(pa2.name))
1960 cb.append('pa3.name: ' + s(pa3.name))
1961 cb.append('pa4.name: ' + s(pa4.name))
1962 cb.append('sa.name: ' + s(sa.name))
1963 cb.append('psa1.name: ' + s(psa1.name))
1964 cb.append('psa2.name: ' + s(psa2.name))
1965 cb.append('psa3.name: ' + s(psa3.name))
1966 cb.append('psa4.name: ' + s(psa4.name))
1967
1968 cb.append('a.auto_rebind: ' + s(a.auto_rebind))
1969 cb.append('pa1.auto_rebind: ' + s(pa1.auto_rebind))
1970 cb.append('pa2.auto_rebind: ' + s(pa2.auto_rebind))
1971 cb.append('pa3.auto_rebind: ' + s(pa3.auto_rebind))
1972 cb.append('pa4.auto_rebind: ' + s(pa4.auto_rebind))
1973 cb.append('sa.auto_rebind: ' + s(sa.auto_rebind))
1974 cb.append('psa1.auto_rebind: ' + s(psa1.auto_rebind))
1975 cb.append('psa2.auto_rebind: ' + s(psa2.auto_rebind))
1976 cb.append('psa3.auto_rebind: ' + s(psa3.auto_rebind))
1977 cb.append('psa4.auto_rebind: ' + s(psa4.auto_rebind))
1978 cb.append('psa5.auto_rebind: ' + s(psa5.auto_rebind))
1979 cb.append('psa6.auto_rebind: ' + s(psa6.auto_rebind))
1980 cb.append('psa7.auto_rebind: ' + s(psa7.auto_rebind))
1981 cb.append('psa8.auto_rebind: ' + s(psa8.auto_rebind))
1982 cb.append('psa9.auto_rebind: ' + s(psa9.auto_rebind))
1983 cb.append('psaA.auto_rebind: ' + s(psaA.auto_rebind))
1984 cb.append('psaB.auto_rebind: ' + s(psaB.auto_rebind))
1985 cb.append('psaC.auto_rebind: ' + s(psaC.auto_rebind))
1986
1987 del s
1988
1989 del a
1990 del pa1
1991 del pa2
1992 del pa3
1993 del pa4
1994 del sa
1995 del psa1
1996 del psa2
1997 del psa3
1998 del psa4
1999 del psa5
2000 del psa6
2001 del psa7
2002 del psa8
2003 del psa9
2004 del psaA
2005 del psaB
2006 del psaC
2007 del psar
2008
2009 del ecall
2010 EOF
2011
2012 let expected =<< trim END
2013 a(): !result: []
2014 pa1(): !result: ['abcArgsPA1']
2015 pa2(): !result: []
2016 pa3(): !result: ['abcArgsPA3']
2017 pa4(): !result: []
2018 sa(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',)
2019 psa1(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',)
2020 psa2(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',)
2021 psa3(): !result: [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}]
2022 psa4(): !result: [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}]
2023 a(42, 43): !result: [42, 43]
2024 pa1(42, 43): !result: ['abcArgsPA1', 42, 43]
2025 pa2(42, 43): !result: [42, 43]
2026 pa3(42, 43): !result: ['abcArgsPA3', 42, 43]
2027 pa4(42, 43): !result: [42, 43]
2028 sa(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',)
2029 psa1(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',)
2030 psa2(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',)
2031 psa3(42, 43): !result: [['abcArgsPSA3', 42, 43], {'abcSelfPSA3': 'abcSelfPSA3Val'}]
2032 psa4(42, 43): !result: [[42, 43], {'abcSelfPSA4': 'abcSelfPSA4Val'}]
2033 a(42, self={"20": 1}): !result: [42]
2034 pa1(42, self={"20": 1}): !result: ['abcArgsPA1', 42]
2035 pa2(42, self={"20": 1}): !result: [42]
2036 pa3(42, self={"20": 1}): !result: ['abcArgsPA3', 42]
2037 pa4(42, self={"20": 1}): !result: [42]
2038 sa(42, self={"20": 1}): !result: [[42], {'20': 1}]
2039 psa1(42, self={"20": 1}): !result: [['abcArgsPSA1', 42], {'20': 1}]
2040 psa2(42, self={"20": 1}): !result: [[42], {'20': 1}]
2041 psa3(42, self={"20": 1}): !result: [['abcArgsPSA3', 42], {'20': 1}]
2042 psa4(42, self={"20": 1}): !result: [[42], {'20': 1}]
2043 a(self={"20": 1}): !result: []
2044 pa1(self={"20": 1}): !result: ['abcArgsPA1']
2045 pa2(self={"20": 1}): !result: []
2046 pa3(self={"20": 1}): !result: ['abcArgsPA3']
2047 pa4(self={"20": 1}): !result: []
2048 sa(self={"20": 1}): !result: [[], {'20': 1}]
2049 psa1(self={"20": 1}): !result: [['abcArgsPSA1'], {'20': 1}]
2050 psa2(self={"20": 1}): !result: [[], {'20': 1}]
2051 psa3(self={"20": 1}): !result: [['abcArgsPSA3'], {'20': 1}]
2052 psa4(self={"20": 1}): !result: [[], {'20': 1}]
2053 a.args: None
2054 pa1.args: ['abcArgsPA1']
2055 pa2.args: None
2056 pa3.args: ['abcArgsPA3']
2057 pa4.args: None
2058 sa.args: None
2059 psa1.args: ['abcArgsPSA1']
2060 psa2.args: None
2061 psa3.args: ['abcArgsPSA3']
2062 psa4.args: None
2063 a.self: None
2064 pa1.self: None
2065 pa2.self: None
2066 pa3.self: {'abcSelfPA3': 'abcSelfPA3Val'}
2067 pa4.self: {'abcSelfPA4': 'abcSelfPA4Val'}
2068 sa.self: None
2069 psa1.self: None
2070 psa2.self: None
2071 psa3.self: {'abcSelfPSA3': 'abcSelfPSA3Val'}
2072 psa4.self: {'abcSelfPSA4': 'abcSelfPSA4Val'}
2073 a.name: 'Args'
2074 pa1.name: 'Args'
2075 pa2.name: 'Args'
2076 pa3.name: 'Args'
2077 pa4.name: 'Args'
2078 sa.name: 'SelfArgs'
2079 psa1.name: 'SelfArgs'
2080 psa2.name: 'SelfArgs'
2081 psa3.name: 'SelfArgs'
2082 psa4.name: 'SelfArgs'
2083 a.auto_rebind: 1
2084 pa1.auto_rebind: 1
2085 pa2.auto_rebind: 1
2086 pa3.auto_rebind: 0
2087 pa4.auto_rebind: 0
2088 sa.auto_rebind: 1
2089 psa1.auto_rebind: 1
2090 psa2.auto_rebind: 1
2091 psa3.auto_rebind: 0
2092 psa4.auto_rebind: 0
2093 psa5.auto_rebind: 0
2094 psa6.auto_rebind: 0
2095 psa7.auto_rebind: 1
2096 psa8.auto_rebind: 1
2097 psa9.auto_rebind: 1
2098 psaA.auto_rebind: 1
2099 psaB.auto_rebind: 1
2100 psaC.auto_rebind: 1
2101 END
2102 call assert_equal(expected, getline(2, '$'))
2103 %bw!
2104endfunc
2105
2106" Test stdout/stderr
2107func Test_python_stdin_stderr()
2108 let caught_writeerr = 0
2109 let caught_writelineerr = 0
2110 redir => messages
2111 py sys.stdout.write('abc8') ; sys.stdout.write('def')
2112 try
2113 py sys.stderr.write('abc9') ; sys.stderr.write('def')
2114 catch /abc9def/
2115 let caught_writeerr = 1
2116 endtry
2117 py sys.stdout.writelines(iter('abcA'))
2118 try
2119 py sys.stderr.writelines(iter('abcB'))
2120 catch /abcB/
2121 let caught_writelineerr = 1
2122 endtry
2123 redir END
2124 call assert_equal("\nabc8def\nabcA", messages)
2125 call assert_equal(1, caught_writeerr)
2126 call assert_equal(1, caught_writelineerr)
2127endfunc
2128
2129" Test subclassing
2130func Test_python_subclass()
2131 new
2132 fun Put(...)
2133 return a:000
2134 endfun
2135
2136 py << trim EOF
2137 class DupDict(vim.Dictionary):
2138 def __setitem__(self, key, value):
2139 super(DupDict, self).__setitem__(key, value)
2140 super(DupDict, self).__setitem__('dup_' + key, value)
2141 dd = DupDict()
2142 dd['a'] = 'b'
2143
2144 class DupList(vim.List):
2145 def __getitem__(self, idx):
2146 return [super(DupList, self).__getitem__(idx)] * 2
2147
2148 dl = DupList()
2149 dl2 = DupList(iter('abcC'))
2150 dl.extend(dl2[0])
2151
2152 class DupFun(vim.Function):
2153 def __call__(self, arg):
2154 return super(DupFun, self).__call__(arg, arg)
2155
2156 df = DupFun('Put')
2157 EOF
2158
2159 call assert_equal(['a', 'dup_a'], sort(keys(pyeval('dd'))))
2160 call assert_equal(['a', 'a'], pyeval('dl'))
2161 call assert_equal(['a', 'b', 'c', 'C'], pyeval('dl2'))
2162 call assert_equal([2, 2], pyeval('df(2)'))
2163 call assert_equal(1, pyeval('dl') is# pyeval('dl'))
2164 call assert_equal(1, pyeval('dd') is# pyeval('dd'))
2165 call assert_equal(function('Put'), pyeval('df'))
2166 delfunction Put
2167 py << trim EOF
2168 del DupDict
2169 del DupList
2170 del DupFun
2171 del dd
2172 del dl
2173 del dl2
2174 del df
2175 EOF
2176 close!
2177endfunc
2178
2179" Test chdir
2180func Test_python_chdir()
2181 new Xfile
2182 py cb = vim.current.buffer
2183 py << trim EOF
2184 import os
2185 fnamemodify = vim.Function('fnamemodify')
2186 cb.append(fnamemodify('.', ':p:h:t'))
2187 cb.append(vim.eval('@%'))
2188 os.chdir('..')
2189 path = fnamemodify('.', ':p:h:t')
2190 if path != 'src':
2191 # Running tests from a shadow directory, so move up another level
2192 # This will result in @% looking like shadow/testdir/Xfile, hence the
2193 # extra fnamemodify
2194 os.chdir('..')
2195 cb.append(fnamemodify('.', ':p:h:t'))
2196 cb.append(fnamemodify(vim.eval('@%'), ':s?^%s.??' % path).replace(os.path.sep, '/'))
2197 os.chdir(path)
2198 del path
2199 else:
2200 cb.append(fnamemodify('.', ':p:h:t'))
2201 cb.append(vim.eval('@%').replace(os.path.sep, '/'))
2202 os.chdir('testdir')
2203 cb.append(fnamemodify('.', ':p:h:t'))
2204 cb.append(vim.eval('@%'))
2205 del fnamemodify
2206 EOF
2207 call assert_equal(['testdir', 'Xfile', 'src', 'testdir/Xfile', 'testdir',
2208 \ 'Xfile'], getline(2, '$'))
2209 close!
2210endfunc
2211
2212" Test errors
2213func Test_python_errors()
2214 fun F() dict
2215 endfun
2216
2217 fun D()
2218 endfun
2219
2220 new
2221 py cb = vim.current.buffer
2222
2223 py << trim EOF
2224 d = vim.Dictionary()
2225 ned = vim.Dictionary(foo='bar', baz='abcD')
2226 dl = vim.Dictionary(a=1)
2227 dl.locked = True
2228 l = vim.List()
2229 ll = vim.List('abcE')
2230 ll.locked = True
2231 nel = vim.List('abcO')
2232 f = vim.Function('string')
2233 fd = vim.Function('F')
2234 fdel = vim.Function('D')
2235 vim.command('delfunction D')
2236
2237 def subexpr_test(expr, name, subexprs):
2238 cb.append('>>> Testing %s using %s' % (name, expr))
2239 for subexpr in subexprs:
2240 ee(expr % subexpr)
2241 cb.append('<<< Finished')
2242
2243 def stringtochars_test(expr):
2244 return subexpr_test(expr, 'StringToChars', (
2245 '1', # Fail type checks
2246 'u"\\0"', # Fail PyString_AsStringAndSize(bytes, , NULL) check
2247 '"\\0"', # Fail PyString_AsStringAndSize(object, , NULL) check
2248 ))
2249
2250 class Mapping(object):
2251 def __init__(self, d):
2252 self.d = d
2253
2254 def __getitem__(self, key):
2255 return self.d[key]
2256
2257 def keys(self):
2258 return self.d.keys()
2259
2260 def items(self):
2261 return self.d.items()
2262
2263 def convertfrompyobject_test(expr, recurse=True):
2264 # pydict_to_tv
2265 stringtochars_test(expr % '{%s : 1}')
2266 if recurse:
2267 convertfrompyobject_test(expr % '{"abcF" : %s}', False)
2268 # pymap_to_tv
2269 stringtochars_test(expr % 'Mapping({%s : 1})')
2270 if recurse:
2271 convertfrompyobject_test(expr % 'Mapping({"abcG" : %s})', False)
2272 # pyseq_to_tv
2273 iter_test(expr)
2274 return subexpr_test(expr, 'ConvertFromPyObject', (
2275 'None', # Not conversible
2276 '{"": 1}', # Empty key not allowed
2277 '{u"": 1}', # Same, but with unicode object
2278 'FailingMapping()', #
2279 'FailingMappingKey()', #
2280 'FailingNumber()', #
2281 ))
2282
2283 def convertfrompymapping_test(expr):
2284 convertfrompyobject_test(expr)
2285 return subexpr_test(expr, 'ConvertFromPyMapping', (
2286 '[]',
2287 ))
2288
2289 def iter_test(expr):
2290 return subexpr_test(expr, '*Iter*', (
2291 'FailingIter()',
2292 'FailingIterNext()',
2293 ))
2294
2295 def number_test(expr, natural=False, unsigned=False):
2296 if natural:
2297 unsigned = True
2298 return subexpr_test(expr, 'NumberToLong', (
2299 '[]',
2300 'None',
2301 ) + (unsigned and ('-1',) or ())
2302 + (natural and ('0',) or ()))
2303
2304 class FailingTrue(object):
2305 def __nonzero__(self):
2306 raise NotImplementedError('bool')
2307
2308 class FailingIter(object):
2309 def __iter__(self):
2310 raise NotImplementedError('iter')
2311
2312 class FailingIterNext(object):
2313 def __iter__(self):
2314 return self
2315
2316 def next(self):
2317 raise NotImplementedError('next')
2318
2319 class FailingIterNextN(object):
2320 def __init__(self, n):
2321 self.n = n
2322
2323 def __iter__(self):
2324 return self
2325
2326 def next(self):
2327 if self.n:
2328 self.n -= 1
2329 return 1
2330 else:
2331 raise NotImplementedError('next N')
2332
2333 class FailingMappingKey(object):
2334 def __getitem__(self, item):
2335 raise NotImplementedError('getitem:mappingkey')
2336
2337 def keys(self):
2338 return list("abcH")
2339
2340 class FailingMapping(object):
2341 def __getitem__(self):
2342 raise NotImplementedError('getitem:mapping')
2343
2344 def keys(self):
2345 raise NotImplementedError('keys')
2346
2347 class FailingList(list):
2348 def __getitem__(self, idx):
2349 if i == 2:
2350 raise NotImplementedError('getitem:list')
2351 else:
2352 return super(FailingList, self).__getitem__(idx)
2353
2354 class NoArgsCall(object):
2355 def __call__(self):
2356 pass
2357
2358 class FailingCall(object):
2359 def __call__(self, path):
2360 raise NotImplementedError('call')
2361
2362 class FailingNumber(object):
2363 def __int__(self):
2364 raise NotImplementedError('int')
2365
2366 cb.append("> Output")
2367 cb.append(">> OutputSetattr")
2368 ee('del sys.stdout.softspace')
2369 number_test('sys.stdout.softspace = %s', unsigned=True)
2370 number_test('sys.stderr.softspace = %s', unsigned=True)
2371 ee('assert sys.stdout.isatty()==False')
2372 ee('assert sys.stdout.seekable()==False')
2373 ee('sys.stdout.close()')
2374 ee('sys.stdout.flush()')
2375 ee('assert sys.stderr.isatty()==False')
2376 ee('assert sys.stderr.seekable()==False')
2377 ee('sys.stderr.close()')
2378 ee('sys.stderr.flush()')
2379 ee('sys.stdout.attr = None')
2380 cb.append(">> OutputWrite")
2381 ee('assert sys.stdout.writable()==True')
2382 ee('assert sys.stdout.readable()==False')
2383 ee('assert sys.stderr.writable()==True')
2384 ee('assert sys.stderr.readable()==False')
2385 ee('assert sys.stdout.closed()==False')
2386 ee('assert sys.stderr.closed()==False')
2387 ee('assert sys.stdout.errors=="strict"')
2388 ee('assert sys.stderr.errors=="strict"')
2389 ee('assert sys.stdout.encoding==sys.stderr.encoding')
2390 ee('sys.stdout.write(None)')
2391 cb.append(">> OutputWriteLines")
2392 ee('sys.stdout.writelines(None)')
2393 ee('sys.stdout.writelines([1])')
2394 iter_test('sys.stdout.writelines(%s)')
2395 cb.append("> VimCommand")
2396 stringtochars_test('vim.command(%s)')
2397 ee('vim.command("", 2)')
2398 #! Not checked: vim->python exceptions translating: checked later
2399 cb.append("> VimToPython")
2400 #! Not checked: everything: needs errors in internal python functions
2401 cb.append("> VimEval")
2402 stringtochars_test('vim.eval(%s)')
2403 ee('vim.eval("", FailingTrue())')
2404 #! Not checked: everything: needs errors in internal python functions
2405 cb.append("> VimEvalPy")
2406 stringtochars_test('vim.bindeval(%s)')
2407 ee('vim.eval("", 2)')
2408 #! Not checked: vim->python exceptions translating: checked later
2409 cb.append("> VimStrwidth")
2410 stringtochars_test('vim.strwidth(%s)')
2411 cb.append("> VimForeachRTP")
2412 ee('vim.foreach_rtp(None)')
2413 ee('vim.foreach_rtp(NoArgsCall())')
2414 ee('vim.foreach_rtp(FailingCall())')
2415 ee('vim.foreach_rtp(int, 2)')
2416 cb.append('> import')
2417 old_rtp = vim.options['rtp']
2418 vim.options['rtp'] = os.getcwd().replace('\\', '\\\\').replace(',', '\\,')
2419 ee('import xxx_no_such_module_xxx')
2420 ee('import failing_import')
2421 ee('import failing')
2422 vim.options['rtp'] = old_rtp
2423 del old_rtp
2424 cb.append("> Options")
2425 cb.append(">> OptionsItem")
2426 ee('vim.options["abcQ"]')
2427 ee('vim.options[""]')
2428 stringtochars_test('vim.options[%s]')
2429 cb.append(">> OptionsContains")
2430 stringtochars_test('%s in vim.options')
2431 cb.append("> Dictionary")
2432 cb.append(">> DictionaryConstructor")
2433 ee('vim.Dictionary("abcI")')
2434 ##! Not checked: py_dict_alloc failure
2435 cb.append(">> DictionarySetattr")
2436 ee('del d.locked')
2437 ee('d.locked = FailingTrue()')
2438 ee('vim.vvars.locked = False')
2439 ee('d.scope = True')
2440 ee('d.xxx = True')
2441 cb.append(">> _DictionaryItem")
2442 ee('d.get("a", 2, 3)')
2443 stringtochars_test('d.get(%s)')
2444 ee('d.pop("a")')
2445 ee('dl.pop("a")')
2446 cb.append(">> DictionaryContains")
2447 ee('"" in d')
2448 ee('0 in d')
2449 cb.append(">> DictionaryIterNext")
2450 ee('for i in ned: ned["a"] = 1')
2451 del i
2452 cb.append(">> DictionaryAssItem")
2453 ee('dl["b"] = 1')
2454 stringtochars_test('d[%s] = 1')
2455 convertfrompyobject_test('d["a"] = %s')
2456 cb.append(">> DictionaryUpdate")
2457 cb.append(">>> kwargs")
2458 cb.append(">>> iter")
2459 ee('d.update(FailingMapping())')
2460 ee('d.update([FailingIterNext()])')
2461 ee('d.update([FailingIterNextN(1)])')
2462 iter_test('d.update(%s)')
2463 convertfrompyobject_test('d.update(%s)')
2464 stringtochars_test('d.update(((%s, 0),))')
2465 convertfrompyobject_test('d.update((("a", %s),))')
2466 cb.append(">> DictionaryPopItem")
2467 ee('d.popitem(1, 2)')
2468 cb.append(">> DictionaryHasKey")
2469 ee('d.has_key()')
2470 cb.append("> List")
2471 cb.append(">> ListConstructor")
2472 ee('vim.List(1, 2)')
2473 ee('vim.List(a=1)')
2474 iter_test('vim.List(%s)')
2475 convertfrompyobject_test('vim.List([%s])')
2476 cb.append(">> ListItem")
2477 ee('l[1000]')
2478 cb.append(">> ListAssItem")
2479 ee('ll[1] = 2')
2480 ee('l[1000] = 3')
2481 cb.append(">> ListAssSlice")
2482 ee('ll[1:100] = "abcJ"')
2483 iter_test('l[:] = %s')
2484 ee('nel[1:10:2] = "abcK"')
2485 cb.append(repr(tuple(nel)))
2486 ee('nel[1:10:2] = "a"')
2487 cb.append(repr(tuple(nel)))
2488 ee('nel[1:1:-1] = "a"')
2489 cb.append(repr(tuple(nel)))
2490 ee('nel[:] = FailingIterNextN(2)')
2491 cb.append(repr(tuple(nel)))
2492 convertfrompyobject_test('l[:] = [%s]')
2493 cb.append(">> ListConcatInPlace")
2494 iter_test('l.extend(%s)')
2495 convertfrompyobject_test('l.extend([%s])')
2496 cb.append(">> ListSetattr")
2497 ee('del l.locked')
2498 ee('l.locked = FailingTrue()')
2499 ee('l.xxx = True')
2500 cb.append("> Function")
2501 cb.append(">> FunctionConstructor")
2502 cb.append(">>> FunctionConstructor")
2503 ee('vim.Function("123")')
2504 ee('vim.Function("xxx_non_existent_function_xxx")')
2505 ee('vim.Function("xxx#non#existent#function#xxx")')
2506 ee('vim.Function("xxx_non_existent_function_xxx2", args=[])')
2507 ee('vim.Function("xxx_non_existent_function_xxx3", self={})')
2508 ee('vim.Function("xxx_non_existent_function_xxx4", args=[], self={})')
2509 cb.append(">>> FunctionNew")
2510 ee('vim.Function("tr", self="abcFuncSelf")')
2511 ee('vim.Function("tr", args=427423)')
2512 ee('vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2")')
2513 ee('vim.Function(self="abcFuncSelf2", args="abcFuncArgs2")')
2514 ee('vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2")')
2515 ee('vim.Function("tr", "")')
2516 cb.append(">> FunctionCall")
2517 convertfrompyobject_test('f(%s)')
2518 convertfrompymapping_test('fd(self=%s)')
2519 cb.append("> TabPage")
2520 cb.append(">> TabPageAttr")
2521 ee('vim.current.tabpage.xxx')
2522 cb.append("> TabList")
2523 cb.append(">> TabListItem")
2524 ee('vim.tabpages[1000]')
2525 cb.append("> Window")
2526 cb.append(">> WindowAttr")
2527 ee('vim.current.window.xxx')
2528 cb.append(">> WindowSetattr")
2529 ee('vim.current.window.buffer = 0')
2530 ee('vim.current.window.cursor = (100000000, 100000000)')
2531 ee('vim.current.window.cursor = True')
2532 number_test('vim.current.window.height = %s', unsigned=True)
2533 number_test('vim.current.window.width = %s', unsigned=True)
2534 ee('vim.current.window.xxxxxx = True')
2535 cb.append("> WinList")
2536 cb.append(">> WinListItem")
2537 ee('vim.windows[1000]')
2538 cb.append("> Buffer")
2539 cb.append(">> StringToLine (indirect)")
2540 ee('vim.current.buffer[0] = u"\\na"')
2541 ee('vim.current.buffer[0] = "\\na"')
2542 cb.append(">> SetBufferLine (indirect)")
2543 ee('vim.current.buffer[0] = True')
2544 cb.append(">> SetBufferLineList (indirect)")
2545 ee('vim.current.buffer[:] = True')
2546 ee('vim.current.buffer[:] = ["\\na", "bc"]')
2547 cb.append(">> InsertBufferLines (indirect)")
2548 ee('vim.current.buffer.append(None)')
2549 ee('vim.current.buffer.append(["\\na", "bc"])')
2550 ee('vim.current.buffer.append("\\nbc")')
2551 cb.append(">> RBItem")
2552 ee('vim.current.buffer[100000000]')
2553 cb.append(">> RBAsItem")
2554 ee('vim.current.buffer[100000000] = ""')
2555 cb.append(">> BufferAttr")
2556 ee('vim.current.buffer.xxx')
2557 cb.append(">> BufferSetattr")
2558 ee('vim.current.buffer.name = True')
2559 ee('vim.current.buffer.xxx = True')
2560 cb.append(">> BufferMark")
2561 ee('vim.current.buffer.mark(0)')
2562 ee('vim.current.buffer.mark("abcM")')
2563 ee('vim.current.buffer.mark("!")')
2564 cb.append(">> BufferRange")
2565 ee('vim.current.buffer.range(1, 2, 3)')
2566 cb.append("> BufMap")
2567 cb.append(">> BufMapItem")
2568 ee('vim.buffers[100000000]')
2569 number_test('vim.buffers[%s]', natural=True)
2570 cb.append("> Current")
2571 cb.append(">> CurrentGetattr")
2572 ee('vim.current.xxx')
2573 cb.append(">> CurrentSetattr")
2574 ee('vim.current.line = True')
2575 ee('vim.current.buffer = True')
2576 ee('vim.current.window = True')
2577 ee('vim.current.tabpage = True')
2578 ee('vim.current.xxx = True')
2579 del d
2580 del ned
2581 del dl
2582 del l
2583 del ll
2584 del nel
2585 del f
2586 del fd
2587 del fdel
2588 del subexpr_test
2589 del stringtochars_test
2590 del Mapping
2591 del convertfrompyobject_test
2592 del convertfrompymapping_test
2593 del iter_test
2594 del number_test
2595 del FailingTrue
2596 del FailingIter
2597 del FailingIterNext
2598 del FailingIterNextN
2599 del FailingMapping
2600 del FailingMappingKey
2601 del FailingList
2602 del NoArgsCall
2603 del FailingCall
2604 del FailingNumber
2605 EOF
2606 delfunction F
2607
2608 let expected =<< trim END
2609 > Output
2610 >> OutputSetattr
2611 del sys.stdout.softspace:AttributeError:('cannot delete OutputObject attributes',)
2612 >>> Testing NumberToLong using sys.stdout.softspace = %s
2613 sys.stdout.softspace = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',)
2614 sys.stdout.softspace = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',)
2615 sys.stdout.softspace = -1:ValueError:('number must be greater or equal to zero',)
2616 <<< Finished
2617 >>> Testing NumberToLong using sys.stderr.softspace = %s
2618 sys.stderr.softspace = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',)
2619 sys.stderr.softspace = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',)
2620 sys.stderr.softspace = -1:ValueError:('number must be greater or equal to zero',)
2621 <<< Finished
2622 assert sys.stdout.isatty()==False:NOT FAILED
2623 assert sys.stdout.seekable()==False:NOT FAILED
2624 sys.stdout.close():NOT FAILED
2625 sys.stdout.flush():NOT FAILED
2626 assert sys.stderr.isatty()==False:NOT FAILED
2627 assert sys.stderr.seekable()==False:NOT FAILED
2628 sys.stderr.close():NOT FAILED
2629 sys.stderr.flush():NOT FAILED
2630 sys.stdout.attr = None:AttributeError:('invalid attribute: attr',)
2631 >> OutputWrite
2632 assert sys.stdout.writable()==True:NOT FAILED
2633 assert sys.stdout.readable()==False:NOT FAILED
2634 assert sys.stderr.writable()==True:NOT FAILED
2635 assert sys.stderr.readable()==False:NOT FAILED
2636 assert sys.stdout.closed()==False:NOT FAILED
2637 assert sys.stderr.closed()==False:NOT FAILED
2638 assert sys.stdout.errors=="strict":NOT FAILED
2639 assert sys.stderr.errors=="strict":NOT FAILED
2640 assert sys.stdout.encoding==sys.stderr.encoding:NOT FAILED
2641 sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, NoneType found',)
2642 >> OutputWriteLines
2643 sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",)
2644 sys.stdout.writelines([1]):TypeError:('coercing to Unicode: need string or buffer, int found',)
2645 >>> Testing *Iter* using sys.stdout.writelines(%s)
2646 sys.stdout.writelines(FailingIter()):NotImplementedError:('iter',)
2647 sys.stdout.writelines(FailingIterNext()):NotImplementedError:('next',)
2648 <<< Finished
2649 > VimCommand
2650 >>> Testing StringToChars using vim.command(%s)
2651 vim.command(1):TypeError:('expected str() or unicode() instance, but got int',)
2652 vim.command(u"\0"):TypeError:('expected string without null bytes',)
2653 vim.command("\0"):TypeError:('expected string without null bytes',)
2654 <<< Finished
2655 vim.command("", 2):TypeError:('command() takes exactly one argument (2 given)',)
2656 > VimToPython
2657 > VimEval
2658 >>> Testing StringToChars using vim.eval(%s)
2659 vim.eval(1):TypeError:('expected str() or unicode() instance, but got int',)
2660 vim.eval(u"\0"):TypeError:('expected string without null bytes',)
2661 vim.eval("\0"):TypeError:('expected string without null bytes',)
2662 <<< Finished
2663 vim.eval("", FailingTrue()):TypeError:('function takes exactly 1 argument (2 given)',)
2664 > VimEvalPy
2665 >>> Testing StringToChars using vim.bindeval(%s)
2666 vim.bindeval(1):TypeError:('expected str() or unicode() instance, but got int',)
2667 vim.bindeval(u"\0"):TypeError:('expected string without null bytes',)
2668 vim.bindeval("\0"):TypeError:('expected string without null bytes',)
2669 <<< Finished
2670 vim.eval("", 2):TypeError:('function takes exactly 1 argument (2 given)',)
2671 > VimStrwidth
2672 >>> Testing StringToChars using vim.strwidth(%s)
2673 vim.strwidth(1):TypeError:('expected str() or unicode() instance, but got int',)
2674 vim.strwidth(u"\0"):TypeError:('expected string without null bytes',)
2675 vim.strwidth("\0"):TypeError:('expected string without null bytes',)
2676 <<< Finished
2677 > VimForeachRTP
2678 vim.foreach_rtp(None):TypeError:("'NoneType' object is not callable",)
2679 vim.foreach_rtp(NoArgsCall()):TypeError:('__call__() takes exactly 1 argument (2 given)',)
2680 vim.foreach_rtp(FailingCall()):NotImplementedError:('call',)
2681 vim.foreach_rtp(int, 2):TypeError:('foreach_rtp() takes exactly one argument (2 given)',)
2682 > import
2683 import xxx_no_such_module_xxx:ImportError:('No module named xxx_no_such_module_xxx',)
2684 import failing_import:ImportError:()
2685 import failing:NotImplementedError:()
2686 > Options
2687 >> OptionsItem
2688 vim.options["abcQ"]:KeyError:('abcQ',)
2689 vim.options[""]:ValueError:('empty keys are not allowed',)
2690 >>> Testing StringToChars using vim.options[%s]
2691 vim.options[1]:TypeError:('expected str() or unicode() instance, but got int',)
2692 vim.options[u"\0"]:TypeError:('expected string without null bytes',)
2693 vim.options["\0"]:TypeError:('expected string without null bytes',)
2694 <<< Finished
2695 >> OptionsContains
2696 >>> Testing StringToChars using %s in vim.options
2697 1 in vim.options:TypeError:('expected str() or unicode() instance, but got int',)
2698 u"\0" in vim.options:TypeError:('expected string without null bytes',)
2699 "\0" in vim.options:TypeError:('expected string without null bytes',)
2700 <<< Finished
2701 > Dictionary
2702 >> DictionaryConstructor
2703 vim.Dictionary("abcI"):ValueError:('expected sequence element of size 2, but got sequence of size 1',)
2704 >> DictionarySetattr
2705 del d.locked:AttributeError:('cannot delete vim.Dictionary attributes',)
2706 d.locked = FailingTrue():NotImplementedError:('bool',)
2707 vim.vvars.locked = False:TypeError:('cannot modify fixed dictionary',)
2708 d.scope = True:AttributeError:('cannot set attribute scope',)
2709 d.xxx = True:AttributeError:('cannot set attribute xxx',)
2710 >> _DictionaryItem
2711 d.get("a", 2, 3):TypeError:('function takes at most 2 arguments (3 given)',)
2712 >>> Testing StringToChars using d.get(%s)
2713 d.get(1):TypeError:('expected str() or unicode() instance, but got int',)
2714 d.get(u"\0"):TypeError:('expected string without null bytes',)
2715 d.get("\0"):TypeError:('expected string without null bytes',)
2716 <<< Finished
2717 d.pop("a"):KeyError:('a',)
2718 dl.pop("a"):error:('dictionary is locked',)
2719 >> DictionaryContains
2720 "" in d:ValueError:('empty keys are not allowed',)
2721 0 in d:TypeError:('expected str() or unicode() instance, but got int',)
2722 >> DictionaryIterNext
2723 for i in ned: ned["a"] = 1:RuntimeError:('hashtab changed during iteration',)
2724 >> DictionaryAssItem
2725 dl["b"] = 1:error:('dictionary is locked',)
2726 >>> Testing StringToChars using d[%s] = 1
2727 d[1] = 1:TypeError:('expected str() or unicode() instance, but got int',)
2728 d[u"\0"] = 1:TypeError:('expected string without null bytes',)
2729 d["\0"] = 1:TypeError:('expected string without null bytes',)
2730 <<< Finished
2731 >>> Testing StringToChars using d["a"] = {%s : 1}
2732 d["a"] = {1 : 1}:TypeError:('expected str() or unicode() instance, but got int',)
2733 d["a"] = {u"\0" : 1}:TypeError:('expected string without null bytes',)
2734 d["a"] = {"\0" : 1}:TypeError:('expected string without null bytes',)
2735 <<< Finished
2736 >>> Testing StringToChars using d["a"] = {"abcF" : {%s : 1}}
2737 d["a"] = {"abcF" : {1 : 1}}:TypeError:('expected str() or unicode() instance, but got int',)
2738 d["a"] = {"abcF" : {u"\0" : 1}}:TypeError:('expected string without null bytes',)
2739 d["a"] = {"abcF" : {"\0" : 1}}:TypeError:('expected string without null bytes',)
2740 <<< Finished
2741 >>> Testing StringToChars using d["a"] = {"abcF" : Mapping({%s : 1})}
2742 d["a"] = {"abcF" : Mapping({1 : 1})}:TypeError:('expected str() or unicode() instance, but got int',)
2743 d["a"] = {"abcF" : Mapping({u"\0" : 1})}:TypeError:('expected string without null bytes',)
2744 d["a"] = {"abcF" : Mapping({"\0" : 1})}:TypeError:('expected string without null bytes',)
2745 <<< Finished
2746 >>> Testing *Iter* using d["a"] = {"abcF" : %s}
2747 d["a"] = {"abcF" : FailingIter()}:TypeError:('unable to convert FailingIter to a Vim structure',)
2748 d["a"] = {"abcF" : FailingIterNext()}:NotImplementedError:('next',)
2749 <<< Finished
2750 >>> Testing ConvertFromPyObject using d["a"] = {"abcF" : %s}
2751 d["a"] = {"abcF" : None}:NOT FAILED
2752 d["a"] = {"abcF" : {"": 1}}:ValueError:('empty keys are not allowed',)
2753 d["a"] = {"abcF" : {u"": 1}}:ValueError:('empty keys are not allowed',)
2754 d["a"] = {"abcF" : FailingMapping()}:NotImplementedError:('keys',)
2755 d["a"] = {"abcF" : FailingMappingKey()}:NotImplementedError:('getitem:mappingkey',)
2756 d["a"] = {"abcF" : FailingNumber()}:TypeError:('long() argument must be a string or a number',)
2757 <<< Finished
2758 >>> Testing StringToChars using d["a"] = Mapping({%s : 1})
2759 d["a"] = Mapping({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',)
2760 d["a"] = Mapping({u"\0" : 1}):TypeError:('expected string without null bytes',)
2761 d["a"] = Mapping({"\0" : 1}):TypeError:('expected string without null bytes',)
2762 <<< Finished
2763 >>> Testing StringToChars using d["a"] = Mapping({"abcG" : {%s : 1}})
2764 d["a"] = Mapping({"abcG" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',)
2765 d["a"] = Mapping({"abcG" : {u"\0" : 1}}):TypeError:('expected string without null bytes',)
2766 d["a"] = Mapping({"abcG" : {"\0" : 1}}):TypeError:('expected string without null bytes',)
2767 <<< Finished
2768 >>> Testing StringToChars using d["a"] = Mapping({"abcG" : Mapping({%s : 1})})
2769 d["a"] = Mapping({"abcG" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',)
2770 d["a"] = Mapping({"abcG" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',)
2771 d["a"] = Mapping({"abcG" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',)
2772 <<< Finished
2773 >>> Testing *Iter* using d["a"] = Mapping({"abcG" : %s})
2774 d["a"] = Mapping({"abcG" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',)
2775 d["a"] = Mapping({"abcG" : FailingIterNext()}):NotImplementedError:('next',)
2776 <<< Finished
2777 >>> Testing ConvertFromPyObject using d["a"] = Mapping({"abcG" : %s})
2778 d["a"] = Mapping({"abcG" : None}):NOT FAILED
2779 d["a"] = Mapping({"abcG" : {"": 1}}):ValueError:('empty keys are not allowed',)
2780 d["a"] = Mapping({"abcG" : {u"": 1}}):ValueError:('empty keys are not allowed',)
2781 d["a"] = Mapping({"abcG" : FailingMapping()}):NotImplementedError:('keys',)
2782 d["a"] = Mapping({"abcG" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',)
2783 d["a"] = Mapping({"abcG" : FailingNumber()}):TypeError:('long() argument must be a string or a number',)
2784 <<< Finished
2785 >>> Testing *Iter* using d["a"] = %s
2786 d["a"] = FailingIter():TypeError:('unable to convert FailingIter to a Vim structure',)
2787 d["a"] = FailingIterNext():NotImplementedError:('next',)
2788 <<< Finished
2789 >>> Testing ConvertFromPyObject using d["a"] = %s
2790 d["a"] = None:NOT FAILED
2791 d["a"] = {"": 1}:ValueError:('empty keys are not allowed',)
2792 d["a"] = {u"": 1}:ValueError:('empty keys are not allowed',)
2793 d["a"] = FailingMapping():NotImplementedError:('keys',)
2794 d["a"] = FailingMappingKey():NotImplementedError:('getitem:mappingkey',)
2795 d["a"] = FailingNumber():TypeError:('long() argument must be a string or a number',)
2796 <<< Finished
2797 >> DictionaryUpdate
2798 >>> kwargs
2799 >>> iter
2800 d.update(FailingMapping()):NotImplementedError:('keys',)
2801 d.update([FailingIterNext()]):NotImplementedError:('next',)
2802 d.update([FailingIterNextN(1)]):NotImplementedError:('next N',)
2803 >>> Testing *Iter* using d.update(%s)
2804 d.update(FailingIter()):NotImplementedError:('iter',)
2805 d.update(FailingIterNext()):NotImplementedError:('next',)
2806 <<< Finished
2807 >>> Testing StringToChars using d.update({%s : 1})
2808 d.update({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',)
2809 d.update({u"\0" : 1}):TypeError:('expected string without null bytes',)
2810 d.update({"\0" : 1}):TypeError:('expected string without null bytes',)
2811 <<< Finished
2812 >>> Testing StringToChars using d.update({"abcF" : {%s : 1}})
2813 d.update({"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',)
2814 d.update({"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',)
2815 d.update({"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',)
2816 <<< Finished
2817 >>> Testing StringToChars using d.update({"abcF" : Mapping({%s : 1})})
2818 d.update({"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',)
2819 d.update({"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',)
2820 d.update({"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',)
2821 <<< Finished
2822 >>> Testing *Iter* using d.update({"abcF" : %s})
2823 d.update({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',)
2824 d.update({"abcF" : FailingIterNext()}):NotImplementedError:('next',)
2825 <<< Finished
2826 >>> Testing ConvertFromPyObject using d.update({"abcF" : %s})
2827 d.update({"abcF" : None}):NOT FAILED
2828 d.update({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',)
2829 d.update({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',)
2830 d.update({"abcF" : FailingMapping()}):NotImplementedError:('keys',)
2831 d.update({"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',)
2832 d.update({"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',)
2833 <<< Finished
2834 >>> Testing StringToChars using d.update(Mapping({%s : 1}))
2835 d.update(Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',)
2836 d.update(Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',)
2837 d.update(Mapping({"\0" : 1})):TypeError:('expected string without null bytes',)
2838 <<< Finished
2839 >>> Testing StringToChars using d.update(Mapping({"abcG" : {%s : 1}}))
2840 d.update(Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',)
2841 d.update(Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',)
2842 d.update(Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',)
2843 <<< Finished
2844 >>> Testing StringToChars using d.update(Mapping({"abcG" : Mapping({%s : 1})}))
2845 d.update(Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',)
2846 d.update(Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',)
2847 d.update(Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',)
2848 <<< Finished
2849 >>> Testing *Iter* using d.update(Mapping({"abcG" : %s}))
2850 d.update(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to a Vim structure',)
2851 d.update(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',)
2852 <<< Finished
2853 >>> Testing ConvertFromPyObject using d.update(Mapping({"abcG" : %s}))
2854 d.update(Mapping({"abcG" : None})):NOT FAILED
2855 d.update(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',)
2856 d.update(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',)
2857 d.update(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',)
2858 d.update(Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',)
2859 d.update(Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',)
2860 <<< Finished
2861 >>> Testing *Iter* using d.update(%s)
2862 d.update(FailingIter()):NotImplementedError:('iter',)
2863 d.update(FailingIterNext()):NotImplementedError:('next',)
2864 <<< Finished
2865 >>> Testing ConvertFromPyObject using d.update(%s)
2866 d.update(None):TypeError:("'NoneType' object is not iterable",)
2867 d.update({"": 1}):ValueError:('empty keys are not allowed',)
2868 d.update({u"": 1}):ValueError:('empty keys are not allowed',)
2869 d.update(FailingMapping()):NotImplementedError:('keys',)
2870 d.update(FailingMappingKey()):NotImplementedError:('getitem:mappingkey',)
2871 d.update(FailingNumber()):TypeError:("'FailingNumber' object is not iterable",)
2872 <<< Finished
2873 >>> Testing StringToChars using d.update(((%s, 0),))
2874 d.update(((1, 0),)):TypeError:('expected str() or unicode() instance, but got int',)
2875 d.update(((u"\0", 0),)):TypeError:('expected string without null bytes',)
2876 d.update((("\0", 0),)):TypeError:('expected string without null bytes',)
2877 <<< Finished
2878 >>> Testing StringToChars using d.update((("a", {%s : 1}),))
2879 d.update((("a", {1 : 1}),)):TypeError:('expected str() or unicode() instance, but got int',)
2880 d.update((("a", {u"\0" : 1}),)):TypeError:('expected string without null bytes',)
2881 d.update((("a", {"\0" : 1}),)):TypeError:('expected string without null bytes',)
2882 <<< Finished
2883 >>> Testing StringToChars using d.update((("a", {"abcF" : {%s : 1}}),))
2884 d.update((("a", {"abcF" : {1 : 1}}),)):TypeError:('expected str() or unicode() instance, but got int',)
2885 d.update((("a", {"abcF" : {u"\0" : 1}}),)):TypeError:('expected string without null bytes',)
2886 d.update((("a", {"abcF" : {"\0" : 1}}),)):TypeError:('expected string without null bytes',)
2887 <<< Finished
2888 >>> Testing StringToChars using d.update((("a", {"abcF" : Mapping({%s : 1})}),))
2889 d.update((("a", {"abcF" : Mapping({1 : 1})}),)):TypeError:('expected str() or unicode() instance, but got int',)
2890 d.update((("a", {"abcF" : Mapping({u"\0" : 1})}),)):TypeError:('expected string without null bytes',)
2891 d.update((("a", {"abcF" : Mapping({"\0" : 1})}),)):TypeError:('expected string without null bytes',)
2892 <<< Finished
2893 >>> Testing *Iter* using d.update((("a", {"abcF" : %s}),))
2894 d.update((("a", {"abcF" : FailingIter()}),)):TypeError:('unable to convert FailingIter to a Vim structure',)
2895 d.update((("a", {"abcF" : FailingIterNext()}),)):NotImplementedError:('next',)
2896 <<< Finished
2897 >>> Testing ConvertFromPyObject using d.update((("a", {"abcF" : %s}),))
2898 d.update((("a", {"abcF" : None}),)):error:("failed to add key 'a' to dictionary",)
2899 d.update((("a", {"abcF" : {"": 1}}),)):ValueError:('empty keys are not allowed',)
2900 d.update((("a", {"abcF" : {u"": 1}}),)):ValueError:('empty keys are not allowed',)
2901 d.update((("a", {"abcF" : FailingMapping()}),)):NotImplementedError:('keys',)
2902 d.update((("a", {"abcF" : FailingMappingKey()}),)):NotImplementedError:('getitem:mappingkey',)
2903 d.update((("a", {"abcF" : FailingNumber()}),)):TypeError:('long() argument must be a string or a number',)
2904 <<< Finished
2905 >>> Testing StringToChars using d.update((("a", Mapping({%s : 1})),))
2906 d.update((("a", Mapping({1 : 1})),)):TypeError:('expected str() or unicode() instance, but got int',)
2907 d.update((("a", Mapping({u"\0" : 1})),)):TypeError:('expected string without null bytes',)
2908 d.update((("a", Mapping({"\0" : 1})),)):TypeError:('expected string without null bytes',)
2909 <<< Finished
2910 >>> Testing StringToChars using d.update((("a", Mapping({"abcG" : {%s : 1}})),))
2911 d.update((("a", Mapping({"abcG" : {1 : 1}})),)):TypeError:('expected str() or unicode() instance, but got int',)
2912 d.update((("a", Mapping({"abcG" : {u"\0" : 1}})),)):TypeError:('expected string without null bytes',)
2913 d.update((("a", Mapping({"abcG" : {"\0" : 1}})),)):TypeError:('expected string without null bytes',)
2914 <<< Finished
2915 >>> Testing StringToChars using d.update((("a", Mapping({"abcG" : Mapping({%s : 1})})),))
2916 d.update((("a", Mapping({"abcG" : Mapping({1 : 1})})),)):TypeError:('expected str() or unicode() instance, but got int',)
2917 d.update((("a", Mapping({"abcG" : Mapping({u"\0" : 1})})),)):TypeError:('expected string without null bytes',)
2918 d.update((("a", Mapping({"abcG" : Mapping({"\0" : 1})})),)):TypeError:('expected string without null bytes',)
2919 <<< Finished
2920 >>> Testing *Iter* using d.update((("a", Mapping({"abcG" : %s})),))
2921 d.update((("a", Mapping({"abcG" : FailingIter()})),)):TypeError:('unable to convert FailingIter to a Vim structure',)
2922 d.update((("a", Mapping({"abcG" : FailingIterNext()})),)):NotImplementedError:('next',)
2923 <<< Finished
2924 >>> Testing ConvertFromPyObject using d.update((("a", Mapping({"abcG" : %s})),))
2925 d.update((("a", Mapping({"abcG" : None})),)):error:("failed to add key 'a' to dictionary",)
2926 d.update((("a", Mapping({"abcG" : {"": 1}})),)):ValueError:('empty keys are not allowed',)
2927 d.update((("a", Mapping({"abcG" : {u"": 1}})),)):ValueError:('empty keys are not allowed',)
2928 d.update((("a", Mapping({"abcG" : FailingMapping()})),)):NotImplementedError:('keys',)
2929 d.update((("a", Mapping({"abcG" : FailingMappingKey()})),)):NotImplementedError:('getitem:mappingkey',)
2930 d.update((("a", Mapping({"abcG" : FailingNumber()})),)):TypeError:('long() argument must be a string or a number',)
2931 <<< Finished
2932 >>> Testing *Iter* using d.update((("a", %s),))
2933 d.update((("a", FailingIter()),)):TypeError:('unable to convert FailingIter to a Vim structure',)
2934 d.update((("a", FailingIterNext()),)):NotImplementedError:('next',)
2935 <<< Finished
2936 >>> Testing ConvertFromPyObject using d.update((("a", %s),))
2937 d.update((("a", None),)):error:("failed to add key 'a' to dictionary",)
2938 d.update((("a", {"": 1}),)):ValueError:('empty keys are not allowed',)
2939 d.update((("a", {u"": 1}),)):ValueError:('empty keys are not allowed',)
2940 d.update((("a", FailingMapping()),)):NotImplementedError:('keys',)
2941 d.update((("a", FailingMappingKey()),)):NotImplementedError:('getitem:mappingkey',)
2942 d.update((("a", FailingNumber()),)):TypeError:('long() argument must be a string or a number',)
2943 <<< Finished
2944 >> DictionaryPopItem
2945 d.popitem(1, 2):TypeError:('popitem() takes no arguments (2 given)',)
2946 >> DictionaryHasKey
2947 d.has_key():TypeError:('has_key() takes exactly one argument (0 given)',)
2948 > List
2949 >> ListConstructor
2950 vim.List(1, 2):TypeError:('function takes at most 1 argument (2 given)',)
2951 vim.List(a=1):TypeError:('list constructor does not accept keyword arguments',)
2952 >>> Testing *Iter* using vim.List(%s)
2953 vim.List(FailingIter()):NotImplementedError:('iter',)
2954 vim.List(FailingIterNext()):NotImplementedError:('next',)
2955 <<< Finished
2956 >>> Testing StringToChars using vim.List([{%s : 1}])
2957 vim.List([{1 : 1}]):TypeError:('expected str() or unicode() instance, but got int',)
2958 vim.List([{u"\0" : 1}]):TypeError:('expected string without null bytes',)
2959 vim.List([{"\0" : 1}]):TypeError:('expected string without null bytes',)
2960 <<< Finished
2961 >>> Testing StringToChars using vim.List([{"abcF" : {%s : 1}}])
2962 vim.List([{"abcF" : {1 : 1}}]):TypeError:('expected str() or unicode() instance, but got int',)
2963 vim.List([{"abcF" : {u"\0" : 1}}]):TypeError:('expected string without null bytes',)
2964 vim.List([{"abcF" : {"\0" : 1}}]):TypeError:('expected string without null bytes',)
2965 <<< Finished
2966 >>> Testing StringToChars using vim.List([{"abcF" : Mapping({%s : 1})}])
2967 vim.List([{"abcF" : Mapping({1 : 1})}]):TypeError:('expected str() or unicode() instance, but got int',)
2968 vim.List([{"abcF" : Mapping({u"\0" : 1})}]):TypeError:('expected string without null bytes',)
2969 vim.List([{"abcF" : Mapping({"\0" : 1})}]):TypeError:('expected string without null bytes',)
2970 <<< Finished
2971 >>> Testing *Iter* using vim.List([{"abcF" : %s}])
2972 vim.List([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter to a Vim structure',)
2973 vim.List([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',)
2974 <<< Finished
2975 >>> Testing ConvertFromPyObject using vim.List([{"abcF" : %s}])
2976 vim.List([{"abcF" : None}]):NOT FAILED
2977 vim.List([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',)
2978 vim.List([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',)
2979 vim.List([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',)
2980 vim.List([{"abcF" : FailingMappingKey()}]):NotImplementedError:('getitem:mappingkey',)
2981 vim.List([{"abcF" : FailingNumber()}]):TypeError:('long() argument must be a string or a number',)
2982 <<< Finished
2983 >>> Testing StringToChars using vim.List([Mapping({%s : 1})])
2984 vim.List([Mapping({1 : 1})]):TypeError:('expected str() or unicode() instance, but got int',)
2985 vim.List([Mapping({u"\0" : 1})]):TypeError:('expected string without null bytes',)
2986 vim.List([Mapping({"\0" : 1})]):TypeError:('expected string without null bytes',)
2987 <<< Finished
2988 >>> Testing StringToChars using vim.List([Mapping({"abcG" : {%s : 1}})])
2989 vim.List([Mapping({"abcG" : {1 : 1}})]):TypeError:('expected str() or unicode() instance, but got int',)
2990 vim.List([Mapping({"abcG" : {u"\0" : 1}})]):TypeError:('expected string without null bytes',)
2991 vim.List([Mapping({"abcG" : {"\0" : 1}})]):TypeError:('expected string without null bytes',)
2992 <<< Finished
2993 >>> Testing StringToChars using vim.List([Mapping({"abcG" : Mapping({%s : 1})})])
2994 vim.List([Mapping({"abcG" : Mapping({1 : 1})})]):TypeError:('expected str() or unicode() instance, but got int',)
2995 vim.List([Mapping({"abcG" : Mapping({u"\0" : 1})})]):TypeError:('expected string without null bytes',)
2996 vim.List([Mapping({"abcG" : Mapping({"\0" : 1})})]):TypeError:('expected string without null bytes',)
2997 <<< Finished
2998 >>> Testing *Iter* using vim.List([Mapping({"abcG" : %s})])
2999 vim.List([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert FailingIter to a Vim structure',)
3000 vim.List([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',)
3001 <<< Finished
3002 >>> Testing ConvertFromPyObject using vim.List([Mapping({"abcG" : %s})])
3003 vim.List([Mapping({"abcG" : None})]):NOT FAILED
3004 vim.List([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',)
3005 vim.List([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',)
3006 vim.List([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',)
3007 vim.List([Mapping({"abcG" : FailingMappingKey()})]):NotImplementedError:('getitem:mappingkey',)
3008 vim.List([Mapping({"abcG" : FailingNumber()})]):TypeError:('long() argument must be a string or a number',)
3009 <<< Finished
3010 >>> Testing *Iter* using vim.List([%s])
3011 vim.List([FailingIter()]):TypeError:('unable to convert FailingIter to a Vim structure',)
3012 vim.List([FailingIterNext()]):NotImplementedError:('next',)
3013 <<< Finished
3014 >>> Testing ConvertFromPyObject using vim.List([%s])
3015 vim.List([None]):NOT FAILED
3016 vim.List([{"": 1}]):ValueError:('empty keys are not allowed',)
3017 vim.List([{u"": 1}]):ValueError:('empty keys are not allowed',)
3018 vim.List([FailingMapping()]):NotImplementedError:('keys',)
3019 vim.List([FailingMappingKey()]):NotImplementedError:('getitem:mappingkey',)
3020 vim.List([FailingNumber()]):TypeError:('long() argument must be a string or a number',)
3021 <<< Finished
3022 >> ListItem
3023 l[1000]:IndexError:('list index out of range',)
3024 >> ListAssItem
3025 ll[1] = 2:error:('list is locked',)
3026 l[1000] = 3:IndexError:('list index out of range',)
3027 >> ListAssSlice
3028 ll[1:100] = "abcJ":error:('list is locked',)
3029 >>> Testing *Iter* using l[:] = %s
3030 l[:] = FailingIter():NotImplementedError:('iter',)
3031 l[:] = FailingIterNext():NotImplementedError:('next',)
3032 <<< Finished
3033 nel[1:10:2] = "abcK":ValueError:('attempt to assign sequence of size greater than 2 to extended slice',)
3034 ('a', 'b', 'c', 'O')
3035 nel[1:10:2] = "a":ValueError:('attempt to assign sequence of size 1 to extended slice of size 2',)
3036 ('a', 'b', 'c', 'O')
3037 nel[1:1:-1] = "a":ValueError:('attempt to assign sequence of size greater than 0 to extended slice',)
3038 ('a', 'b', 'c', 'O')
3039 nel[:] = FailingIterNextN(2):NotImplementedError:('next N',)
3040 ('a', 'b', 'c', 'O')
3041 >>> Testing StringToChars using l[:] = [{%s : 1}]
3042 l[:] = [{1 : 1}]:TypeError:('expected str() or unicode() instance, but got int',)
3043 l[:] = [{u"\0" : 1}]:TypeError:('expected string without null bytes',)
3044 l[:] = [{"\0" : 1}]:TypeError:('expected string without null bytes',)
3045 <<< Finished
3046 >>> Testing StringToChars using l[:] = [{"abcF" : {%s : 1}}]
3047 l[:] = [{"abcF" : {1 : 1}}]:TypeError:('expected str() or unicode() instance, but got int',)
3048 l[:] = [{"abcF" : {u"\0" : 1}}]:TypeError:('expected string without null bytes',)
3049 l[:] = [{"abcF" : {"\0" : 1}}]:TypeError:('expected string without null bytes',)
3050 <<< Finished
3051 >>> Testing StringToChars using l[:] = [{"abcF" : Mapping({%s : 1})}]
3052 l[:] = [{"abcF" : Mapping({1 : 1})}]:TypeError:('expected str() or unicode() instance, but got int',)
3053 l[:] = [{"abcF" : Mapping({u"\0" : 1})}]:TypeError:('expected string without null bytes',)
3054 l[:] = [{"abcF" : Mapping({"\0" : 1})}]:TypeError:('expected string without null bytes',)
3055 <<< Finished
3056 >>> Testing *Iter* using l[:] = [{"abcF" : %s}]
3057 l[:] = [{"abcF" : FailingIter()}]:TypeError:('unable to convert FailingIter to a Vim structure',)
3058 l[:] = [{"abcF" : FailingIterNext()}]:NotImplementedError:('next',)
3059 <<< Finished
3060 >>> Testing ConvertFromPyObject using l[:] = [{"abcF" : %s}]
3061 l[:] = [{"abcF" : None}]:NOT FAILED
3062 l[:] = [{"abcF" : {"": 1}}]:ValueError:('empty keys are not allowed',)
3063 l[:] = [{"abcF" : {u"": 1}}]:ValueError:('empty keys are not allowed',)
3064 l[:] = [{"abcF" : FailingMapping()}]:NotImplementedError:('keys',)
3065 l[:] = [{"abcF" : FailingMappingKey()}]:NotImplementedError:('getitem:mappingkey',)
3066 l[:] = [{"abcF" : FailingNumber()}]:TypeError:('long() argument must be a string or a number',)
3067 <<< Finished
3068 >>> Testing StringToChars using l[:] = [Mapping({%s : 1})]
3069 l[:] = [Mapping({1 : 1})]:TypeError:('expected str() or unicode() instance, but got int',)
3070 l[:] = [Mapping({u"\0" : 1})]:TypeError:('expected string without null bytes',)
3071 l[:] = [Mapping({"\0" : 1})]:TypeError:('expected string without null bytes',)
3072 <<< Finished
3073 >>> Testing StringToChars using l[:] = [Mapping({"abcG" : {%s : 1}})]
3074 l[:] = [Mapping({"abcG" : {1 : 1}})]:TypeError:('expected str() or unicode() instance, but got int',)
3075 l[:] = [Mapping({"abcG" : {u"\0" : 1}})]:TypeError:('expected string without null bytes',)
3076 l[:] = [Mapping({"abcG" : {"\0" : 1}})]:TypeError:('expected string without null bytes',)
3077 <<< Finished
3078 >>> Testing StringToChars using l[:] = [Mapping({"abcG" : Mapping({%s : 1})})]
3079 l[:] = [Mapping({"abcG" : Mapping({1 : 1})})]:TypeError:('expected str() or unicode() instance, but got int',)
3080 l[:] = [Mapping({"abcG" : Mapping({u"\0" : 1})})]:TypeError:('expected string without null bytes',)
3081 l[:] = [Mapping({"abcG" : Mapping({"\0" : 1})})]:TypeError:('expected string without null bytes',)
3082 <<< Finished
3083 >>> Testing *Iter* using l[:] = [Mapping({"abcG" : %s})]
3084 l[:] = [Mapping({"abcG" : FailingIter()})]:TypeError:('unable to convert FailingIter to a Vim structure',)
3085 l[:] = [Mapping({"abcG" : FailingIterNext()})]:NotImplementedError:('next',)
3086 <<< Finished
3087 >>> Testing ConvertFromPyObject using l[:] = [Mapping({"abcG" : %s})]
3088 l[:] = [Mapping({"abcG" : None})]:NOT FAILED
3089 l[:] = [Mapping({"abcG" : {"": 1}})]:ValueError:('empty keys are not allowed',)
3090 l[:] = [Mapping({"abcG" : {u"": 1}})]:ValueError:('empty keys are not allowed',)
3091 l[:] = [Mapping({"abcG" : FailingMapping()})]:NotImplementedError:('keys',)
3092 l[:] = [Mapping({"abcG" : FailingMappingKey()})]:NotImplementedError:('getitem:mappingkey',)
3093 l[:] = [Mapping({"abcG" : FailingNumber()})]:TypeError:('long() argument must be a string or a number',)
3094 <<< Finished
3095 >>> Testing *Iter* using l[:] = [%s]
3096 l[:] = [FailingIter()]:TypeError:('unable to convert FailingIter to a Vim structure',)
3097 l[:] = [FailingIterNext()]:NotImplementedError:('next',)
3098 <<< Finished
3099 >>> Testing ConvertFromPyObject using l[:] = [%s]
3100 l[:] = [None]:NOT FAILED
3101 l[:] = [{"": 1}]:ValueError:('empty keys are not allowed',)
3102 l[:] = [{u"": 1}]:ValueError:('empty keys are not allowed',)
3103 l[:] = [FailingMapping()]:NotImplementedError:('keys',)
3104 l[:] = [FailingMappingKey()]:NotImplementedError:('getitem:mappingkey',)
3105 l[:] = [FailingNumber()]:TypeError:('long() argument must be a string or a number',)
3106 <<< Finished
3107 >> ListConcatInPlace
3108 >>> Testing *Iter* using l.extend(%s)
3109 l.extend(FailingIter()):NotImplementedError:('iter',)
3110 l.extend(FailingIterNext()):NotImplementedError:('next',)
3111 <<< Finished
3112 >>> Testing StringToChars using l.extend([{%s : 1}])
3113 l.extend([{1 : 1}]):TypeError:('expected str() or unicode() instance, but got int',)
3114 l.extend([{u"\0" : 1}]):TypeError:('expected string without null bytes',)
3115 l.extend([{"\0" : 1}]):TypeError:('expected string without null bytes',)
3116 <<< Finished
3117 >>> Testing StringToChars using l.extend([{"abcF" : {%s : 1}}])
3118 l.extend([{"abcF" : {1 : 1}}]):TypeError:('expected str() or unicode() instance, but got int',)
3119 l.extend([{"abcF" : {u"\0" : 1}}]):TypeError:('expected string without null bytes',)
3120 l.extend([{"abcF" : {"\0" : 1}}]):TypeError:('expected string without null bytes',)
3121 <<< Finished
3122 >>> Testing StringToChars using l.extend([{"abcF" : Mapping({%s : 1})}])
3123 l.extend([{"abcF" : Mapping({1 : 1})}]):TypeError:('expected str() or unicode() instance, but got int',)
3124 l.extend([{"abcF" : Mapping({u"\0" : 1})}]):TypeError:('expected string without null bytes',)
3125 l.extend([{"abcF" : Mapping({"\0" : 1})}]):TypeError:('expected string without null bytes',)
3126 <<< Finished
3127 >>> Testing *Iter* using l.extend([{"abcF" : %s}])
3128 l.extend([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter to a Vim structure',)
3129 l.extend([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',)
3130 <<< Finished
3131 >>> Testing ConvertFromPyObject using l.extend([{"abcF" : %s}])
3132 l.extend([{"abcF" : None}]):NOT FAILED
3133 l.extend([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',)
3134 l.extend([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',)
3135 l.extend([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',)
3136 l.extend([{"abcF" : FailingMappingKey()}]):NotImplementedError:('getitem:mappingkey',)
3137 l.extend([{"abcF" : FailingNumber()}]):TypeError:('long() argument must be a string or a number',)
3138 <<< Finished
3139 >>> Testing StringToChars using l.extend([Mapping({%s : 1})])
3140 l.extend([Mapping({1 : 1})]):TypeError:('expected str() or unicode() instance, but got int',)
3141 l.extend([Mapping({u"\0" : 1})]):TypeError:('expected string without null bytes',)
3142 l.extend([Mapping({"\0" : 1})]):TypeError:('expected string without null bytes',)
3143 <<< Finished
3144 >>> Testing StringToChars using l.extend([Mapping({"abcG" : {%s : 1}})])
3145 l.extend([Mapping({"abcG" : {1 : 1}})]):TypeError:('expected str() or unicode() instance, but got int',)
3146 l.extend([Mapping({"abcG" : {u"\0" : 1}})]):TypeError:('expected string without null bytes',)
3147 l.extend([Mapping({"abcG" : {"\0" : 1}})]):TypeError:('expected string without null bytes',)
3148 <<< Finished
3149 >>> Testing StringToChars using l.extend([Mapping({"abcG" : Mapping({%s : 1})})])
3150 l.extend([Mapping({"abcG" : Mapping({1 : 1})})]):TypeError:('expected str() or unicode() instance, but got int',)
3151 l.extend([Mapping({"abcG" : Mapping({u"\0" : 1})})]):TypeError:('expected string without null bytes',)
3152 l.extend([Mapping({"abcG" : Mapping({"\0" : 1})})]):TypeError:('expected string without null bytes',)
3153 <<< Finished
3154 >>> Testing *Iter* using l.extend([Mapping({"abcG" : %s})])
3155 l.extend([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert FailingIter to a Vim structure',)
3156 l.extend([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',)
3157 <<< Finished
3158 >>> Testing ConvertFromPyObject using l.extend([Mapping({"abcG" : %s})])
3159 l.extend([Mapping({"abcG" : None})]):NOT FAILED
3160 l.extend([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',)
3161 l.extend([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',)
3162 l.extend([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',)
3163 l.extend([Mapping({"abcG" : FailingMappingKey()})]):NotImplementedError:('getitem:mappingkey',)
3164 l.extend([Mapping({"abcG" : FailingNumber()})]):TypeError:('long() argument must be a string or a number',)
3165 <<< Finished
3166 >>> Testing *Iter* using l.extend([%s])
3167 l.extend([FailingIter()]):TypeError:('unable to convert FailingIter to a Vim structure',)
3168 l.extend([FailingIterNext()]):NotImplementedError:('next',)
3169 <<< Finished
3170 >>> Testing ConvertFromPyObject using l.extend([%s])
3171 l.extend([None]):NOT FAILED
3172 l.extend([{"": 1}]):ValueError:('empty keys are not allowed',)
3173 l.extend([{u"": 1}]):ValueError:('empty keys are not allowed',)
3174 l.extend([FailingMapping()]):NotImplementedError:('keys',)
3175 l.extend([FailingMappingKey()]):NotImplementedError:('getitem:mappingkey',)
3176 l.extend([FailingNumber()]):TypeError:('long() argument must be a string or a number',)
3177 <<< Finished
3178 >> ListSetattr
3179 del l.locked:AttributeError:('cannot delete vim.List attributes',)
3180 l.locked = FailingTrue():NotImplementedError:('bool',)
3181 l.xxx = True:AttributeError:('cannot set attribute xxx',)
3182 > Function
3183 >> FunctionConstructor
3184 >>> FunctionConstructor
3185 vim.Function("123"):ValueError:('unnamed function 123 does not exist',)
3186 vim.Function("xxx_non_existent_function_xxx"):ValueError:('function xxx_non_existent_function_xxx does not exist',)
3187 vim.Function("xxx#non#existent#function#xxx"):NOT FAILED
3188 vim.Function("xxx_non_existent_function_xxx2", args=[]):ValueError:('function xxx_non_existent_function_xxx2 does not exist',)
3189 vim.Function("xxx_non_existent_function_xxx3", self={}):ValueError:('function xxx_non_existent_function_xxx3 does not exist',)
3190 vim.Function("xxx_non_existent_function_xxx4", args=[], self={}):ValueError:('function xxx_non_existent_function_xxx4 does not exist',)
3191 >>> FunctionNew
3192 vim.Function("tr", self="abcFuncSelf"):TypeError:('unable to convert str to a Vim dictionary',)
3193 vim.Function("tr", args=427423):TypeError:('unable to convert int to a Vim list',)
3194 vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to a Vim dictionary',)
3195 vim.Function(self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to a Vim dictionary',)
3196 vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to a Vim dictionary',)
3197 vim.Function("tr", ""):TypeError:('function takes exactly 1 argument (2 given)',)
3198 >> FunctionCall
3199 >>> Testing StringToChars using f({%s : 1})
3200 f({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',)
3201 f({u"\0" : 1}):TypeError:('expected string without null bytes',)
3202 f({"\0" : 1}):TypeError:('expected string without null bytes',)
3203 <<< Finished
3204 >>> Testing StringToChars using f({"abcF" : {%s : 1}})
3205 f({"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',)
3206 f({"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',)
3207 f({"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',)
3208 <<< Finished
3209 >>> Testing StringToChars using f({"abcF" : Mapping({%s : 1})})
3210 f({"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',)
3211 f({"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',)
3212 f({"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',)
3213 <<< Finished
3214 >>> Testing *Iter* using f({"abcF" : %s})
3215 f({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',)
3216 f({"abcF" : FailingIterNext()}):NotImplementedError:('next',)
3217 <<< Finished
3218 >>> Testing ConvertFromPyObject using f({"abcF" : %s})
3219 f({"abcF" : None}):NOT FAILED
3220 f({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',)
3221 f({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',)
3222 f({"abcF" : FailingMapping()}):NotImplementedError:('keys',)
3223 f({"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',)
3224 f({"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',)
3225 <<< Finished
3226 >>> Testing StringToChars using f(Mapping({%s : 1}))
3227 f(Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',)
3228 f(Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',)
3229 f(Mapping({"\0" : 1})):TypeError:('expected string without null bytes',)
3230 <<< Finished
3231 >>> Testing StringToChars using f(Mapping({"abcG" : {%s : 1}}))
3232 f(Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',)
3233 f(Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',)
3234 f(Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',)
3235 <<< Finished
3236 >>> Testing StringToChars using f(Mapping({"abcG" : Mapping({%s : 1})}))
3237 f(Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',)
3238 f(Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',)
3239 f(Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',)
3240 <<< Finished
3241 >>> Testing *Iter* using f(Mapping({"abcG" : %s}))
3242 f(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to a Vim structure',)
3243 f(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',)
3244 <<< Finished
3245 >>> Testing ConvertFromPyObject using f(Mapping({"abcG" : %s}))
3246 f(Mapping({"abcG" : None})):NOT FAILED
3247 f(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',)
3248 f(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',)
3249 f(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',)
3250 f(Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',)
3251 f(Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',)
3252 <<< Finished
3253 >>> Testing *Iter* using f(%s)
3254 f(FailingIter()):TypeError:('unable to convert FailingIter to a Vim structure',)
3255 f(FailingIterNext()):NotImplementedError:('next',)
3256 <<< Finished
3257 >>> Testing ConvertFromPyObject using f(%s)
3258 f(None):NOT FAILED
3259 f({"": 1}):ValueError:('empty keys are not allowed',)
3260 f({u"": 1}):ValueError:('empty keys are not allowed',)
3261 f(FailingMapping()):NotImplementedError:('keys',)
3262 f(FailingMappingKey()):NotImplementedError:('getitem:mappingkey',)
3263 f(FailingNumber()):TypeError:('long() argument must be a string or a number',)
3264 <<< Finished
3265 >>> Testing StringToChars using fd(self={%s : 1})
3266 fd(self={1 : 1}):TypeError:('expected str() or unicode() instance, but got int',)
3267 fd(self={u"\0" : 1}):TypeError:('expected string without null bytes',)
3268 fd(self={"\0" : 1}):TypeError:('expected string without null bytes',)
3269 <<< Finished
3270 >>> Testing StringToChars using fd(self={"abcF" : {%s : 1}})
3271 fd(self={"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',)
3272 fd(self={"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',)
3273 fd(self={"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',)
3274 <<< Finished
3275 >>> Testing StringToChars using fd(self={"abcF" : Mapping({%s : 1})})
3276 fd(self={"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',)
3277 fd(self={"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',)
3278 fd(self={"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',)
3279 <<< Finished
3280 >>> Testing *Iter* using fd(self={"abcF" : %s})
3281 fd(self={"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',)
3282 fd(self={"abcF" : FailingIterNext()}):NotImplementedError:('next',)
3283 <<< Finished
3284 >>> Testing ConvertFromPyObject using fd(self={"abcF" : %s})
3285 fd(self={"abcF" : None}):NOT FAILED
3286 fd(self={"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',)
3287 fd(self={"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',)
3288 fd(self={"abcF" : FailingMapping()}):NotImplementedError:('keys',)
3289 fd(self={"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',)
3290 fd(self={"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',)
3291 <<< Finished
3292 >>> Testing StringToChars using fd(self=Mapping({%s : 1}))
3293 fd(self=Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',)
3294 fd(self=Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',)
3295 fd(self=Mapping({"\0" : 1})):TypeError:('expected string without null bytes',)
3296 <<< Finished
3297 >>> Testing StringToChars using fd(self=Mapping({"abcG" : {%s : 1}}))
3298 fd(self=Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',)
3299 fd(self=Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',)
3300 fd(self=Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',)
3301 <<< Finished
3302 >>> Testing StringToChars using fd(self=Mapping({"abcG" : Mapping({%s : 1})}))
3303 fd(self=Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',)
3304 fd(self=Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',)
3305 fd(self=Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',)
3306 <<< Finished
3307 >>> Testing *Iter* using fd(self=Mapping({"abcG" : %s}))
3308 fd(self=Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to a Vim structure',)
3309 fd(self=Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',)
3310 <<< Finished
3311 >>> Testing ConvertFromPyObject using fd(self=Mapping({"abcG" : %s}))
3312 fd(self=Mapping({"abcG" : None})):NOT FAILED
3313 fd(self=Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',)
3314 fd(self=Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',)
3315 fd(self=Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',)
3316 fd(self=Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',)
3317 fd(self=Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',)
3318 <<< Finished
3319 >>> Testing *Iter* using fd(self=%s)
3320 fd(self=FailingIter()):TypeError:('unable to convert FailingIter to a Vim dictionary',)
3321 fd(self=FailingIterNext()):TypeError:('unable to convert FailingIterNext to a Vim dictionary',)
3322 <<< Finished
3323 >>> Testing ConvertFromPyObject using fd(self=%s)
3324 fd(self=None):TypeError:('unable to convert NoneType to a Vim dictionary',)
3325 fd(self={"": 1}):ValueError:('empty keys are not allowed',)
3326 fd(self={u"": 1}):ValueError:('empty keys are not allowed',)
3327 fd(self=FailingMapping()):NotImplementedError:('keys',)
3328 fd(self=FailingMappingKey()):NotImplementedError:('getitem:mappingkey',)
3329 fd(self=FailingNumber()):TypeError:('unable to convert FailingNumber to a Vim dictionary',)
3330 <<< Finished
3331 >>> Testing ConvertFromPyMapping using fd(self=%s)
3332 fd(self=[]):TypeError:('unable to convert list to a Vim dictionary',)
3333 <<< Finished
3334 > TabPage
3335 >> TabPageAttr
3336 vim.current.tabpage.xxx:AttributeError:('xxx',)
3337 > TabList
3338 >> TabListItem
3339 vim.tabpages[1000]:IndexError:('no such tab page',)
3340 > Window
3341 >> WindowAttr
3342 vim.current.window.xxx:AttributeError:('xxx',)
3343 >> WindowSetattr
3344 vim.current.window.buffer = 0:TypeError:('readonly attribute: buffer',)
3345 vim.current.window.cursor = (100000000, 100000000):error:('cursor position outside buffer',)
3346 vim.current.window.cursor = True:TypeError:('argument must be 2-item sequence, not bool',)
3347 >>> Testing NumberToLong using vim.current.window.height = %s
3348 vim.current.window.height = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',)
3349 vim.current.window.height = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',)
3350 vim.current.window.height = -1:ValueError:('number must be greater or equal to zero',)
3351 <<< Finished
3352 >>> Testing NumberToLong using vim.current.window.width = %s
3353 vim.current.window.width = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',)
3354 vim.current.window.width = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',)
3355 vim.current.window.width = -1:ValueError:('number must be greater or equal to zero',)
3356 <<< Finished
3357 vim.current.window.xxxxxx = True:AttributeError:('xxxxxx',)
3358 > WinList
3359 >> WinListItem
3360 vim.windows[1000]:IndexError:('no such window',)
3361 > Buffer
3362 >> StringToLine (indirect)
3363 vim.current.buffer[0] = u"\na":error:('string cannot contain newlines',)
3364 vim.current.buffer[0] = "\na":error:('string cannot contain newlines',)
3365 >> SetBufferLine (indirect)
3366 vim.current.buffer[0] = True:TypeError:('bad argument type for built-in operation',)
3367 >> SetBufferLineList (indirect)
3368 vim.current.buffer[:] = True:TypeError:('bad argument type for built-in operation',)
3369 vim.current.buffer[:] = ["\na", "bc"]:error:('string cannot contain newlines',)
3370 >> InsertBufferLines (indirect)
3371 vim.current.buffer.append(None):TypeError:('bad argument type for built-in operation',)
3372 vim.current.buffer.append(["\na", "bc"]):error:('string cannot contain newlines',)
3373 vim.current.buffer.append("\nbc"):error:('string cannot contain newlines',)
3374 >> RBItem
3375 vim.current.buffer[100000000]:IndexError:('line number out of range',)
3376 >> RBAsItem
3377 vim.current.buffer[100000000] = "":IndexError:('line number out of range',)
3378 >> BufferAttr
3379 vim.current.buffer.xxx:AttributeError:('xxx',)
3380 >> BufferSetattr
3381 vim.current.buffer.name = True:TypeError:('expected str() or unicode() instance, but got bool',)
3382 vim.current.buffer.xxx = True:AttributeError:('xxx',)
3383 >> BufferMark
3384 vim.current.buffer.mark(0):TypeError:('expected str() or unicode() instance, but got int',)
3385 vim.current.buffer.mark("abcM"):ValueError:('mark name must be a single character',)
3386 vim.current.buffer.mark("!"):error:('invalid mark name',)
3387 >> BufferRange
3388 vim.current.buffer.range(1, 2, 3):TypeError:('function takes exactly 2 arguments (3 given)',)
3389 > BufMap
3390 >> BufMapItem
3391 vim.buffers[100000000]:KeyError:(100000000,)
3392 >>> Testing NumberToLong using vim.buffers[%s]
3393 vim.buffers[[]]:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',)
3394 vim.buffers[None]:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',)
3395 vim.buffers[-1]:ValueError:('number must be greater than zero',)
3396 vim.buffers[0]:ValueError:('number must be greater than zero',)
3397 <<< Finished
3398 > Current
3399 >> CurrentGetattr
3400 vim.current.xxx:AttributeError:('xxx',)
3401 >> CurrentSetattr
3402 vim.current.line = True:TypeError:('bad argument type for built-in operation',)
3403 vim.current.buffer = True:TypeError:('expected vim.Buffer object, but got bool',)
3404 vim.current.window = True:TypeError:('expected vim.Window object, but got bool',)
3405 vim.current.tabpage = True:TypeError:('expected vim.TabPage object, but got bool',)
3406 vim.current.xxx = True:AttributeError:('xxx',)
3407 END
3408
3409 call assert_equal(expected, getline(2, '$'))
3410 close!
3411endfunc
3412
3413" Test import
3414func Test_python_import()
3415 new
3416 py cb = vim.current.buffer
3417
3418 py << trim EOF
3419 sys.path.insert(0, os.path.join(os.getcwd(), 'python_before'))
3420 sys.path.append(os.path.join(os.getcwd(), 'python_after'))
3421 vim.options['rtp'] = os.getcwd().replace(',', '\\,').replace('\\', '\\\\')
3422 l = []
3423 def callback(path):
3424 l.append(path[-len('/testdir'):].replace(os.path.sep, '/'))
3425 vim.foreach_rtp(callback)
3426 cb.append(repr(l))
3427 del l
3428 def callback(path):
3429 return path[-len('/testdir'):].replace(os.path.sep, '/')
3430 cb.append(repr(vim.foreach_rtp(callback)))
3431 del callback
3432 from module import dir as d
3433 from modulex import ddir
3434 cb.append(d + ',' + ddir)
3435 import before
3436 cb.append(before.dir)
3437 import after
3438 cb.append(after.dir)
3439 import topmodule as tm
3440 import topmodule.submodule as tms
3441 import topmodule.submodule.subsubmodule.subsubsubmodule as tmsss
3442 cb.append(tm.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/__init__.py'):])
3443 cb.append(tms.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/__init__.py'):])
3444 cb.append(tmsss.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/subsubmodule/subsubsubmodule.py'):])
3445 del before
3446 del after
3447 del d
3448 del ddir
3449 del tm
3450 del tms
3451 del tmsss
3452 EOF
3453
3454 let expected =<< trim END
3455 ['/testdir']
3456 '/testdir'
3457 2,xx
3458 before
3459 after
3460 pythonx/topmodule/__init__.py
3461 pythonx/topmodule/submodule/__init__.py
3462 pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py
3463 END
3464 call assert_equal(expected, getline(2, '$'))
3465 close!
3466endfunc
3467
3468" Test exceptions
3469func Test_python_exception()
3470 fun Exe(e)
3471 execute a:e
3472 endfun
3473
3474 new
3475 py cb = vim.current.buffer
3476
3477 py << trim EOF
3478 Exe = vim.bindeval('function("Exe")')
3479 ee('vim.command("throw \'abcN\'")')
3480 ee('Exe("throw \'def\'")')
3481 ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")')
3482 ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")')
3483 ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")')
3484 ee('vim.eval("xxx_unknown_function_xxx()")')
3485 ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")')
3486 del Exe
3487 EOF
3488 delfunction Exe
3489
3490 let expected =<< trim END
3491 vim.command("throw 'abcN'"):error:('abcN',)
3492 Exe("throw 'def'"):error:('def',)
3493 vim.eval("Exe('throw ''ghi''')"):error:('ghi',)
3494 vim.eval("Exe('echoerr ''jkl''')"):error:('Vim(echoerr):jkl',)
3495 vim.eval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)
3496 vim.eval("xxx_unknown_function_xxx()"):error:('Vim:E117: Unknown function: xxx_unknown_function_xxx',)
3497 vim.bindeval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)
3498 END
3499 call assert_equal(expected, getline(2, '$'))
3500 close!
3501endfunc
3502
3503" Regression: interrupting vim.command propagates to next vim.command
3504func Test_python_keyboard_interrupt()
3505 new
3506 py cb = vim.current.buffer
3507 py << trim EOF
3508 def test_keyboard_interrupt():
3509 try:
3510 vim.command('while 1 | endwhile')
3511 except KeyboardInterrupt:
3512 cb.append('Caught KeyboardInterrupt')
3513 except Exception:
3514 cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info()))
3515 else:
3516 cb.append('!!!!!!!! No exception')
3517 try:
3518 vim.command('$ put =\'Running :put\'')
3519 except KeyboardInterrupt:
3520 cb.append('!!!!!!!! Caught KeyboardInterrupt')
3521 except Exception:
3522 cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info()))
3523 else:
3524 cb.append('No exception')
3525 EOF
3526
3527 debuggreedy
3528 call inputsave()
3529 call feedkeys("s\ns\ns\ns\nq\n")
3530 redir => output
3531 debug silent! py test_keyboard_interrupt()
3532 redir END
3533 0 debuggreedy
3534 call inputrestore()
3535 py del test_keyboard_interrupt
3536
3537 let expected =<< trim END
3538 Caught KeyboardInterrupt
3539 Running :put
3540 No exception
3541 END
3542 call assert_equal(expected, getline(2, '$'))
3543 call assert_equal('', output)
3544 close!
3545endfunc
3546
Bram Moolenaar6c2b7b82020-04-14 20:15:49 +02003547" vim: shiftwidth=2 sts=2 expandtab