Skip to content

Commit

Permalink
Update test_portfolio1.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannis-vm committed Dec 15, 2024
1 parent 791f658 commit 4b4926d
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions pelicun/tests/dl_calculation/portfolio_1/test_portfolio1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down

0 comments on commit 4b4926d

Please sign in to comment.