
from unittest import TestCase
from expects import expect, equal, raise_error 

from slender import List

class TestKeepIf(TestCase):

    def test_keep_if_if_func_is_none(self):
        e = List([1, 2, 3, 4, 5])
        expect(e.keep_if(None).to_list()).to(equal([1, 2, 3, 4, 5]))

    def test_keep_if_if_func_is_valid(self):
        e = List([1, 2, 3, 4, 5])
        expect(e.keep_if(lambda item: item > 3).to_list()).to(equal([4, 5]))

    def test_keep_if_if_func_is_invalid_for_all_items(self):
        e = List([1, 2, 3, 4, 5])
        expect(e.keep_if(lambda item: item > 6).to_list()).to(equal([]))

    def test_keep_if_if_func_is_different(self):
        e = List([1, 2, 3, 4])
        expect(lambda: e.keep_if('...')).to(raise_error(TypeError))




[((191, 212), 'slender.List', 'List', (['[1, 2, 3, 4, 5]'], {}), '([1, 2, 3, 4, 5])\n', (195, 212), False, 'from slender import List\n'), ((340, 361), 'slender.List', 'List', (['[1, 2, 3, 4, 5]'], {}), '([1, 2, 3, 4, 5])\n', (344, 361), False, 'from slender import List\n'), ((513, 534), 'slender.List', 'List', (['[1, 2, 3, 4, 5]'], {}), '([1, 2, 3, 4, 5])\n', (517, 534), False, 'from slender import List\n'), ((670, 688), 'slender.List', 'List', (['[1, 2, 3, 4]'], {}), '([1, 2, 3, 4])\n', (674, 688), False, 'from slender import List\n'), ((258, 280), 'expects.equal', 'equal', (['[1, 2, 3, 4, 5]'], {}), '([1, 2, 3, 4, 5])\n', (263, 280), False, 'from expects import expect, equal, raise_error\n'), ((424, 437), 'expects.equal', 'equal', (['[4, 5]'], {}), '([4, 5])\n', (429, 437), False, 'from expects import expect, equal, raise_error\n'), ((597, 606), 'expects.equal', 'equal', (['[]'], {}), '([])\n', (602, 606), False, 'from expects import expect, equal, raise_error\n'), ((733, 755), 'expects.raise_error', 'raise_error', (['TypeError'], {}), '(TypeError)\n', (744, 755), False, 'from expects import expect, equal, raise_error\n')]