-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise error on failed Param validation #1272
Conversation
Fixed Pyomo#930 by following the same pattern as used in `_setitem_when_present` for Var and IndexedComponent
Codecov Report
@@ Coverage Diff @@
## master #1272 +/- ##
==========================================
- Coverage 70.93% 70.93% -0.01%
==========================================
Files 534 534
Lines 80964 80965 +1
==========================================
- Hits 57431 57429 -2
- Misses 23533 23536 +3
Continue to review full report at Codecov.
|
I tested this locally and it seems to fix things. I don't think this will have any unintended side effects but we should wait for @jsiirola to take a look before merging. For tests, take a look at https://github.com/Pyomo/pyomo/blob/master/pyomo/core/tests/unit/test_param.py. I think we just need to add a method under
|
I think this solution looks fine, and will approve once we have some tests to make sure that this doesn't sneak back in. To add to what @blnicho said, I generally prefer that we verify the exception message as well as the type (especially when we are looking for a common type like In this case, something like with self.assertRaisesRegexp(ValueError, "Value failed parameter validation rule"):
m.p = -3 would be good. |
Hi everyone, I could use a bit more guidance on the tests:
Thanks! |
@goroderickgo: for Q1, while Block (and Model) will catch the with self.assertRaisesRegexp(ValueError, "Value not in parameter domain NonNegativeReals"):
m.p = Param(initialize=-3, domain=NonNegativeReals) For Q2: until PyUtilib/pyutilib#79 is accepted and merged in, using |
@goroderickgo I merged the PyUtilib PR so you should be fine to move ahead with the |
…en value is not valid
Fixes #930
Summary/Motivation:
As noted in #930, the
validate
option for Params does not raise an error when the validation function returns False (i.e., the functionality described in the documentation does not work as described).Changes proposed in this PR:
try/except
block. This proposed fix is modeled after the pattern used for the methods with the same name (_setitem_when_not_present
) in for IndexedComponent and Var.I'm not very familiar with adding tests, so I would gladly take guidance if I need to add any.
Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: