mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 06:25:30 -04:00
Tests: adding option to copy file into temp dir.
This commit is contained in:
parent
07629d7218
commit
3ef71de5f9
1 changed files with 12 additions and 2 deletions
|
|
@ -1,13 +1,23 @@
|
|||
from contextlib import contextmanager
|
||||
import os
|
||||
from shutil import copy
|
||||
import tempfile
|
||||
|
||||
|
||||
@contextmanager
|
||||
def cdtemp():
|
||||
"""Context manager to change to/return from a tmpdir."""
|
||||
def cdtemp(files=None):
|
||||
"""Context manager to change to/return from a tmpdir.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
files : Iterable of str or Path-like
|
||||
Set of files to copy into the temporary directory
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
cwd = os.getcwd()
|
||||
if files:
|
||||
for file in files:
|
||||
copy(file, tmpdir, follow_symlinks=True)
|
||||
try:
|
||||
os.chdir(tmpdir)
|
||||
yield
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue