From d47f41637f76f5ed81976d5c4c9a1027c8c6e320 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Aug 2022 07:53:36 -0500 Subject: [PATCH] Some updates to DAGMC testing. --- openmc/universe.py | 4 ++-- tests/regression_tests/dagmc/legacy/test.py | 3 ++- .../regression_tests/dagmc/universes/test.py | 22 ------------------- .../test_bounds.py} | 12 +++++----- 4 files changed, 10 insertions(+), 31 deletions(-) rename tests/unit_tests/{test_dagmc_universe.py => dagmc/test_bounds.py} (87%) diff --git a/openmc/universe.py b/openmc/universe.py index 727e7a096d..65bcce7470 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -678,8 +678,8 @@ class DAGMCUniverse(UniverseBase): @filename.setter def filename(self, val): - cv.check_type('DAGMC filename', val, str) - self._filename = val + cv.check_type('DAGMC filename', val, (Path, str)) + self._filename = str(val) @property def auto_geom_ids(self): diff --git a/tests/regression_tests/dagmc/legacy/test.py b/tests/regression_tests/dagmc/legacy/test.py index e0fccb9344..dacbc19ee0 100644 --- a/tests/regression_tests/dagmc/legacy/test.py +++ b/tests/regression_tests/dagmc/legacy/test.py @@ -1,6 +1,7 @@ import openmc import openmc.lib +from pathlib import Path import pytest from tests.testing_harness import PyAPITestHarness @@ -27,7 +28,7 @@ def model(): model.settings.dagmc = True # geometry - dag_univ = openmc.DAGMCUniverse("dagmc.h5m") + dag_univ = openmc.DAGMCUniverse(Path("dagmc.h5m")) model.geometry = openmc.Geometry(dag_univ) # tally diff --git a/tests/regression_tests/dagmc/universes/test.py b/tests/regression_tests/dagmc/universes/test.py index 67c8f962d8..47897ad568 100644 --- a/tests/regression_tests/dagmc/universes/test.py +++ b/tests/regression_tests/dagmc/universes/test.py @@ -53,28 +53,6 @@ class DAGMCUniverseTest(PyAPITestHarness): # assigns the bound_dag_geometry to the model to test the type checks in model.Geometry setter model.Geometry = bound_pincell_geometry - # checks that the bounding box is calculated correctly - bounding_box = pincell_univ.bounding_box - assert bounding_box[0].tolist() == [-25., -25., -25.] - assert bounding_box[1].tolist() == [25., 25., 25.] - - # checks that the bounding region is six surfaces each with a vacuum boundary type - b_region = pincell_univ.bounding_region(bounded_type='box', boundary_type='vacuum') - assert isinstance(b_region, openmc.Region) - assert len(b_region.get_surfaces()) == 6 - starting_id = 10000 - for i, surface in enumerate(b_region.get_surfaces().values()): - assert surface.boundary_type == 'vacuum' - assert surface.id == 10000 + i - - # checks that the bounding region is a single surface with a reflective boundary type - b_region = pincell_univ.bounding_region(bounded_type='sphere', boundary_type='reflective') - assert isinstance(b_region, openmc.Region) - assert len(b_region.get_surfaces()) == 1 - for surface in list(b_region.get_surfaces().values()): - assert surface.boundary_type == 'reflective' - assert surface.id == 10000 - # create a 2 x 2 lattice using the DAGMC pincell pitch = np.asarray((24.0, 24.0)) lattice = openmc.RectLattice() diff --git a/tests/unit_tests/test_dagmc_universe.py b/tests/unit_tests/dagmc/test_bounds.py similarity index 87% rename from tests/unit_tests/test_dagmc_universe.py rename to tests/unit_tests/dagmc/test_bounds.py index 9904fa03b3..dbca3ca253 100644 --- a/tests/unit_tests/test_dagmc_universe.py +++ b/tests/unit_tests/dagmc/test_bounds.py @@ -3,21 +3,21 @@ import pytest from pathlib import Path -def test_bounding_box(): +def test_bounding_box(request): """Checks that the DAGMCUniverse.bounding_box returns the correct values""" - u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) + u = openmc.DAGMCUniverse(Path(request.fspath).parent / "dagmc.h5m") ll, ur = u.bounding_box assert ll == pytest.approx((-25.0, -25.0, -25)) assert ur == pytest.approx((25.0, 25.0, 25)) -def test_bounding_region(): +def test_bounding_region(request): """Checks that the DAGMCUniverse.bounding_region() returns a region with correct surfaces and boundary types""" - u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) + u = openmc.DAGMCUniverse(Path(request.fspath).parent / "dagmc.h5m") region = u.bounding_region() # should default to bounded_type='box' assert isinstance(region, openmc.Region) @@ -42,11 +42,11 @@ def test_bounding_region(): assert region.surface.boundary_type == "reflective" -def test_bounded_universe(): +def test_bounded_universe(request): """Checks that the DAGMCUniverse.bounded_universe() returns a openmc.Universe with correct surface ids and cell ids""" - u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) + u = openmc.DAGMCUniverse(Path(request.fspath).parent / "dagmc.h5m") # bounded with defaults bu = u.bounded_universe()