You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
415 B
17 lines
415 B
import tempfile
|
|
from pathlib import Path
|
|
from contextlib import contextmanager
|
|
import shutil
|
|
|
|
|
|
@contextmanager
|
|
def make_tempdir(files={}, mode="w"):
|
|
temp_dir_str = tempfile.mkdtemp()
|
|
temp_dir = Path(temp_dir_str)
|
|
for name, content in files.items():
|
|
path = temp_dir / name
|
|
with path.open(mode) as file_:
|
|
file_.write(content)
|
|
yield temp_dir
|
|
shutil.rmtree(temp_dir_str)
|