Exemplo n.º 1
0
    def test_npos_between_both (self):
        assert _npos(atleast=1, atmost=2)(4, 8, hurley=15)
        assert _npos(atleast=1, atmost=3)(4, 8, 15, kate=16)
        assert _npos(atleast=2, atmost=3)(4, 8, hurley=15)
        assert _npos(atleast=2, atmost=3)(4, 8, 15, kate=16)

        assert not _npos(atleast=1, atmost=2)(4, 8, 15, kate=16)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    def test_npos_between_args (self):
        assert _npos(atleast=0, atmost=1)()
        assert _npos(atleast=0, atmost=1)(4)
        assert _npos(atleast=1, atmost=2)(4, 8)
        assert _npos(atleast=1, atmost=3)(4, 8)
        assert _npos(atleast=2, atmost=3)(4, 8)
        assert _npos(atleast=2, atmost=3)(4, 8, 15)

        assert not _npos(atleast=1, atmost=2)()
        assert not _npos(atleast=1, atmost=2)(4, 8, 15)
Exemplo n.º 4
0
    def test_npos_atleast_args (self):
        assert _npos(atleast=0)()
        assert _npos(atleast=0)(4)
        assert _npos(atleast=0)(4, 8)
        assert _npos(atleast=1)(4, 8)
        assert _npos(atleast=2)(4, 8)

        assert not _npos(atleast=1)()
        assert not _npos(atleast=2)(1)
Exemplo n.º 5
0
    def test_npos_exactly_args (self):
        assert _npos(exactly=0)()
        assert _npos(exactly=1)(4)
        assert _npos(exactly=2)(4, 8)

        assert not _npos(exactly=0)(4)
        assert not _npos(exactly=1)(4, 8)
        assert not _npos(exactly=2)(4)
Exemplo n.º 6
0
    def test_npos_atmost_args (self):
        assert _npos(atmost=0)()
        assert _npos(atmost=1)()
        assert _npos(atmost=2)(4, 8)
        assert _npos(atmost=3)(4, 8)

        assert not _npos(atmost=0)(4, 8)
        assert not _npos(atmost=1)(4, 8)
Exemplo n.º 7
0
    def test_npos_exactly_both (self):
        assert _npos(exactly=2)(4, 8, sawyer=8)

        assert not _npos(exactly=0)(4, sawyer=8)
        assert not _npos(exactly=1)(4, 8, hurley=15)
        assert not _npos(exactly=3)(4, sawyer=8)
Exemplo n.º 8
0
    def test_npos_atmost_both (self):
        assert _npos(atmost=2)(4, sawyer=8)
        assert _npos(atmost=3)(4, 8, hurley=15)

        assert not _npos(atmost=0)(4, sawyer=8)
        assert not _npos(atmost=1)(4, 8, hurley=15)
Exemplo n.º 9
0
 def test_npos_bad_negative (self):
     _npos(atleast=-1)
Exemplo n.º 10
0
 def test_npos_bad_spec (self):
     _npos(atleast=1, exactly=2)