-
Notifications
You must be signed in to change notification settings - Fork 15
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
TST: Remove deprecated patterns in tests to silence warnings #742
Conversation
@@ -378,7 +378,7 @@ class ExportData: | |||
classification: Optional[str] = None | |||
config: dict = field(default_factory=dict) | |||
content: Optional[Union[dict, str]] = None | |||
depth_reference: str = "msl" # deprecated | |||
depth_reference: Optional[str] = None # deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been done in #624 . Now it emits a deprecation warning every time ExportData is initialized 😱
rep_include: Optional[bool] = Field( | ||
default=False, | ||
) | ||
rep_include: Optional[bool] = Field(default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the default here to None, to distinguish when it is present in the users config. And to avoid an incorrect UserWarning saying it should be removed from the config.
Should have been done in #694
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a breaking change possible from this out in the wild?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be at the moment. The roundtrip we do on the config where we dump it back to dictionary while dropping None
should then only trigger this 👇 part of the code if rep_include
has an actual value in the config:
fmu-dataio/src/fmu/dataio/dataio.py
Line 525 in 827f293
if "rep_include" in self.config.get("access", {}).get("ssdl", {}): |
But to be more future proof for when we address #629, I will change it to
if self.config.get("access", {}).get("ssdl", {}).get("rep_include") is not None:
Actually when we have the config as a pydantic object we can use the model_fields_set
property to check this instead 🙂
|
||
logger.debug("No case metadata, issue a warning!") | ||
warn("Case metadata does not exist, metadata will be empty!", UserWarning) | ||
warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a bit many warnings emitted here when the case metadata was not present, so I merged the messages to one
@@ -86,7 +86,7 @@ def test_content_fluid_contact_raises_on_invalid_contact(regsurf, globalconfig2) | |||
ExportData( | |||
config=globalconfig2, | |||
name="MyName", | |||
content={"fluid_contact": {"contact": "OEC"}}, | |||
content={"fluid_contact": {"contact": "oec"}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed this to lowercase to avoid the UserWarning on top of the ValueError that the test is mainly checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this warning (I added it) is misguided. I can't recall our discussion of it but should we support all upper-case for contacts too, since that is generally the convention? Maybe not the PR to discuss this on but came to mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you mention it.. I think we should, it is as you say a very common convention (more common than lowercase letters IMO). Then we can convert it to lowercase for them without emitting the message 😊
@@ -55,14 +44,15 @@ def test_missing_or_wrong_config_exports_with_warning(monkeypatch, tmp_path, reg | |||
|
|||
monkeypatch.chdir(tmp_path) | |||
|
|||
with pytest.warns(UserWarning, match=pydantic_warning()): | |||
with pytest.warns(UserWarning, match="The global config"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two UserWarnings are emitted everytime the config is invalid, this match string matches both of them.. hence the change.
@@ -437,6 +455,7 @@ def test_content_deprecated_seismic_offset(regsurf, globalconfig2): | |||
} | |||
|
|||
|
|||
@pytest.mark.filterwarnings("ignore: Number of maps nodes are 0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning coming from xtgeo, not relevant for this test
@@ -45,6 +45,7 @@ def test_incl_jobs_warning(rmsglobalconfig): | |||
config=rmsglobalconfig, | |||
content="depth", | |||
) | |||
dataio.ExportData.include_ertjobs = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not adding a reset of the class variable here was triggering warnings in the tests below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A large effort, nice job. This will make viewing test results so much more pleasant.
dummy_content = "depth" # will not be used, but will silence warning | ||
etemp = dataio.ExportData(config=config, name=self.name, content=dummy_content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a big problem with this, but it does seem like something that becomes an oddity in future. Not sure on where something better might live (if there is something better)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not agree more, this hack is not pretty 😬 .. but this part of the code was already hacky, we initialize a dummy ExportData
instance just to get to the ObjectDataProvider
... so I figured I could sneak this in as well 😄
It is hopefully not going to live long into the future. This AggregatedData
class is in need for some attention. Introducing pydantic but also refactoring at least this part of the code 👍
I was considering only silencing the warning in the tests, but the aggregation service in Sumo is also using this.. and this warning regarding missing content is just not relevant for the aggregation.
rep_include: Optional[bool] = Field( | ||
default=False, | ||
) | ||
rep_include: Optional[bool] = Field(default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a breaking change possible from this out in the wild?
@@ -86,7 +86,7 @@ def test_content_fluid_contact_raises_on_invalid_contact(regsurf, globalconfig2) | |||
ExportData( | |||
config=globalconfig2, | |||
name="MyName", | |||
content={"fluid_contact": {"contact": "OEC"}}, | |||
content={"fluid_contact": {"contact": "oec"}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this warning (I added it) is misguided. I can't recall our discussion of it but should we support all upper-case for contacts too, since that is generally the convention? Maybe not the PR to discuss this on but came to mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice; nothing to add what is already discussed
Closes #735
Mainly fixed by:
config
andcontent
toExportData
instances that doesn't have itaccess_ssdl
withclassification
andrep_include
argumentsexport/generate_metadata
functionsvertical_domain
as dictionary and adding newdomain_reference
argumentpytest.warns
were appropiateWith these changes we are down to 4 warnings all coming from ERT regarding deprecated pydantic behaviour.