def test_init_with_sentinel_args(self): a = iter(['1', '2', '3', 'DONE']) sentinel = 'DONE' def get_next(): return next(a) it = modify_iter(get_next, sentinel, int) expected = [1, 2, 3] self.assertEqual(expected, [i for i in it])
def test_init_with_sentinel_kwargs(self): a = iter([1, 2, 3, 4]) sentinel = 4 def get_next(): return next(a) it = modify_iter(get_next, sentinel, modifier=str) expected = ['1', '2', '3'] self.assertEqual(expected, [i for i in it])
def test_modifier_rstrip_unicode(self): a = [u(''), u(' '), u(' a '), u('b '), u(' c'), u(' '), u('')] it = modify_iter(a, modifier=lambda s: s.rstrip()) expected = [u(''), u(''), u(' a'), u('b'), u(' c'), u(''), u('')] self.assertEqual(expected, [i for i in it])
def test_modifier_rstrip(self): a = ['', ' ', ' a ', 'b ', ' c', ' ', ''] it = modify_iter(a, modifier=lambda s: s.rstrip()) expected = ['', '', ' a', 'b', ' c', '', ''] self.assertEqual(expected, [i for i in it])
def test_modifier_default(self): a = ['', ' ', ' a ', 'b ', ' c', ' ', ''] it = modify_iter(a) expected = ['', ' ', ' a ', 'b ', ' c', ' ', ''] self.assertEqual(expected, [i for i in it])