Skip to content

Commit

Permalink
Changed localized error message
Browse files Browse the repository at this point in the history
  • Loading branch information
DKilkenny committed Oct 1, 2020
1 parent fadd4e1 commit 40fbff7
Show file tree
Hide file tree
Showing 33 changed files with 156 additions and 156 deletions.
12 changes: 6 additions & 6 deletions openmdao/components/tests/test_add_subtract_comp.py
Expand Up @@ -336,8 +336,8 @@ def test_for_bad_scale_factors(self):
adder.add_equation('adder_output', ['input_a', 'input_b', 'input_c'], vec_size=self.nn,
length=3, scaling_factors=[1, -1])

expected_msg = 'AddSubtractComp (add_subtract_comp): Scaling factors list needs to be ' \
'same length as input names'
expected_msg = "'add_subtract_comp' <class AddSubtractComp>: Scaling factors list needs to be " \
"same length as input names"

self.assertEqual(str(err.exception), expected_msg)

Expand All @@ -362,17 +362,17 @@ def test_for_bad_input_set(self):
adder.add_equation('adder_output', ['input_a',], vec_size=self.nn,
length=3, scaling_factors=[1, -1])

expected_msg = 'AddSubtractComp (add_subtract_comp): must specify more than one input ' \
'name for an equation, but only one given'
expected_msg = "'add_subtract_comp' <class AddSubtractComp>: must specify more than one input " \
"name for an equation, but only one given"

self.assertEqual(str(err.exception), expected_msg)

with self.assertRaises(ValueError) as err:
adder.add_equation('adder_output', 'input_a', vec_size=self.nn,
length=3, scaling_factors=[1, -1])

expected_msg = 'AddSubtractComp (add_subtract_comp): must specify more than one input ' \
'name for an equation, but only one given'
expected_msg = "'add_subtract_comp' <class AddSubtractComp>: must specify more than one input " \
"name for an equation, but only one given"

self.assertEqual(str(err.exception), expected_msg)

Expand Down
4 changes: 2 additions & 2 deletions openmdao/components/tests/test_demux_comp.py
Expand Up @@ -23,7 +23,7 @@ def test_invalid_axis(self):
with self.assertRaises(RuntimeError) as ctx:
demux_comp.add_var('a', shape=(nn,), axis=1)
self.assertEqual(str(ctx.exception),
"DemuxComp (demux_comp): Invalid axis (1) for variable 'a' of shape (10,)")
"'demux_comp' <class DemuxComp>: Invalid axis (1) for variable 'a' of shape (10,)")

def test_axis_with_wrong_size(self):
nn = 10
Expand All @@ -41,7 +41,7 @@ def test_axis_with_wrong_size(self):
with self.assertRaises(RuntimeError) as ctx:
demux_comp.add_var('a', shape=(nn, 7), axis=1)
self.assertEqual(str(ctx.exception),
"DemuxComp (demux_comp): Variable 'a' cannot be demuxed along axis 1. Axis size is "
"'demux_comp' <class DemuxComp>: Variable 'a' cannot be demuxed along axis 1. Axis size is "
"7 but vec_size is 10.")


Expand Down
32 changes: 16 additions & 16 deletions openmdao/components/tests/test_exec_comp.py
Expand Up @@ -281,23 +281,23 @@ def test_no_expr(self):
with self.assertRaises(Exception) as context:
prob.setup()
self.assertEqual(str(context.exception),
"ExecComp (C1): No valid expressions provided to ExecComp(): [].")
"'C1' <class ExecComp>: No valid expressions provided to ExecComp(): [].")

def test_colon_vars(self):
prob = om.Problem()
prob.model.add_subsystem('C1', om.ExecComp('y=foo:bar+1.'))
with self.assertRaises(Exception) as context:
prob.setup()
self.assertEqual(str(context.exception),
"ExecComp (C1): failed to compile expression 'y=foo:bar+1.'.")
"'C1' <class ExecComp>: failed to compile expression 'y=foo:bar+1.'.")

