def test_empty(self): """ Empty pipe returns same value. """ o = object() assert o is pipe()(o)
def test_success(self): """ Succeeds if all wrapped converters succeed. """ c = pipe(str, strtobool, bool) assert True is c("True") is c(True)
def test_fail(self): """ Fails if any wrapped converter fails. """ c = pipe(str, strtobool) # First wrapped converter fails: with pytest.raises(ValueError): c(33) # Last wrapped converter fails: with pytest.raises(ValueError): c("33")
class C(object): a1 = attrib(default="True", converter=pipe(str, strtobool, bool)) a2 = attrib(default=True, converter=[str, strtobool, bool])
class C: a1 = attrib(default="True", converter=pipe(str, to_bool, bool)) a2 = attrib(default=True, converter=[str, to_bool, bool])