Exemplo n.º 1
0
def test_allx():
    l1 = [1, 1, 1]
    l2 = [True, False]
    assert all(l1), util.allx(l1)
    assert not all(l2), util.allx(l2)
    assert not util.allx([])
    assert util.allx(i for i in [1, 1, 1])
    assert util.allx(i for i in range(1, 2))
    assert not util.allx(i for i in range(1))
    assert not util.allx(i for i in range(0))
    with pytest.raises(TypeError):
        util.allx(None)
Exemplo n.º 2
0
 def test_allx(self):
     l1 = [1, 1, 1]
     l2 = [True, False]
     self.assertTrue(all(l1), util.allx(l1))
     self.assertFalse(all(l2), util.allx(l2))
     self.assertFalse(util.allx([]))
     self.assertTrue(util.allx(i for i in [1, 1, 1]))
     self.assertTrue(util.allx(i for i in range(1, 2)))
     self.assertFalse(util.allx(i for i in range(1)))
     self.assertFalse(util.allx(i for i in range(0)))
     with self.assertRaises(TypeError):
         util.allx(None)
Exemplo n.º 3
0
def allx(iterable):
    '''Same as the built-in :func:`all() <python:all>` function, except that it
    returns :class:`False` if ``iterable`` is empty.

    .. versionadded:: 2.13
    '''
    return util.allx(iterable)