From cdb0ed8b4e87ba01009369a2ba63eb76594008c3 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:26:10 +0100 Subject: [PATCH 1/2] Update test_results.py Added test_missing_aggregator to cover the raisevalue error that requires the aggregators --- testsuite/MDAnalysisTests/analysis/test_results.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_results.py b/testsuite/MDAnalysisTests/analysis/test_results.py index 97d299de101..59bdf9dcd17 100644 --- a/testsuite/MDAnalysisTests/analysis/test_results.py +++ b/testsuite/MDAnalysisTests/analysis/test_results.py @@ -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: @@ -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]))] @@ -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 From 5d32d150be4d079b6446ae55233badf12989a21b Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:36:28 +0100 Subject: [PATCH 2/2] Update test_results.py PEP fixes --- testsuite/MDAnalysisTests/analysis/test_results.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_results.py b/testsuite/MDAnalysisTests/analysis/test_results.py index 59bdf9dcd17..e3d8fa6ca95 100644 --- a/testsuite/MDAnalysisTests/analysis/test_results.py +++ b/testsuite/MDAnalysisTests/analysis/test_results.py @@ -171,12 +171,12 @@ def test_all_results(self, results_0, results_1, merger, n): 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'"): + 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