test_constants_and_functions.py
Go to the documentation of this file.
1 import pytest
2 
3 m = pytest.importorskip("pybind11_tests.constants_and_functions")
4 
5 
7  assert m.some_constant == 14
8 
9 
11  assert m.test_function() == "test_function()"
12  assert m.test_function(7) == "test_function(7)"
13  assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)"
14  assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)"
15 
16  assert m.test_function() == "test_function()"
17  assert m.test_function("abcd") == "test_function(char *)"
18  assert m.test_function(1, 1.0) == "test_function(int, float)"
19  assert m.test_function(1, 1.0) == "test_function(int, float)"
20  assert m.test_function(2.0, 2) == "test_function(float, int)"
21 
22 
23 def test_bytes():
24  assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]"
25 
26 
28  c = m.C()
29  assert c.m1(2) == 1
30  assert c.m2(3) == 1
31  assert c.m3(5) == 2
32  assert c.m4(7) == 3
33  assert c.m5(10) == 5
34  assert c.m6(14) == 8
35  assert c.m7(20) == 13
36  assert c.m8(29) == 21
37 
38  assert m.f1(33) == 34
39  assert m.f2(53) == 55
40  assert m.f3(86) == 89
41  assert m.f4(140) == 144
42 
43 
45  class RaisingRepr:
46  def __repr__(self):
47  raise RuntimeError("Surprise!")
48 
49  with pytest.raises(RuntimeError):
50  m.register_large_capture_with_invalid_arguments(m)
51  with pytest.raises(RuntimeError):
52  m.register_with_raising_repr(m, RaisingRepr())


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:45