Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 1 | " Test for pyx* commands and functions with Python 2. |
| 2 | |
| 3 | set pyx=2 |
| 4 | if !has('python') |
Bram Moolenaar | b0f94c1 | 2019-06-13 22:19:53 +0200 | [diff] [blame] | 5 | throw 'Skipped, python feature missing' |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 6 | endif |
| 7 | |
| 8 | let s:py2pattern = '^2\.[0-7]\.\d\+' |
| 9 | let s:py3pattern = '^3\.\d\+\.\d\+' |
| 10 | |
| 11 | |
| 12 | func Test_has_pythonx() |
| 13 | call assert_true(has('pythonx')) |
| 14 | endfunc |
| 15 | |
| 16 | |
| 17 | func Test_pyx() |
| 18 | redir => var |
| 19 | pyx << EOF |
| 20 | import sys |
| 21 | print(sys.version) |
| 22 | EOF |
| 23 | redir END |
| 24 | call assert_match(s:py2pattern, split(var)[0]) |
| 25 | endfunc |
| 26 | |
| 27 | |
| 28 | func Test_pyxdo() |
| 29 | pyx import sys |
| 30 | enew |
| 31 | pyxdo return sys.version.split("\n")[0] |
| 32 | call assert_match(s:py2pattern, split(getline('.'))[0]) |
| 33 | endfunc |
| 34 | |
| 35 | |
| 36 | func Test_pyxeval() |
| 37 | pyx import sys |
| 38 | call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0]) |
| 39 | endfunc |
| 40 | |
| 41 | |
| 42 | func Test_pyxfile() |
| 43 | " No special comments nor shebangs |
| 44 | redir => var |
| 45 | pyxfile pyxfile/pyx.py |
| 46 | redir END |
| 47 | call assert_match(s:py2pattern, split(var)[0]) |
| 48 | |
| 49 | " Python 2 special comment |
| 50 | redir => var |
| 51 | pyxfile pyxfile/py2_magic.py |
| 52 | redir END |
| 53 | call assert_match(s:py2pattern, split(var)[0]) |
| 54 | |
| 55 | " Python 2 shebang |
| 56 | redir => var |
| 57 | pyxfile pyxfile/py2_shebang.py |
| 58 | redir END |
| 59 | call assert_match(s:py2pattern, split(var)[0]) |
| 60 | |
| 61 | if has('python3') |
| 62 | " Python 3 special comment |
| 63 | redir => var |
| 64 | pyxfile pyxfile/py3_magic.py |
| 65 | redir END |
| 66 | call assert_match(s:py3pattern, split(var)[0]) |
| 67 | |
| 68 | " Python 3 shebang |
| 69 | redir => var |
| 70 | pyxfile pyxfile/py3_shebang.py |
| 71 | redir END |
| 72 | call assert_match(s:py3pattern, split(var)[0]) |
| 73 | endif |
| 74 | endfunc |
Bram Moolenaar | 7f3a284 | 2019-05-18 15:02:25 +0200 | [diff] [blame] | 75 | |
| 76 | func Test_Catch_Exception_Message() |
| 77 | try |
| 78 | pyx raise RuntimeError( 'TEST' ) |
| 79 | catch /.*/ |
| 80 | call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception ) |
| 81 | endtry |
| 82 | endfunc |