-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically load external frontends in load()
- Loading branch information
1 parent
ed665c5
commit 67823c1
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import tempfile | ||
from unittest import mock | ||
|
||
from yt.data_objects.static_output import Dataset | ||
from yt.geometry.grid_geometry_handler import GridIndex | ||
from yt.loaders import load | ||
from yt.utilities.object_registries import output_type_registry | ||
|
||
|
||
def test_external_frontend(): | ||
class MockEntryPoint: | ||
@classmethod | ||
def load(cls): | ||
class MockHierarchy(GridIndex): | ||
grid = None | ||
|
||
class MockDataset(Dataset): | ||
_index_class = MockHierarchy | ||
|
||
def _parse_parameter_file(self): | ||
self.current_time = 1.0 | ||
|
||
def _set_code_unit_attributes(self): | ||
self.length_unit = self.quan(1.0, "code_length") | ||
self.mass_unit = self.quan(1.0, "code_mass") | ||
self.time_unit = self.quan(1.0, "code_time") | ||
|
||
@classmethod | ||
def _is_valid(cls, filename, *args, **kwargs): | ||
return True | ||
|
||
assert "MockDataset" not in output_type_registry | ||
|
||
with tempfile.NamedTemporaryFile() as test_file: | ||
with mock.patch("importlib.metadata.entry_points") as ep: | ||
ep.return_value = {"yt.frontends": [MockEntryPoint]} | ||
ds = load(test_file.name) | ||
assert "MockDataset" in str(ds.__class__) | ||
|
||
assert "MockDataset" in output_type_registry | ||
output_type_registry.pop("MockDataset") |