def test_powerset(self): it = iterators.powerset(xrange(3)) self.assertTrue(iterators.isiterable(it)) lst = list(it) self.assertTrue( lst == [(), (0,), (1,), (2,), (0, 1), (0, 2), (1, 2), (0, 1, 2)] )
def test_splitlines(self): s = \ """a b c d e""" lines = misc.splitlines(s) self.assertTrue(iterators.isiterable(lines)) self.assertTrue(iterators.ilen(lines) == 5)
def test_isiterable(self): self.assertTrue(iterators.isiterable([])) self.assertTrue(iterators.isiterable([1, 2, 3])) self.assertTrue(iterators.isiterable(x for x in [1, 2])) self.assertFalse(iterators.isiterable(1)) self.assertFalse(iterators.isiterable('string', strings=False)) self.assertTrue(iterators.isiterable('string', strings=True))
def test_files(self): files = misc.files('.', '*') self.assertTrue(iterators.isiterable(files))
def wrapped(*args, **kwargs): value = func(*args, **kwargs) return value if isiterable(value) else [value]
def test_split(self): head, tail = iterators.split(range(10)) self.assertTrue(head == 0) self.assertTrue(iterators.isiterable(tail))