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