Skip to content
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

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

tnatt
Copy link
Collaborator

@tnatt tnatt commented Jul 5, 2024

Closes #735

Mainly fixed by:

  • adding config and content to ExportData instances that doesn't have it
  • replacing access_ssdl with classification and rep_include arguments
  • removing arguments from export/generate_metadata functions
  • removing vertical_domain as dictionary and adding new domain_reference argument
  • wrapping things in pytest.warns were appropiate

With these changes we are down to 4 warnings all coming from ERT regarding deprecated pydantic behaviour.

@tnatt tnatt requested review from mferrera and jcrivenaes July 5, 2024 12:18
@@ -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
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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

Copy link
Collaborator

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?

Copy link
Collaborator Author

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:

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(
Copy link
Collaborator Author

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"}},
Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator Author

@tnatt tnatt Jul 6, 2024

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"):
Copy link
Collaborator Author

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")
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

Copy link
Collaborator

@mferrera mferrera left a 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.

Comment on lines +249 to +250
dummy_content = "depth" # will not be used, but will silence warning
etemp = dataio.ExportData(config=config, name=self.name, content=dummy_content)
Copy link
Collaborator

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)

Copy link
Collaborator Author

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.

src/fmu/dataio/aggregation.py Show resolved Hide resolved
rep_include: Optional[bool] = Field(
default=False,
)
rep_include: Optional[bool] = Field(default=None)
Copy link
Collaborator

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"}},
Copy link
Collaborator

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

Copy link
Collaborator

@jcrivenaes jcrivenaes left a 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

@tnatt tnatt merged commit 14844cf into equinor:main Jul 8, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address test warnings regarding deprecated behavior
3 participants