diff --git a/pelicun/tests/dl_calculation/portfolio_1/test_portfolio1.py b/pelicun/tests/dl_calculation/portfolio_1/test_portfolio1.py index a90f78f4..4c122f1b 100644 --- a/pelicun/tests/dl_calculation/portfolio_1/test_portfolio1.py +++ b/pelicun/tests/dl_calculation/portfolio_1/test_portfolio1.py @@ -34,9 +34,9 @@ """DL Calculation Portfolio Example 1.""" -import sys import os import shutil +import sys import tempfile from pathlib import Path from typing import Generator @@ -46,47 +46,48 @@ from pelicun.pelicun_warnings import PelicunWarning from pelicun.tools import DL_calculation -# @pytest.fixture -# def obtain_temp_dir() -> Generator: -# # get the path of this file -# this_file = __file__ -# initial_dir = Path.cwd() -# this_dir = str(Path(this_file).parent) +@pytest.fixture +def obtain_temp_dir() -> Generator: + # get the path of this file + this_file = __file__ + + initial_dir = Path.cwd() + this_dir = str(Path(this_file).parent) -# temp_dir = tempfile.mkdtemp() + temp_dir = tempfile.mkdtemp() -# yield this_dir, temp_dir + yield this_dir, temp_dir -# # go back to the right directory, otherwise any tests that follow -# # could have issues. -# os.chdir(initial_dir) + # go back to the right directory, otherwise any tests that follow + # could have issues. + os.chdir(initial_dir) def test_dl_calculation_portfolio_1(obtain_temp_dir: str) -> None: - # this_dir: str - # temp_dir: str - - # this_dir, temp_dir = obtain_temp_dir # type: ignore - - # # Copy all input files to a temporary directory. - # # All outputs will also go there. - # # This approach is more robust to changes in the output files over - # # time. - - # os.chdir(this_dir) - # temp_dir = tempfile.mkdtemp() - # # copy input files - # for file_name in ( - # '400-AIM.json', - # '401-AIM.json', - # '401-CMP_QNT.csv', - # 'response.csv', - # ): - # shutil.copy(f'{this_dir}/{file_name}', f'{temp_dir}/{file_name}') + this_dir: str + temp_dir: str + + this_dir, temp_dir = obtain_temp_dir # type: ignore + + # Copy all input files to a temporary directory. + # All outputs will also go there. + # This approach is more robust to changes in the output files over + # time. + + os.chdir(this_dir) + temp_dir = tempfile.mkdtemp() + # copy input files + for file_name in ( + '400-AIM.json', + '401-AIM.json', + 'portfolio_assessment_configuration.json', + 'response.csv', + ): + shutil.copy(f'{this_dir}/{file_name}', f'{temp_dir}/{file_name}') - # # change directory to there - # os.chdir(temp_dir) + # change directory to there + os.chdir(temp_dir) # run sys.argv = [