def test_optional(): from pybind11_tests import double_or_zero, half_or_none, test_nullopt 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
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