def test_apply (self): # args assert _apply(isint)([42,]) assert _apply(_all(isstring))(['jack', 'sawyer']) assert _zip(isint, _apply(_all(isstring)))(42, ['jack', 'sawyer']) # args + kwargs assert _apply(_npos(exactly=2)([42, "bad robot!"], {'jack': 4, 'kate': 15})) assert _apply(_nkw(exactly=2)([42, "bad robot!"], {'jack': 4, 'kate': 15})) assert _apply(_nargs(exactly=4)([42, "bad robot!"], {'jack': 4, 'kate': 15})) # recursive (yeah, it makes my brain hurt, too...) It's # actually pretty simple, though... It's equivalent to # _and(isstring)(chain(people)) (in other words, it's a # completely contrived example which is much more cleanly # solved in another way! :-)) # apply `isstring` to each element in an iterable. I.e., # ``_apply(_all(isstring))(['jack', 'hurley'])`` is equivalent # to ``_all(isstring)('jack', 'hurley') all_strings = _apply(_all(isstring)) # make two groups of people, then combine them group_1 = ['jack', 'sawyer'] group_2 = ['kate', 'hurley'] people = (group_1, group_2) assert _apply(_zip(all_strings, all_strings))(people)
def test_all (self): # no args assert _all(istrue)() # single arg assert _all(istrue)(True) assert _all(isstring)("bad robot!") assert not _all(isfalse)(True) # multiple args assert _all(istrue)(True, True) assert _all(isstring)("bad robot!", "I made this!") assert not _all(isfalse)(False, True)
def test_composition (self): assert _all(_or(isempty, isatom))('', (), 42) assert not _all(_or(isempty, isatom))('', (), (42,))
def test_short_circuit (self): assert _any(passfail)(True, 'fail') assert not _all(passfail)(False, 'fail') assert not _none(passfail)(True, 'fail')