def test_bad_kwargs(self):
prob = om.Problem()
prob.model.add_subsystem('C1', om.ExecComp('y=x+1.', xx=2.0))
with self.assertRaises(Exception) as context:
prob.setup()
self.assertEqual(str(context.exception),
"ExecComp (C1): arg 'xx' in call to ExecComp() does not refer to any variable "
"'C1' <class ExecComp>: arg 'xx' in call to ExecComp() does not refer to any variable "
"in the expressions ['y=x+1.']")

def test_bad_kwargs_meta(self):
Expand All @@ -307,7 +307,7 @@ def test_bad_kwargs_meta(self):
with self.assertRaises(Exception) as context:
prob.setup()
self.assertEqual(str(context.exception),
"ExecComp (C1): the following metadata names were not recognized for "
"'C1' <class ExecComp>: the following metadata names were not recognized for "
"variable 'x': ['high', 'low', 'val']")

def test_name_collision_const(self):
Expand All @@ -316,7 +316,7 @@ def test_name_collision_const(self):
with self.assertRaises(Exception) as context:
prob.setup()
self.assertEqual(str(context.exception),
"ExecComp (C1): cannot assign to variable 'e' because it's already defined "
"'C1' <class ExecComp>: cannot assign to variable 'e' because it's already defined "
"as an internal function or constant.")

def test_name_collision_func(self):
Expand All @@ -325,7 +325,7 @@ def test_name_collision_func(self):
with self.assertRaises(Exception) as context:
prob.setup()
self.assertEqual(str(context.exception),
"ExecComp (C1): cannot assign to variable 'sin' because it's already defined "
"'C1' <class ExecComp>: cannot assign to variable 'sin' because it's already defined "
"as an internal function or constant.")

def test_func_as_rhs_var(self):
Expand All @@ -334,7 +334,7 @@ def test_func_as_rhs_var(self):
with self.assertRaises(Exception) as context:
prob.setup()
self.assertEqual(str(context.exception),
"ExecComp (C1): cannot use 'sin' as a variable because it's already defined "
"'C1' <class ExecComp>: cannot use 'sin' as a variable because it's already defined "
"as an internal function.")

def test_mixed_type(self):
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_units_varname_novalue(self):
prob.setup()

self.assertEqual(str(cm.exception),
"ExecComp (C1): cannot use variable name 'units' because it's a reserved keyword.")
"'C1' <class ExecComp>: cannot use variable name 'units' because it's a reserved keyword.")

def test_common_units(self):
# all variables in the ExecComp have the same units
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_conflicting_units(self):
prob.setup()

self.assertEqual(str(cm.exception),
"ExecComp (C1): units of 'km' have been specified for variable 'x', but "
"'C1' <class ExecComp>: units of 'km' have been specified for variable 'x', but "
"units of 'm' have been specified for the entire component.")

def test_shape_and_value(self):
Expand Down Expand Up @@ -514,7 +514,7 @@ def test_conflicting_shape(self):
p.setup()

self.assertEqual(str(context.exception).replace('L,', ','), # L on Windows
"ExecComp (comp): shape of (5,) has been specified for variable 'x', "
"'comp' <class ExecComp>: shape of (5,) has been specified for variable 'x', "
"but a value of shape (1,) has been provided.")

def test_common_shape(self):
Expand Down Expand Up @@ -556,7 +556,7 @@ def test_common_shape_conflicting_shape(self):
p.setup()

self.assertEqual(str(context.exception).replace('L,', ','), # L on Windows
"ExecComp (comp): shape of (10,) has been specified for variable 'y', "
"'comp' <class ExecComp>: shape of (10,) has been specified for variable 'y', "
"but shape of (5,) has been specified for the entire component.")

def test_common_shape_conflicting_value(self):
Expand All @@ -570,7 +570,7 @@ def test_common_shape_conflicting_value(self):
p.setup()

self.assertEqual(str(context.exception).replace('1L,', '1,'), # 1L on Windows
"ExecComp (comp): value of shape (1,) has been specified for variable 'x', "
"'comp' <class ExecComp>: value of shape (1,) has been specified for variable 'x', "
"but shape of (5,) has been specified for the entire component.")

