Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions openmc/utility_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def input_path(filename: PathLike) -> Path:
Path object

"""
# An empty filename represents the absence of a path (e.g., a mesh or
# DAGMC universe read back from a summary/statepoint file that was never
# written with a source file) and should not be resolved to the current
# working directory.
filename = os.fspath(filename)
if not filename:
return Path(filename)

if openmc.config['resolve_paths']:
path = Path(filename)
xml_dir = _XML_INPUT_PATH.get()
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ def test_umesh_from_hdf5_without_filename(run_in_tmpdir):
group['connectivity'] = np.zeros((1, 8), dtype=int)
group['element_types'] = [0]

mesh = openmc.MeshBase.from_hdf5(group)
with openmc.config.patch('resolve_paths', True):
mesh = openmc.MeshBase.from_hdf5(group)

assert mesh.filename == Path()
assert mesh.has_statepoint_data
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/test_universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def test_dagmc_universe_from_hdf5_without_filename(run_in_tmpdir):
group.attrs['auto_mat_ids'] = 1
group.attrs['length_multiplier'] = 1.0

univ = openmc.DAGMCUniverse.from_hdf5(group)
with openmc.config.patch('resolve_paths', True):
univ = openmc.DAGMCUniverse.from_hdf5(group)

assert univ.id == 1
assert univ.filename == Path()
Expand Down
20 changes: 20 additions & 0 deletions tests/unit_tests/test_utility_funcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

import openmc
from openmc.utility_funcs import input_path


def test_input_path_empty_not_resolved():
"""An empty filename represents "no file" (e.g., an in-memory mesh or
DAGMC universe read back from a summary/statepoint that was never
written with a source file, see UnstructuredMesh.from_hdf5 and
DAGMCUniverse.from_hdf5) and should stay empty rather than being
resolved to the current working directory."""
with openmc.config.patch('resolve_paths', True):
assert input_path('') == Path()


def test_input_path_nonempty_resolved(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
with openmc.config.patch('resolve_paths', True):
assert input_path('foo.h5') == (tmp_path / 'foo.h5').resolve()
3 changes: 1 addition & 2 deletions tests/unit_tests/weightwindows/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
from itertools import product
from pathlib import Path

import pytest

import numpy as np
from uncertainties import ufloat

import openmc
import openmc.lib
from openmc.stats import Discrete, Point
Expand Down
Loading