Skip to content

Commit a74f599

Browse files
committed
added tests for SWIG demo
1 parent 15ecfc5 commit a74f599

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+

Examples/week-08-extensions/swig/add.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
# Do not make changes to this file unless you know what you are doing--modify
55
# the SWIG interface file instead.
66

7-
8-
9-
10-
117
from sys import version_info
128
if version_info >= (2, 6, 0):
139
def swig_import_helper():
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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

0 commit comments

Comments
 (0)