test_constants_and_functions.py revision 12037:d28054ac6ec9
1
2
3def test_constants():
4    from pybind11_tests import some_constant
5
6    assert some_constant == 14
7
8
9def test_function_overloading():
10    from pybind11_tests import MyEnum, test_function
11
12    assert test_function() == "test_function()"
13    assert test_function(7) == "test_function(7)"
14    assert test_function(MyEnum.EFirstEntry) == "test_function(enum=1)"
15    assert test_function(MyEnum.ESecondEntry) == "test_function(enum=2)"
16
17    assert test_function(1, 1.0) == "test_function(int, float)"
18    assert test_function(2.0, 2) == "test_function(float, int)"
19
20
21def test_bytes():
22    from pybind11_tests import return_bytes, print_bytes
23
24    assert print_bytes(return_bytes()) == "bytes[1 0 2 0]"
25
26
27def test_exception_specifiers():
28    from pybind11_tests.exc_sp import C, f1, f2, f3, f4
29
30    c = C()
31    assert c.m1(2) == 1
32    assert c.m2(3) == 1
33    assert c.m3(5) == 2
34    assert c.m4(7) == 3
35    assert c.m5(10) == 5
36    assert c.m6(14) == 8
37    assert c.m7(20) == 13
38    assert c.m8(29) == 21
39
40    assert f1(33) == 34
41    assert f2(53) == 55
42    assert f3(86) == 89
43    assert f4(140) == 144
44