Skip to content

GEOPY-2702: Validate "geoh5" for existing path#857

Open
benk-mira wants to merge 4 commits intodevelopfrom
GEOPY-2702
Open

GEOPY-2702: Validate "geoh5" for existing path#857
benk-mira wants to merge 4 commits intodevelopfrom
GEOPY-2702

Conversation

@benk-mira
Copy link
Contributor

@benk-mira benk-mira commented Mar 11, 2026

GEOPY-2702 - Validate "geoh5" for existing path

Copilot AI review requested due to automatic review settings March 11, 2026 19:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens validation for the geoh5 path in BaseUIJson by enforcing a .geoh5 file extension and adds a regression test to ensure invalid extensions are rejected.

Changes:

  • Added a geoh5 extension validator to require .geoh5.
  • Switched geoh5 field validation to run in mode="before".
  • Added a unit test expecting a ValidationError when geoh5 has the wrong extension.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
geoh5py/ui_json/ui_json.py Adds .geoh5 extension validation and changes validator execution mode for geoh5.
tests/ui_json/uijson_test.py Adds a test asserting invalid geoh5 extensions raise a Pydantic ValidationError.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +103 to +112
@field_validator("geoh5", mode="before")
@classmethod
def workspace_path_exists(cls, path: Path):
if not path.exists():
raise FileNotFoundError(f"geoh5 path {path} does not exist.")
return path

@field_validator("geoh5", mode="before")
@classmethod
def valid_geoh5_extension(cls, path: Path):
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geoh5 is frequently passed as a string (e.g., other tests call geoh5=str(...)). With mode="before", Pydantic validators receive the raw input, so path can be a str here and path.exists() will raise an AttributeError rather than producing the intended validation error. Consider switching this validator back to mode="after" (so the value is parsed into a Path first) or explicitly coercing path = Path(path) when a string is provided.

Suggested change
@field_validator("geoh5", mode="before")
@classmethod
def workspace_path_exists(cls, path: Path):
if not path.exists():
raise FileNotFoundError(f"geoh5 path {path} does not exist.")
return path
@field_validator("geoh5", mode="before")
@classmethod
def valid_geoh5_extension(cls, path: Path):
@field_validator("geoh5", mode="after")
@classmethod
def workspace_path_exists(cls, path: Path | None):
if path is None:
return path
if not path.exists():
raise FileNotFoundError(f"geoh5 path {path} does not exist.")
return path
@field_validator("geoh5", mode="after")
@classmethod
def valid_geoh5_extension(cls, path: Path | None):
if path is None:
return path

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Copilot is right. Why before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't recall the reason. Makes sense to keep as after. Fixed.

Comment on lines +103 to +112
@field_validator("geoh5", mode="before")
@classmethod
def workspace_path_exists(cls, path: Path):
if not path.exists():
raise FileNotFoundError(f"geoh5 path {path} does not exist.")
return path

@field_validator("geoh5", mode="before")
@classmethod
def valid_geoh5_extension(cls, path: Path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Copilot is right. Why before?



def test_geoh5_validate_extension(tmp_path):
h5file = tmp_path / "test"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to comment above, input would be a str from file. So test with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sebhmg sebhmg changed the title GEOPY-2702 GEOPY-2702: Validate "geoh5" for existing path Mar 16, 2026
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.18%. Comparing base (7e3b1de) to head (49934ef).
⚠️ Report is 18 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #857      +/-   ##
===========================================
- Coverage    91.18%   91.18%   -0.01%     
===========================================
  Files          115      115              
  Lines        10272    10298      +26     
  Branches      1898     1901       +3     
===========================================
+ Hits          9367     9390      +23     
- Misses         483      485       +2     
- Partials       422      423       +1     
Files with missing lines Coverage Δ
geoh5py/ui_json/ui_json.py 89.44% <100.00%> (+0.40%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants