From 2ec6f9476873884b95b2bca46f1e9e52054d1c3c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 1 Mar 2024 17:25:57 +0000 Subject: [PATCH] added test for energyfilter error handling --- openmc/filter.py | 4 ++++ tests/unit_tests/test_filters.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/openmc/filter.py b/openmc/filter.py index f2bbf2f5050..7a21c976b41 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -1349,6 +1349,10 @@ class EnergyFilter(RealFilter): """ units = 'eV' + def __init__(self, values, filter_id=None): + cv.check_length('values', values, 2) + super().__init__(values, filter_id) + def get_bin_index(self, filter_bin): # Use lower energy bound to find index for RealFilters deltas = np.abs(self.bins[:, 1] - filter_bin[1]) / filter_bin[1] diff --git a/tests/unit_tests/test_filters.py b/tests/unit_tests/test_filters.py index 4ace59e723e..55bb62075bd 100644 --- a/tests/unit_tests/test_filters.py +++ b/tests/unit_tests/test_filters.py @@ -1,6 +1,6 @@ import numpy as np import openmc -from pytest import fixture, approx +from pytest import fixture, approx, raises @fixture(scope='module') @@ -248,6 +248,11 @@ def test_energy(): assert len(f.values) == 710 +def test_energyfilter_error_handling(): + with raises(ValueError): + openmc.EnergyFilter([1e6]) + + def test_lethargy_bin_width(): f = openmc.EnergyFilter.from_group_structure('VITAMIN-J-175') assert len(f.lethargy_bin_width) == 175