def test_math(self):
Expand Down Expand Up @@ -599,7 +599,7 @@ def test_np(self):
prob.run_model()

self.assertEqual(str(context.exception),
"ExecComp (C1): Error occurred evaluating 'y2=np.cos(x)'\n"
"'C1' <class ExecComp>: Error occurred evaluating 'y2=np.cos(x)'\n"
" ExecComp supports a subset of numpy functions directly, without the 'np' prefix.\n"
" 'cos' is supported (See the documentation).")

Expand All @@ -612,7 +612,7 @@ def test_numpy(self):
prob.run_model()

self.assertEqual(str(context.exception),
"ExecComp (C1): Error occurred evaluating 'y=numpy.sin(x)'\n"
"'C1' <class ExecComp>: Error occurred evaluating 'y=numpy.sin(x)'\n"
" ExecComp supports a subset of numpy functions directly, without the 'numpy' prefix.\n"
" 'sin' is supported (See the documentation).")

Expand All @@ -625,7 +625,7 @@ def test_numpy_fft(self):
prob.run_model()

self.assertEqual(str(context.exception),
"ExecComp (C1): Error occurred evaluating 'y=numpy.fft(x)'\n"
"'C1' <class ExecComp>: Error occurred evaluating 'y=numpy.fft(x)'\n"
" ExecComp supports a subset of numpy functions directly, without the 'numpy' prefix.\n"
" 'fft' is not supported (See the documentation).")

Expand Down Expand Up @@ -800,7 +800,7 @@ def test_has_diag_partials_error(self):
with self.assertRaises(Exception) as context:
p.setup()
self.assertEqual(str(context.exception),
"ExecComp (comp): has_diag_partials is True but partial(y, A) is not square (shape=(3, 15)).")
"'comp' <class ExecComp>: has_diag_partials is True but partial(y, A) is not square (shape=(3, 15)).")

