def test_elementtype(self): example_list = [1.0, 2.0, 3.0] self.assertEqual( validate_list("example_list", example_list, elementtype="float"), True) example_list = [1.0, "a", 3.0] self.assertRaises(ValueError, validate_list, "example_list", example_list, elementtype="float") example_list = [1.0, 2.2, 3.0] self.assertRaises(ValueError, validate_list, "example_list", example_list, elementtype="int") example_list = [1, 2, 3] self.assertEqual( validate_list("example_list", example_list, elementtype="int"), True) example_list = ['a', 'b', 'c'] self.assertEqual( validate_list("example_list", example_list, elementtype="string"), True) example_list = ['a', 2.2, 'c'] self.assertRaises(ValueError, validate_list, "example_list", example_list, elementtype="string")
def test_descending(self): example_list = [3.0, 2.0, 1.0] self.assertEqual( validate_list("example_list", example_list, order="descending"), True) example_list = [2.0, 3.0, 1.0] self.assertRaises(ValueError, validate_list, "example_list", example_list, order="descending") example_list = [3.0, 2.0, np.NaN] self.assertRaises(ValueError, validate_list, "example_list", example_list, order="descending") example_list = [ 3.0, np.NaN, 2.0, 1.0, ] self.assertRaises(ValueError, validate_list, "example_list", example_list, order="descending")
def test_empty(self): example_list = [] self.assertEqual(validate_list("example_list", example_list), True) self.assertRaises(ValueError, validate_list, "example_list", example_list, empty_allowed=False)
def test_unique(self): example_list = [3.0, 2.0, 1.0] self.assertEqual( validate_list("example_list", example_list, unique=True), True) example_list = [3.0, 3.0, 1.0] self.assertRaises(ValueError, validate_list, "example_list", example_list, unique=True)
def test_list(self): example_list = [1.0, 2.0, 3.0] self.assertEqual(validate_list("example_list", example_list), True) example_tuple = (1.0, 2.0, 3.0) self.assertEqual(validate_list("example_tuple", example_tuple), True)