File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,6 +69,14 @@ def input_path(filename: PathLike) -> Path:
6969 Path object
7070
7171 """
72+ # An empty filename represents the absence of a path (e.g., a mesh or
73+ # DAGMC universe read back from a summary/statepoint file that was never
74+ # written with a source file) and should not be resolved to the current
75+ # working directory.
76+ filename = os .fspath (filename )
77+ if not filename :
78+ return Path (filename )
79+
7280 if openmc .config ['resolve_paths' ]:
7381 path = Path (filename )
7482 xml_dir = _XML_INPUT_PATH .get ()
Original file line number Diff line number Diff line change @@ -470,7 +470,8 @@ def test_umesh_from_hdf5_without_filename(run_in_tmpdir):
470470 group ['connectivity' ] = np .zeros ((1 , 8 ), dtype = int )
471471 group ['element_types' ] = [0 ]
472472
473- mesh = openmc .MeshBase .from_hdf5 (group )
473+ with openmc .config .patch ('resolve_paths' , True ):
474+ mesh = openmc .MeshBase .from_hdf5 (group )
474475
475476 assert mesh .filename == Path ()
476477 assert mesh .has_statepoint_data
Original file line number Diff line number Diff line change @@ -198,7 +198,8 @@ def test_dagmc_universe_from_hdf5_without_filename(run_in_tmpdir):
198198 group .attrs ['auto_mat_ids' ] = 1
199199 group .attrs ['length_multiplier' ] = 1.0
200200
201- univ = openmc .DAGMCUniverse .from_hdf5 (group )
201+ with openmc .config .patch ('resolve_paths' , True ):
202+ univ = openmc .DAGMCUniverse .from_hdf5 (group )
202203
203204 assert univ .id == 1
204205 assert univ .filename == Path ()
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
3+ import openmc
4+ from openmc .utility_funcs import input_path
5+
6+
7+ def test_input_path_empty_not_resolved ():
8+ """An empty filename represents "no file" (e.g., an in-memory mesh or
9+ DAGMC universe read back from a summary/statepoint that was never
10+ written with a source file, see UnstructuredMesh.from_hdf5 and
11+ DAGMCUniverse.from_hdf5) and should stay empty rather than being
12+ resolved to the current working directory."""
13+ with openmc .config .patch ('resolve_paths' , True ):
14+ assert input_path ('' ) == Path ()
15+
16+
17+ def test_input_path_nonempty_resolved (tmp_path , monkeypatch ):
18+ monkeypatch .chdir (tmp_path )
19+ with openmc .config .patch ('resolve_paths' , True ):
20+ assert input_path ('foo.h5' ) == (tmp_path / 'foo.h5' ).resolve ()
Original file line number Diff line number Diff line change 11import os
22from itertools import product
3+ from pathlib import Path
34
45import pytest
5-
66import numpy as np
77from uncertainties import ufloat
8-
98import openmc
109import openmc .lib
1110from openmc .stats import Discrete , Point
You can’t perform that action at this time.
0 commit comments