def test_optional_with_value(x): """ When optional() is called, it returns a function that does not raise for none-None values, and returns the value it was passed.. """ fn = mod.optional() assert fn(x) == x
def test_optional(): """ When optional() is called, it returns a validator that raises ReturnEarly if called with None, but not with other values. """ fn = mod.optional() with pytest.raises(mod.ReturnEarly): fn(None)
def test_optional_with_default_value(): """ When optional() is called with some value value, then it returns a function that raises when it is called with either None or the value passed to optional(). """ fn = mod.optional('foo') with pytest.raises(mod.ReturnEarly): fn(None) with pytest.raises(mod.ReturnEarly): fn('foo')
def test_optional_with_default_value(): """ When optional() is called with some value value, then it returns a function that raises when it is called with either None or the value passed to optional(). """ fn = mod.optional("foo") with pytest.raises(mod.ReturnEarly): fn(None) with pytest.raises(mod.ReturnEarly): fn("foo")