From d23bc92dc9d15f9127728724854882336a7589b7 Mon Sep 17 00:00:00 2001 From: Svenn-Arne Dragly Date: Fri, 16 Nov 2018 13:56:22 +0100 Subject: [PATCH] Pass the result of one plugin on to the next This fixes an issue where only the result of the last plugin would be used when multiple plugins were activated. This also adds a test that catches this issue. --- exdir/core/dataset.py | 10 +++++----- tests/test_plugins.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/exdir/core/dataset.py b/exdir/core/dataset.py index 60ea50e..fbdc981 100644 --- a/exdir/core/dataset.py +++ b/exdir/core/dataset.py @@ -77,13 +77,13 @@ def __getitem__(self, args): meta = self.meta.to_dict() atts = self.attrs.to_dict() + dataset_data = exdir.plugin_interface.DatasetData(data=values, + attrs=self.attrs.to_dict(), + meta=meta) for plugin in plugins: - dataset_data = exdir.plugin_interface.DatasetData(data=values, - attrs=self.attrs.to_dict(), - meta=meta) - dataset_data = plugin.prepare_read(dataset_data) - data = dataset_data.data + + data = dataset_data.data return data diff --git a/tests/test_plugins.py b/tests/test_plugins.py index cda36b1..3a7dc62 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -211,3 +211,29 @@ def prepare_write(self, attribute_data): assert d.attrs["value"] == 84 f.close() +def test_reading_in_order(setup_teardown_folder): + class DatasetPlugin1(exdir.plugin_interface.Dataset): + def prepare_read(self, dataset_data): + dataset_data.data = dataset_data.data * 2 + return dataset_data + + class DatasetPlugin2(exdir.plugin_interface.Dataset): + def prepare_read(self, dataset_data): + dataset_data.data = dataset_data.data * 3 + return dataset_data + + plugin1 = exdir.plugin_interface.Plugin( + "plugin1", + dataset_plugins=[DatasetPlugin1()] + ) + plugin2 = exdir.plugin_interface.Plugin( + "plugin2", + dataset_plugins=[DatasetPlugin2()] + ) + + f = exdir.File(setup_teardown_folder[1], "w", plugins=[plugin1, plugin2]) + assert f + d = f.create_dataset("foo", data=np.array([1, 2, 3])) + assert all(d.data == np.array([6, 12, 18])) + f.close() +