Skip to content

Commit

Permalink
Addition of test for missing aggregation function when `require_all_a…
Browse files Browse the repository at this point in the history
…ggregators=True` (#4770)

- fix #4650 
- add `test_missing_aggregator` test.
  • Loading branch information
talagayev authored Nov 26, 2024
1 parent c48962e commit 277f8ee
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions testsuite/MDAnalysisTests/analysis/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from MDAnalysis.analysis import results as results_module
from numpy.testing import assert_equal
from itertools import cycle


class Test_Results:
Expand Down Expand Up @@ -155,8 +156,6 @@ def merger(self):

@pytest.mark.parametrize("n", [1, 2, 5, 14])
def test_all_results(self, results_0, results_1, merger, n):
from itertools import cycle

objects = [obj for obj, _ in zip(cycle([results_0, results_1]), range(n))]

arr = [i for _, i in zip(range(n), cycle([0, 1]))]
Expand All @@ -171,3 +170,13 @@ def test_all_results(self, results_0, results_1, merger, n):
results = merger.merge(objects)
for attr, merged_value in results.items():
assert_equal(merged_value, answers.get(attr), err_msg=f"{attr=}, {merged_value=}, {arr=}, {objects=}")

def test_missing_aggregator(self, results_0, results_1, merger):
original_float_lookup = merger._lookup.get("float")
merger._lookup["float"] = None

with pytest.raises(ValueError,
match="No aggregation function for key='float'"):
merger.merge([results_0, results_1], require_all_aggregators=True)

merger._lookup["float"] = original_float_lookup

0 comments on commit 277f8ee

Please sign in to comment.