def test_no_scalar(self): self.assertEqual(iterutils.listify(['foo'], scalar_ok=False), ['foo']) self.assertEqual( iterutils.listify(['foo'], always_copy=True, scalar_ok=False), ['foo']) self.assertRaises(TypeError, iterutils.listify, 1, scalar_ok=False) self.assertRaises(TypeError, iterutils.listify, 'foo', scalar_ok=False)
def test_type(self): x = 'foo' res = iterutils.listify(x, type=tuple) self.assertEqual(res, ('foo', )) y = ['foo', 'bar'] res = iterutils.listify(y, type=tuple) self.assertEqual(res, ('foo', 'bar'))
def test_always_copy(self): x = ['foo', 'bar'] res = iterutils.listify(x, always_copy=True) self.assertEqual(res, x) self.assertTrue(x is not res)
def test_many(self): x = ['foo', 'bar'] res = iterutils.listify(x) self.assertEqual(res, x) self.assertTrue(x is res)
def test_one(self): self.assertEqual(iterutils.listify('foo'), ['foo'])
def test_none(self): self.assertEqual(iterutils.listify(None), [])