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