Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:52

0001 import pytest
0002 
0003 m = pytest.importorskip("pybind11_tests.constants_and_functions")
0004 
0005 
0006 def test_constants():
0007     assert m.some_constant == 14
0008 
0009 
0010 def test_function_overloading():
0011     assert m.test_function() == "test_function()"
0012     assert m.test_function(7) == "test_function(7)"
0013     assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)"
0014     assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)"
0015 
0016     assert m.test_function() == "test_function()"
0017     assert m.test_function("abcd") == "test_function(char *)"
0018     assert m.test_function(1, 1.0) == "test_function(int, float)"
0019     assert m.test_function(1, 1.0) == "test_function(int, float)"
0020     assert m.test_function(2.0, 2) == "test_function(float, int)"
0021 
0022 
0023 def test_bytes():
0024     assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]"
0025 
0026 
0027 def test_exception_specifiers():
0028     c = m.C()
0029     assert c.m1(2) == 1
0030     assert c.m2(3) == 1
0031     assert c.m3(5) == 2
0032     assert c.m4(7) == 3
0033     assert c.m5(10) == 5
0034     assert c.m6(14) == 8
0035     assert c.m7(20) == 13
0036     assert c.m8(29) == 21
0037 
0038     assert m.f1(33) == 34
0039     assert m.f2(53) == 55
0040     assert m.f3(86) == 89
0041     assert m.f4(140) == 144
0042 
0043 
0044 def test_function_record_leaks():
0045     class RaisingRepr:
0046         def __repr__(self):
0047             raise RuntimeError("Surprise!")
0048 
0049     with pytest.raises(RuntimeError):
0050         m.register_large_capture_with_invalid_arguments(m)
0051     with pytest.raises(RuntimeError):
0052         m.register_with_raising_repr(m, RaisingRepr())