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