##// END OF EJS Templates
Using better approach for skipping test if Cython no pres.
Brian Granger -
Show More
@@ -1,45 +1,45
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Tests for the Cython magics extension."""
2 """Tests for the Cython magics extension."""
3
3
4 import os
4 import os
5 import nose.tools as nt
5 import nose.tools as nt
6
6
7
7
8 code = """def f(x):
8 code = """def f(x):
9 return 2*x
9 return 2*x
10 """
10 """
11
11
12 try:
12 try:
13 import Cython
13 import Cython
14 except:
14 except:
15 pass
15 __test__ = False
16 else:
16
17 def setup():
17 def setup():
18 ip = get_ipython()
18 ip = get_ipython()
19 ip.extension_manager.load_extension('cythonmagic')
19 ip.extension_manager.load_extension('cythonmagic')
20
20
21 def test_cython_inline():
21 def test_cython_inline():
22 ip = get_ipython()
22 ip = get_ipython()
23 ip.ex('a=10; b=20')
23 ip.ex('a=10; b=20')
24 result = ip.run_cell_magic('cython_inline','','return a+b')
24 result = ip.run_cell_magic('cython_inline','','return a+b')
25 nt.assert_equals(result, 30)
25 nt.assert_equals(result, 30)
26
26
27 def test_cython_pyximport():
27 def test_cython_pyximport():
28 module_name = '_test_cython_pyximport'
28 module_name = '_test_cython_pyximport'
29 ip = get_ipython()
29 ip = get_ipython()
30 ip.run_cell_magic('cython_pyximport', module_name, code)
30 ip.run_cell_magic('cython_pyximport', module_name, code)
31 ip.ex('g = f(10)')
31 ip.ex('g = f(10)')
32 nt.assert_equals(ip.user_ns['g'], 20.0)
32 nt.assert_equals(ip.user_ns['g'], 20.0)
33 try:
33 try:
34 os.remove(module_name+'.pyx')
34 os.remove(module_name+'.pyx')
35 except OSError:
35 except OSError:
36 pass
36 pass
37
37
38 def test_cython():
38 def test_cython():
39 ip = get_ipython()
39 ip = get_ipython()
40 ip.run_cell_magic('cython', '', code)
40 ip.run_cell_magic('cython', '', code)
41 ip.ex('g = f(10)')
41 ip.ex('g = f(10)')
42 nt.assert_equals(ip.user_ns['g'], 20.0)
42 nt.assert_equals(ip.user_ns['g'], 20.0)
43
43
44
44
45
45
General Comments 0
You need to be logged in to leave comments. Login now