File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed
Examples/week-08-extensions/swig Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change
1
+ Simple SWIG Example
2
+ ===================
3
+
4
+ This dir has a very, very simple example of using SWIG to generate a
5
+ wrapper around a simple C function.
6
+
7
+ The logic, such as it is, is in the add.i interface file.
8
+
9
+ To build, siply call:
10
+
11
+ python ./setup.py build_ext --in_place
12
+
13
+ distutils understands SWIG, so it will run SWIG for you.
14
+
15
+ You, of course, need to have SWIG isntalled on your system.
16
+
Original file line number Diff line number Diff line change 4
4
# Do not make changes to this file unless you know what you are doing--modify
5
5
# the SWIG interface file instead.
6
6
7
-
8
-
9
-
10
-
11
7
from sys import version_info
12
8
if version_info >= (2 , 6 , 0 ):
13
9
def swig_import_helper ():
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+
3
+ """
4
+ simple test file for SWIG-ified add function
5
+ """
6
+
7
+ import pytest
8
+
9
+ from add import add
10
+
11
+
12
+ def test_add1 ():
13
+ assert add (3 , 4 ) == 7
14
+
15
+
16
+ def test_add_float ():
17
+ # only integers!
18
+ with pytest .raises (TypeError ):
19
+ assert add (3.1 , 4.1 ) == 7.2
20
+
21
+
22
+ def test_add_string ():
23
+ # only integers!
24
+ with pytest .raises (TypeError ):
25
+ assert add ('2' , 4 ) == 6
You can’t perform that action at this time.
0 commit comments