def test_optional():
    from pybind11_tests import double_or_zero, half_or_none

    assert double_or_zero(None) == 0
    assert double_or_zero(42) == 84
    pytest.raises(TypeError, double_or_zero, 'foo')

    assert half_or_none(0) is None
    assert half_or_none(42) == 21
    pytest.raises(TypeError, half_or_none, 'foo')
def test_optional():
    from pybind11_tests import double_or_zero, half_or_none

    assert double_or_zero(None) == 0
    assert double_or_zero(42) == 84
    pytest.raises(TypeError, double_or_zero, 'foo')

    assert half_or_none(0) is None
    assert half_or_none(42) == 21
    pytest.raises(TypeError, half_or_none, 'foo')
Exemple #3
0
def test_optional():
    from pybind11_tests import (double_or_zero, half_or_none, test_nullopt,
                                test_no_assign, NoAssign)

    assert double_or_zero(None) == 0
    assert double_or_zero(42) == 84
    pytest.raises(TypeError, double_or_zero, 'foo')

    assert half_or_none(0) is None
    assert half_or_none(42) == 21
    pytest.raises(TypeError, half_or_none, 'foo')

    assert test_nullopt() == 42
    assert test_nullopt(None) == 42
    assert test_nullopt(42) == 42
    assert test_nullopt(43) == 43

    assert test_no_assign() == 42
    assert test_no_assign(None) == 42
    assert test_no_assign(NoAssign(43)) == 43
    pytest.raises(TypeError, test_no_assign, 43)
def test_optional():
    from pybind11_tests import (double_or_zero, half_or_none, test_nullopt,
                                test_no_assign, NoAssign)

    assert double_or_zero(None) == 0
    assert double_or_zero(42) == 84
    pytest.raises(TypeError, double_or_zero, 'foo')

    assert half_or_none(0) is None
    assert half_or_none(42) == 21
    pytest.raises(TypeError, half_or_none, 'foo')

    assert test_nullopt() == 42
    assert test_nullopt(None) == 42
    assert test_nullopt(42) == 42
    assert test_nullopt(43) == 43

    assert test_no_assign() == 42
    assert test_no_assign(None) == 42
    assert test_no_assign(NoAssign(43)) == 43
    pytest.raises(TypeError, test_no_assign, 43)
def test_optional():
    from pybind11_tests import double_or_zero, half_or_none, test_nullopt

    if double_or_zero(None) != 0:
        raise AssertionError
    if double_or_zero(42) != 84:
        raise AssertionError
    pytest.raises(TypeError, double_or_zero, 'foo')

    if half_or_none(0) is not None:
        raise AssertionError
    if half_or_none(42) != 21:
        raise AssertionError
    pytest.raises(TypeError, half_or_none, 'foo')

    if test_nullopt() != 42:
        raise AssertionError
    if test_nullopt(None) != 42:
        raise AssertionError
    if test_nullopt(42) != 42:
        raise AssertionError
    if test_nullopt(43) != 43:
        raise AssertionError