def test_optional(): assert m.double_or_zero(None) == 0 assert m.double_or_zero(42) == 84 pytest.raises(TypeError, m.double_or_zero, "foo") assert m.half_or_none(0) is None assert m.half_or_none(42) == 21 pytest.raises(TypeError, m.half_or_none, "foo") assert m.test_nullopt() == 42 assert m.test_nullopt(None) == 42 assert m.test_nullopt(42) == 42 assert m.test_nullopt(43) == 43 assert m.test_no_assign() == 42 assert m.test_no_assign(None) == 42 assert m.test_no_assign(m.NoAssign(43)) == 43 pytest.raises(TypeError, m.test_no_assign, 43) assert m.nodefer_none_optional(None) holder = m.OptionalHolder() mvalue = holder.member assert mvalue.initialized assert holder.member_initialized()
def test_reference_sensitive_optional(): assert m.double_or_zero_refsensitive(None) == 0 assert m.double_or_zero_refsensitive(42) == 84 pytest.raises(TypeError, m.double_or_zero_refsensitive, "foo") assert m.half_or_none_refsensitive(0) is None assert m.half_or_none_refsensitive(42) == 21 pytest.raises(TypeError, m.half_or_none_refsensitive, "foo") assert m.test_nullopt_refsensitive() == 42 assert m.test_nullopt_refsensitive(None) == 42 assert m.test_nullopt_refsensitive(42) == 42 assert m.test_nullopt_refsensitive(43) == 43 assert m.test_no_assign_refsensitive() == 42 assert m.test_no_assign_refsensitive(None) == 42 assert m.test_no_assign_refsensitive(m.NoAssign(43)) == 43 pytest.raises(TypeError, m.test_no_assign_refsensitive, 43) holder = m.OptionalRefSensitiveHolder() mvalue = holder.member assert mvalue.initialized assert holder.member_initialized() props = m.OptionalRefSensitiveProperties() assert int(props.access_by_ref) == 42 assert int(props.access_by_copy) == 42
def test_boost_optional(): assert m.double_or_zero_boost(None) == 0 assert m.double_or_zero_boost(42) == 84 pytest.raises(TypeError, m.double_or_zero_boost, "foo") assert m.half_or_none_boost(0) is None assert m.half_or_none_boost(42) == 21 pytest.raises(TypeError, m.half_or_none_boost, "foo") assert m.test_nullopt_boost() == 42 assert m.test_nullopt_boost(None) == 42 assert m.test_nullopt_boost(42) == 42 assert m.test_nullopt_boost(43) == 43 assert m.test_no_assign_boost() == 42 assert m.test_no_assign_boost(None) == 42 assert m.test_no_assign_boost(m.NoAssign(43)) == 43 pytest.raises(TypeError, m.test_no_assign_boost, 43) holder = m.OptionalBoostHolder() mvalue = holder.member assert mvalue.initialized assert holder.member_initialized() props = m.OptionalBoostProperties() assert int(props.access_by_ref) == 42 assert int(props.access_by_copy) == 42
def test_exp_optional(): assert m.double_or_zero_exp(None) == 0 assert m.double_or_zero_exp(42) == 84 pytest.raises(TypeError, m.double_or_zero_exp, "foo") assert m.half_or_none_exp(0) is None assert m.half_or_none_exp(42) == 21 pytest.raises(TypeError, m.half_or_none_exp, "foo") assert m.test_nullopt_exp() == 42 assert m.test_nullopt_exp(None) == 42 assert m.test_nullopt_exp(42) == 42 assert m.test_nullopt_exp(43) == 43 assert m.test_no_assign_exp() == 42 assert m.test_no_assign_exp(None) == 42 assert m.test_no_assign_exp(m.NoAssign(43)) == 43 pytest.raises(TypeError, m.test_no_assign_exp, 43)
def test_optional(): assert m.double_or_zero(None) == 0 assert m.double_or_zero(42) == 84 pytest.raises(TypeError, m.double_or_zero, "foo") assert m.half_or_none(0) is None assert m.half_or_none(42) == 21 pytest.raises(TypeError, m.half_or_none, "foo") assert m.test_nullopt() == 42 assert m.test_nullopt(None) == 42 assert m.test_nullopt(42) == 42 assert m.test_nullopt(43) == 43 assert m.test_no_assign() == 42 assert m.test_no_assign(None) == 42 assert m.test_no_assign(m.NoAssign(43)) == 43 pytest.raises(TypeError, m.test_no_assign, 43) assert m.nodefer_none_optional(None)
def test_exp_optional(): assert m.double_or_zero_exp(None) == 0 assert m.double_or_zero_exp(42) == 84 pytest.raises(TypeError, m.double_or_zero_exp, "foo") assert m.half_or_none_exp(0) is None assert m.half_or_none_exp(42) == 21 pytest.raises(TypeError, m.half_or_none_exp, "foo") assert m.test_nullopt_exp() == 42 assert m.test_nullopt_exp(None) == 42 assert m.test_nullopt_exp(42) == 42 assert m.test_nullopt_exp(43) == 43 assert m.test_no_assign_exp() == 42 assert m.test_no_assign_exp(None) == 42 assert m.test_no_assign_exp(m.NoAssign(43)) == 43 pytest.raises(TypeError, m.test_no_assign_exp, 43) holder = m.OptionalExpHolder() mvalue = holder.member assert mvalue.initialized assert holder.member_initialized()