def test_has_diag_partials(self):
# Really check to see that the has_diag_partials argument had its intended effect
Expand Down
6 changes: 3 additions & 3 deletions openmdao/components/tests/test_external_code_comp.py
Expand Up @@ -116,7 +116,7 @@ def test_timeout_raise(self):
try:
self.prob.run_model()
except om.AnalysisError as exc:
self.assertEqual(str(exc), "ExternalCodeComp (extcode): Error calling compute(), "
self.assertEqual(str(exc), "'extcode' <class ExternalCodeComp>: Error calling compute(), "
"Timed out after 1.0 sec.")
else:
self.fail('Expected AnalysisError')
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_badcmd(self):
try:
self.prob.run_model()
except ValueError as exc:
self.assertEqual(str(exc), "ExternalCodeComp (extcode): Error calling compute(), "
self.assertEqual(str(exc), "'extcode' <class ExternalCodeComp>: Error calling compute(), "
"The command to be executed, 'no-such-command', cannot be found")
self.assertEqual(self.extcode.return_code, -999999)
else:
Expand All @@ -209,7 +209,7 @@ def test_nullcmd(self):
try:
self.prob.run_model()
except ValueError as exc:
self.assertEqual(str(exc), "ExternalCodeComp (extcode): Error calling compute(), "
self.assertEqual(str(exc), "'extcode' <class ExternalCodeComp>: Error calling compute(), "
"Empty command list")
else:
self.fail('Expected ValueError')
Expand Down
8 changes: 4 additions & 4 deletions openmdao/components/tests/test_meta_model_structured_comp.py
Expand Up @@ -525,7 +525,7 @@ def test_raise_out_of_bounds_error(self):
# The interpolating output name is given as a regexp because the exception could
# happen with f or g first. The order those are evaluated comes from the keys of
# dict so no guarantee on the order except for Python 3.6 !
msg = "MetaModelStructuredComp \(comp\): Error interpolating output '[f|g]' because input 'comp.z' was " \
msg = "'comp' <class MetaModelStructuredComp>: Error interpolating output '[f|g]' because input 'comp.z' was " \
"out of bounds \('.*', '.*'\) with value '9.0'"
with self.assertRaisesRegex(om.AnalysisError, msg):
self.run_and_check_derivs(self.prob)
Expand Down Expand Up @@ -668,7 +668,7 @@ def setup(self):
with self.assertRaises(om.AnalysisError) as cm:
p.run_model()

msg = ("MMComp (MM): Error interpolating output 'y' because input 'MM.x' was out of bounds ('0.0', '1.0') with value '1.1'")
msg = ("'MM' <class MMComp>: Error interpolating output 'y' because input 'MM.x' was out of bounds ('0.0', '1.0') with value '1.1'")
self.assertEqual(str(cm.exception), msg)


Expand Down Expand Up @@ -1115,8 +1115,8 @@ def test_analysis_error_warning_msg(self):

p.set_val('x', 0.75)

msg = "Analysis Error: MetaModelStructuredComp " \
"(interp) Line 203 of file {}".format(inspect.getsourcefile(om.MetaModelStructuredComp))
msg = "Analysis Error: 'interp' <class MetaModelStructuredComp> " \
"Line 203 of file {}".format(inspect.getsourcefile(om.MetaModelStructuredComp))
with assert_warning(UserWarning, msg):
p.run_driver()

Expand Down
12 changes: 6 additions & 6 deletions openmdao/components/tests/test_meta_model_unstructured_comp.py
Expand Up @@ -50,7 +50,7 @@ def test_sin_metamodel(self):
with self.assertRaises(RuntimeError) as cm:
prob.run_model()

msg = ("MetaModelUnStructuredComp (sin_mm): The following training data sets must be "
msg = ("'sin_mm' <class MetaModelUnStructuredComp>: The following training data sets must be "
"provided as options: ['train:x', 'train:f_x']")
self.assertEqual(str(cm.exception), msg)

Expand Down Expand Up @@ -82,7 +82,7 @@ def test_error_no_surrogate(self):
with self.assertRaises(RuntimeError) as cm:
prob.run_model()

msg = ("MetaModelUnStructuredComp (sin_mm): No surrogate specified for output 'f_x'")
msg = ("'sin_mm' <class MetaModelUnStructuredComp>: No surrogate specified for output 'f_x'")
self.assertEqual(str(cm.exception), msg)

def test_sin_metamodel_preset_data(self):
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_unequal_training_inputs(self):
with self.assertRaises(RuntimeError) as cm:
prob.run_model()

expected = ("MetaModelUnStructuredComp (mm): Each variable must have the same number"
expected = ("'mm' <class MetaModelUnStructuredComp>: Each variable must have the same number"
" of training points. Expected 4 but found"
" 2 points for 'y'.")

Expand Down Expand Up @@ -379,7 +379,7 @@ def test_unequal_training_outputs(self):
with self.assertRaises(RuntimeError) as cm:
prob.run_model()

expected = ("MetaModelUnStructuredComp (mm): Each variable must have the same number"
expected = ("'mm' <class MetaModelUnStructuredComp>: Each variable must have the same number"
" of training points. Expected 4 but found"
" 2 points for 'f'.")
self.assertEqual(str(cm.exception), expected)
Expand Down Expand Up @@ -1065,8 +1065,8 @@ def test_surrogate_message_format(self):
with self.assertRaises(ValueError) as cm:
prob.run_model()

self.assertEqual(str(cm.exception), 'MetaModelUnStructuredComp (sin_mm): '
'Error calling compute(), KrigingSurrogate requires at least 2 training points.')
self.assertEqual(str(cm.exception), "'sin_mm' <class MetaModelUnStructuredComp>: "
"Error calling compute(), KrigingSurrogate requires at least 2 training points.")


class MetaModelUnstructuredSurrogatesFeatureTestCase(unittest.TestCase):
Expand Down
Expand Up @@ -43,7 +43,7 @@ def test_error_messages(self):
with self.assertRaises(RuntimeError) as cm:
prob.run_model()

msg = ("MultiFiMetaModelUnStructuredComp (mm): No surrogate specified for output 'y'")
msg = ("'mm' <class MultiFiMetaModelUnStructuredComp>: No surrogate specified for output 'y'")
self.assertEqual(str(cm.exception), msg)

# Wrong number of input samples
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_error_messages(self):
with self.assertRaises(RuntimeError) as cm:
prob.run_model()

msg = ("MultiFiMetaModelUnStructuredComp (mm): Each variable must have the same number of training points. Expected 3 but found 4 points for 'x2'.")
msg = ("'mm' <class MultiFiMetaModelUnStructuredComp>: Each variable must have the same number of training points. Expected 3 but found 4 points for 'x2'.")
self.assertEqual(str(cm.exception), msg)

# Wrong number of output samples
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_error_messages(self):
with self.assertRaises(RuntimeError) as cm:
prob.run_model()

msg = ("MultiFiMetaModelUnStructuredComp (mm): Each variable must have the same number of training points. Expected 3 but found 4 points for 'y'.")
msg = ("'mm' <class MultiFiMetaModelUnStructuredComp>: Each variable must have the same number of training points. Expected 3 but found 4 points for 'y'.")
self.assertEqual(str(cm.exception), msg)

def test_inputs_wrt_nfidelity(self):
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_surrogate_message_format(self):
with self.assertRaises(ValueError) as cm:
prob.run_model()

self.assertEqual(str(cm.exception), "MultiFiMetaModelUnStructuredComp (mm): "
self.assertEqual(str(cm.exception), "'mm' <class MultiFiMetaModelUnStructuredComp>: "
"Error calling compute(), Multiple input features cannot have the same value.")

def test_om_slice_in_add_input(self):
Expand Down
6 changes: 3 additions & 3 deletions openmdao/components/tests/test_mux_comp.py
Expand Up @@ -24,7 +24,7 @@ def test_invalid_axis_scalar(self):
with self.assertRaises(ValueError) as ctx:
mux_comp.add_var('a', shape=(1,), axis=2)
self.assertEqual(str(ctx.exception),
'MuxComp (mux_comp): Cannot mux a 1D inputs for a along axis greater than 1 (2)')
"'mux_comp' <class MuxComp>: Cannot mux a 1D inputs for a along axis greater than 1 (2)")

def test_invalid_axis_1D(self):
nn = 10
Expand All @@ -50,8 +50,8 @@ def test_invalid_axis_1D(self):
with self.assertRaises(ValueError) as ctx:
mux_comp.add_var('b', shape=(b_size,), axis=2)
self.assertEqual(str(ctx.exception),
'MuxComp (mux_comp): Cannot mux a 1D inputs for b along axis greater '
'than 1 (2)')
"'mux_comp' <class MuxComp>: Cannot mux a 1D inputs for b along axis greater "
"than 1 (2)")


class TestMuxCompScalar(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions openmdao/components/tests/test_spline_comp.py
Expand Up @@ -312,7 +312,7 @@ def test_error_messages(self):
with self.assertRaises(ValueError) as cm:
prob.setup()

msg = "SplineComp (interp): 'x_cp_val' is not a valid option when using method 'bsplines'. "
msg = "'interp' <class SplineComp>: 'x_cp_val' is not a valid option when using method 'bsplines'. "
msg += "Set 'num_cp' instead."
self.assertEqual(str(cm.exception), msg)

Expand All @@ -327,7 +327,7 @@ def test_error_messages(self):
with self.assertRaises(ValueError) as cm:
prob.setup()

msg = "SplineComp (interp): It is not valid to set both options 'x_cp_val' and 'num_cp'."
msg = "'interp' <class SplineComp>: It is not valid to set both options 'x_cp_val' and 'num_cp'."
self.assertEqual(str(cm.exception), msg)

prob = om.Problem()
Expand All @@ -341,7 +341,7 @@ def test_error_messages(self):
with self.assertRaises(ValueError) as cm:
prob.setup()

msg = "SplineComp (interp): Either option 'x_cp_val' or 'num_cp' must be set."
msg = "'interp' <class SplineComp>: Either option 'x_cp_val' or 'num_cp' must be set."
self.assertEqual(str(cm.exception), msg)

def test_y_units(self):
Expand Down

0 comments on commit 40fbff7

Please sign in to comment.