##// END OF EJS Templates
Add test for external library linking.
Fernando Perez -
Show More
@@ -1,47 +1,56 b''
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 from IPython.utils import py3compat
7 from IPython.utils import py3compat
8
8
9 code = py3compat.str_to_unicode("""def f(x):
9 code = py3compat.str_to_unicode("""def f(x):
10 return 2*x
10 return 2*x
11 """)
11 """)
12
12
13 try:
13 try:
14 import Cython
14 import Cython
15 except:
15 except:
16 __test__ = False
16 __test__ = False
17
17
18 def setup():
19 ip = get_ipython()
18 ip = get_ipython()
19
20
21 def setup():
20 ip.extension_manager.load_extension('cythonmagic')
22 ip.extension_manager.load_extension('cythonmagic')
21
23
24
22 def test_cython_inline():
25 def test_cython_inline():
23 ip = get_ipython()
24 ip.ex('a=10; b=20')
26 ip.ex('a=10; b=20')
25 result = ip.run_cell_magic('cython_inline','','return a+b')
27 result = ip.run_cell_magic('cython_inline','','return a+b')
26 nt.assert_equals(result, 30)
28 nt.assert_equals(result, 30)
27
29
30
28 def test_cython_pyximport():
31 def test_cython_pyximport():
29 module_name = '_test_cython_pyximport'
32 module_name = '_test_cython_pyximport'
30 ip = get_ipython()
31 ip.run_cell_magic('cython_pyximport', module_name, code)
33 ip.run_cell_magic('cython_pyximport', module_name, code)
32 ip.ex('g = f(10)')
34 ip.ex('g = f(10)')
33 nt.assert_equals(ip.user_ns['g'], 20.0)
35 nt.assert_equals(ip.user_ns['g'], 20.0)
34 try:
36 try:
35 os.remove(module_name+'.pyx')
37 os.remove(module_name+'.pyx')
36 except OSError:
38 except OSError:
37 pass
39 pass
38
40
41
39 def test_cython():
42 def test_cython():
40 ip = get_ipython()
41 ip.run_cell_magic('cython', '', code)
43 ip.run_cell_magic('cython', '', code)
42 ip.ex('g = f(10)')
44 ip.ex('g = f(10)')
43 nt.assert_equals(ip.user_ns['g'], 20.0)
45 nt.assert_equals(ip.user_ns['g'], 20.0)
44
46
45
47
46
48 def test_extlibs():
49 code = py3compat.str_to_unicode("""
50 from libc.math cimport sin
51 x = sin(0.0)
52 """)
53 ip.user_ns['x'] = 1
54 ip.run_cell_magic('cython', '-l m', code)
55 nt.assert_equals(ip.user_ns['x'], 0)
47
56
General Comments 0
You need to be logged in to leave comments. Login now