-
Notifications
You must be signed in to change notification settings - Fork 4
Analysis mode is now also derived from non-str sources #44
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
Merged
forman
merged 9 commits into
main
from
forman-40-detect_analysis_mode_from_product_type
Apr 16, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8133372
Analysis mode is now also derived from non-str sources
forman bec27af
improved error message
forman a53e73a
improved docstrings
forman 9f28485
Update xarray_eopf/backend.py
forman 69a556d
Update xarray_eopf/backend.py
forman fa0aa4a
Update tests/test_amode.py
forman 867eca5
Update tests/test_amode.py
forman 9ab8f44
improved docstring
forman 4f8d3c7
fixed logic
forman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,11 @@ | ||||||
| # Copyright (c) 2025 by EOPF Sample Service team and contributors | ||||||
| # Permissions are hereby granted under the terms of the Apache 2.0 License: | ||||||
| # https://opensource.org/license/apache-2-0. | ||||||
| import fsspec | ||||||
| import zarr.storage | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| import pytest | ||||||
| from typing import Any, Iterable | ||||||
| from unittest import TestCase | ||||||
|
|
||||||
|
|
@@ -14,7 +19,7 @@ class TestMode(AnalysisMode): | |||||
| product_type = "TEST" | ||||||
|
|
||||||
| def is_valid_source(self, source: Any) -> bool: | ||||||
| return source == "TEST" | ||||||
| return isinstance(source, str) and "TEST" in source | ||||||
|
|
||||||
| def get_applicable_params(self, **kwargs) -> dict[str, any]: | ||||||
| return {} | ||||||
|
|
@@ -39,14 +44,56 @@ def setUp(self): | |||||
| def tearDown(self): | ||||||
| AnalysisMode.registry.unregister(TestMode) | ||||||
|
|
||||||
| def test_guess_ok(self): | ||||||
| self.assertIsInstance(AnalysisMode.guess("TEST.zarr"), TestMode) | ||||||
| self.assertIsInstance(AnalysisMode.guess({}, product_type="TEST"), TestMode) | ||||||
|
|
||||||
| # noinspection PyMethodMayBeStatic | ||||||
| def test_guess_fail(self): | ||||||
| with pytest.raises( | ||||||
| ValueError, match="Unable to detect analysis mode for input" | ||||||
| ): | ||||||
| AnalysisMode.guess("REST.zarr") | ||||||
|
|
||||||
| with pytest.raises( | ||||||
| ValueError, match="Unable to detect analysis mode for input" | ||||||
| ): | ||||||
| AnalysisMode.guess({}, product_type="REST") | ||||||
|
|
||||||
| with pytest.raises( | ||||||
| ValueError, match="Unable to detect analysis mode for input" | ||||||
| ): | ||||||
| AnalysisMode.guess("TEST.zarr", product_type="REST"), TestMode | ||||||
|
|
||||||
| def test_from_source(self): | ||||||
| self.assertIsInstance(AnalysisMode.from_source("TEST"), TestMode) | ||||||
| self.assertIsNone(AnalysisMode.from_source("REST")) | ||||||
| self.assertIsInstance(AnalysisMode.from_source("TEST.zarr"), TestMode) | ||||||
| self.assertIsNone(AnalysisMode.from_source("REST.zarr")) | ||||||
| self.assertIsNone(AnalysisMode.from_source({})) | ||||||
|
|
||||||
| def test_from_product_type(self): | ||||||
| self.assertIsInstance(AnalysisMode.from_product_type("TEST"), TestMode) | ||||||
| self.assertIsNone(AnalysisMode.from_product_type("REST")) | ||||||
|
|
||||||
| def test_source_to_path(self): | ||||||
| # From str | ||||||
| self.assertEqual("test1.zarr", AnalysisMode._source_to_path("test1.zarr")) | ||||||
|
|
||||||
| # From pathlib.Path | ||||||
| self.assertEqual("test2.zarr", AnalysisMode._source_to_path(Path("test2.zarr"))) | ||||||
|
|
||||||
| # From fsspec.FSMap | ||||||
| path = AnalysisMode._source_to_path( | ||||||
| fsspec.filesystem("local").get_mapper("test3.zarr") | ||||||
| ) | ||||||
| self.assertEqual("test3.zarr", Path(path).name) | ||||||
|
|
||||||
| # From zarr.storage.DirectoryStore | ||||||
| path = AnalysisMode._source_to_path(zarr.storage.DirectoryStore("test4.zarr")) | ||||||
| self.assertEqual("test4.zarr", Path(path).name) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
See comment above
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, it is correct. |
||||||
|
|
||||||
| # From dict | ||||||
| self.assertEqual(None, AnalysisMode._source_to_path({"path": "test5.zarr"})) | ||||||
|
|
||||||
|
|
||||||
| class AnalysisModeRegistryTest(TestCase): | ||||||
| # noinspection PyMethodMayBeStatic | ||||||
|
|
||||||
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
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
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
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
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.
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.
Or am I missing something?
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.
Fine! Copy/paste.
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.
Nope, it was correct!
Path(path).namegets the filename of an absolute path.