Refactor options manager#39
Draft
connorjward wants to merge 4 commits into
Draft
Conversation
Collaborator
Author
|
@JHopeCollins this is only a rough first attempt but I want to check with you on the approach. The main thing I'm doing is moving the options logic into the |
0b9e714 to
a0fd39a
Compare
Collaborator
Author
|
Here's an example demonstrating what I believe to be quite unintuitive behaviour. I totally get why this isn't recommended practice, but I also think that we should always try and do the intuitive thing. @pytest.mark.skipnopetsc4py
@pytest.mark.parametrize("options_prefix", (None, "", "custom_"))
def test_commandline_options_change(caplog, options_prefix):
from petsc4py import PETSc
options = PETSc.Options()
om = petsctools.OptionsManager(
{"opt1": "value1"}, options_prefix=options_prefix
)
with om.inserted_options():
assert options[f"{om.options_prefix}opt1"] == "value1"
# Put some options in the database after the options manager is created
options[f"{om.options_prefix}opt1"] = "value2"
with om.inserted_options():
# NOTE: not 'value2' because we use the frozen value from when we first
# made the options manager
assert options[f"{om.options_prefix}opt1"] == "value1"
# the original option should be put back (currently it's dropped)
assert options[f"{om.options_prefix}opt1"] == "value2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Key changes:
Closes #37
The MFE in the issue is fixed by this: