From 44654e775923a78168847aac1b7ba0aaa02e4abd Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 18 Mar 2019 09:17:30 -0500 Subject: [PATCH] A couple capi.plot module fixes and an added test. --- openmc/capi/plot.py | 3 +-- tests/unit_tests/test_capi.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/openmc/capi/plot.py b/openmc/capi/plot.py index edb2e42a3d..7e429be6c8 100644 --- a/openmc/capi/plot.py +++ b/openmc/capi/plot.py @@ -1,7 +1,6 @@ from ctypes import c_int, c_int32, c_double, Structure, POINTER from . import _dll -from .core import _DLLGlobal from .error import _error_handler import numpy as np @@ -31,7 +30,7 @@ class _Position(Structure): elif idx == 2: return self.z else: - raise IndexError("{} index is invalid for _Position".format(key)) + raise IndexError("{} index is invalid for _Position".format(idx)) def __setitem__(self, idx, val): if idx == 0: diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index 14dac21fc8..dc3812fe0d 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -438,3 +438,26 @@ def test_property_map(capi_init): properties = openmc.capi.plot.property_map(s) assert np.allclose(expected_properties, properties, atol=1e-04) + + +def test_position(capi_init): + + pos = openmc.capi.plot._Position(1.0, 1.0, 1.0) + + assert pos[0] == 1.0 + assert pos[1] == 1.0 + assert pos[2] == 1.0 + + pos[0] = 1.3 + pos[1] = 1.3 + pos[2] = 1.3 + + assert pos[0] == 1.3 + assert pos[1] == 1.3 + assert pos[2] == 1.3 + + with pytest.raises(IndexError) as e: + pos[3] = 1.3 + + with pytest.raises(IndexError) as e: + pos[-1] = 1.3