def test_incorrect_format(self): # Tests that an error is raised if the input is not iterable params = None with self.assertRaises(ValueError) as ae: _check_list_weights(params, 'Bad Test 2') self.assertEqual(str(ae.exception), 'Bad Test 2 must be formatted with a list of tuples')
def test_error_weights_not_1(self): # Tests that an error is raised when the weights do not sum to 1.0 params = [('Something', 0.5), ('Something Else', 0.4)] with self.assertRaises(ValueError) as ae: _check_list_weights(params, 'Bad Test 1') self.assertEqual(str(ae.exception), 'Bad Test 1 weights do not sum to 1.0!')
def test_correct_instance(self): # Tests the instance when the list of parameters is entered correctly # as a tuple with weights summing to 1.0 # Single entry params = [('Something', 1.0)] self.assertListEqual(params, _check_list_weights(params, 'Test 0')) # Multiple entry params = [('Something', 0.5), ('Something Else', 0.5)] self.assertListEqual(params, _check_list_weights(params, 'Test 1'))