MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_reference_wrapper

Function test_reference_wrapper

tests/test_builtin_casters.py:449–481  ·  view source on GitHub ↗

std::reference_wrapper for builtin and user types

()

Source from the content-addressed store, hash-verified

447
448
449def test_reference_wrapper():
450 """std::reference_wrapper for builtin and user types"""
451 assert m.refwrap_builtin(42) == 420
452 assert m.refwrap_usertype(UserType(42)) == 42
453 assert m.refwrap_usertype_const(UserType(42)) == 42
454
455 with pytest.raises(TypeError) as excinfo:
456 m.refwrap_builtin(None)
457 assert "incompatible function arguments" in str(excinfo.value)
458
459 with pytest.raises(TypeError) as excinfo:
460 m.refwrap_usertype(None)
461 assert "incompatible function arguments" in str(excinfo.value)
462
463 assert m.refwrap_lvalue().value == 1
464 assert m.refwrap_lvalue_const().value == 1
465
466 a1 = m.refwrap_list(copy=True)
467 a2 = m.refwrap_list(copy=True)
468 assert [x.value for x in a1] == [2, 3]
469 assert [x.value for x in a2] == [2, 3]
470 assert a1[0] is not a2[0]
471 assert a1[1] is not a2[1]
472
473 b1 = m.refwrap_list(copy=False)
474 b2 = m.refwrap_list(copy=False)
475 assert [x.value for x in b1] == [1, 2]
476 assert [x.value for x in b2] == [1, 2]
477 assert b1[0] is b2[0]
478 assert b1[1] is b2[1]
479
480 assert m.refwrap_iiw(IncType(5)) == 5
481 assert m.refwrap_call_iiw(IncType(10), m.refwrap_iiw) == [10, 10, 10, 10]
482
483
484def test_complex_cast(doc):

Callers

nothing calls this directly

Calls 3

UserTypeClass · 0.90
IncTypeClass · 0.90
strClass · 0.85

Tested by

no test coverage detected