forked from pybind/python_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_python_example.py
More file actions
48 lines (32 loc) · 986 Bytes
/
test_python_example.py
File metadata and controls
48 lines (32 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
import python_example as m
import pytest
def test_version():
assert m.__version__ == "0.0.1"
def test_add_1_2():
assert m.add(1, 2) == 3
def test_subtract_1_2():
assert m.subtract(1, 2) == -1
def test_ndarray_args():
data = np.array([range(10)])
assert m.ndarray_sum(data) == sum(range(10))
def test_runtime_error():
with pytest.raises(RuntimeError):
m.runtime_error()
def test_range_error():
with pytest.raises(ValueError):
m.range_error()
def test_return_ndarray():
a = m.get_ndarray(10, 5.0)
assert isinstance(a, np.ndarray)
np.testing.assert_allclose(a, 5.0)
assert len(a) == 10
def test_get_class_with_vector_results():
n = 10
t = 4.3
h = 88.3
results = m.get_vector_results(n, t, h)
assert len(results.temperature) == n
np.testing.assert_allclose(results.temperature, t)
assert len(results.humidity) == n
np.testing.assert_allclose(results.humidity, h)