blob: 64bd579c268eaeec76c715a29c3f86cd8dbf5398 [file] [log] [blame]
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01001" Test for pyx* commands and functions with Python 2.
2
3set pyx=2
4if !has('python')
Bram Moolenaarb0f94c12019-06-13 22:19:53 +02005 throw 'Skipped, python feature missing'
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01006endif
7
8let s:py2pattern = '^2\.[0-7]\.\d\+'
9let s:py3pattern = '^3\.\d\+\.\d\+'
10
11
12func Test_has_pythonx()
13 call assert_true(has('pythonx'))
14endfunc
15
16
17func Test_pyx()
18 redir => var
19 pyx << EOF
20import sys
21print(sys.version)
22EOF
23 redir END
24 call assert_match(s:py2pattern, split(var)[0])
25endfunc
26
27
28func 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])
33endfunc
34
35
36func Test_pyxeval()
37 pyx import sys
38 call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0])
39endfunc
40
41
42func 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
74endfunc
Bram Moolenaar7f3a2842019-05-18 15:02:25 +020075
76func Test_Catch_Exception_Message()
77 try
78 pyx raise RuntimeError( 'TEST' )
79 catch /.*/
80 call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception )
81 endtry
82endfunc