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