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 |
|
|
17 | def setup(): | |
18 |
|
|
18 | ip = get_ipython() | |
19 |
|
|
19 | ip.extension_manager.load_extension('cythonmagic') | |
20 |
|
20 | |||
21 |
|
|
21 | def test_cython_inline(): | |
22 |
|
|
22 | ip = get_ipython() | |
23 |
|
|
23 | ip.ex('a=10; b=20') | |
24 |
|
|
24 | result = ip.run_cell_magic('cython_inline','','return a+b') | |
25 |
|
|
25 | nt.assert_equals(result, 30) | |
26 |
|
26 | |||
27 |
|
|
27 | def test_cython_pyximport(): | |
28 |
|
|
28 | module_name = '_test_cython_pyximport' | |
29 |
|
|
29 | ip = get_ipython() | |
30 |
|
|
30 | ip.run_cell_magic('cython_pyximport', module_name, code) | |
31 |
|
|
31 | ip.ex('g = f(10)') | |
32 |
|
|
32 | nt.assert_equals(ip.user_ns['g'], 20.0) | |
33 |
|
|
33 | try: | |
34 |
|
|
34 | os.remove(module_name+'.pyx') | |
35 |
|
|
35 | except OSError: | |
36 |
|
|
36 | pass | |
37 |
|
37 | |||
38 |
|
|
38 | def test_cython(): | |
39 |
|
|
39 | ip = get_ipython() | |
40 |
|
|
40 | ip.run_cell_magic('cython', '', code) | |
41 |
|
|
41 | ip.ex('g = f(10)') | |
42 |
|
|
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