def testGetDefault(self): params = InputParameters() params.add('foo', default=42) params.setValue('foo', 54) self.assertEqual(params.getDefault('foo'), 42) with self.assertRaises(MooseException) as e: params.getDefault('bar') self.assertIn("The parameter 'bar' does not exist", str(e.exception))
def testSetDefault(self): params = InputParameters() params.add('foo', vtype=int) self.assertIsNone(params.getValue('foo')) params.setDefault('foo', 1980) self.assertEqual(params.getValue('foo'), 1980) params.add('bar', default=1980) params.setDefault('bar', 1949) self.assertEqual(params.getValue('bar'), 1980) self.assertEqual(params.getDefault('bar'), 1949) with self.assertRaises(MooseException) as e: params.setDefault('other', 1980) self.assertIn("The parameter 'other' does not exist", str(e.exception)) params.setValue('_error_mode', InputParameters.ErrorMode.ERROR) # use error to capture return with self.assertLogs(level='ERROR') as log: params.setDefault('foo', 'wrong') self.assertEqual(len(log.output), 1) self.assertIn("'foo' must be of type", log.output[0])