def testValidate(self): font = InputParameters() font.add('size', default=24) font.add('name', required=True) with self.assertRaises(MooseException) as e: font.validate() self.assertIn("The parameter 'name' is marked as required, but no value is assigned", str(e.exception))
def testSetRequired(self): date = InputParameters() date.add('year') self.assertEqual(date.isRequired('year'), False) date.setValue('year', 1980) date.setRequired('year', True) self.assertEqual(date.isRequired('year'), True) date.validate() with self.assertRaises(MooseException) as e: date.setRequired('year', True) self.assertIn( "The parameter 'year' has already been validated, the required state cannot be changed.", str(e.exception)) date.setValue('_error_mode', InputParameters.ErrorMode.ERROR) with self.assertLogs(level='ERROR') as log: value = date.isRequired('wrong') self.assertEqual(value, False) self.assertEqual(len(log.output), 1) self.assertIn("The parameter 'wrong' does not exist.", log.output[0])