Skip to content

Commit

Permalink
Add check for '_original' file existence in function pipeline_file_o…
Browse files Browse the repository at this point in the history
…utput_test
  • Loading branch information
Stefanie08 committed Oct 18, 2024
1 parent 1d60177 commit f7d6cef
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions oemof_b3/tools/testing_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,19 @@ def pipeline_file_output_test(delete_switch, output_rule_list):
for raw_file_path in absolute_path_list:
# Check if file already exists in directory
if os.path.isfile(raw_file_path):
# Rename file with extension original
# Rename file with extension '_original'
renamed_file = file_name_extension(raw_file_path)
renamed_path.append(renamed_file)
if not os.path.isfile(raw_file_path):
# Add '_original' extension to path file
file_name, file_ext = os.path.splitext(raw_file_path)
renamed_file = f"{file_name}_original{file_ext}"
# Check if the '_original' extension exist
if os.path.isfile(renamed_file):
raise FileExistsError(
f"File {renamed_file} already exists."
f"Please rename the file {renamed_file} first."
)

try:
# Run the snakemake rule
Expand Down Expand Up @@ -424,12 +434,12 @@ def pipeline_folder_output_test(delete_switch, output_rule_list):
try:
# Check if file already exists in directory
if os.path.isfile(raw_dir_path):
# Rename file with extension original
# Rename file with extension '_original'
renamed_file = file_name_extension(raw_dir_path)
renamed_file_path.append(renamed_file)
# Check if file already exists in directory
# Check if directory already exists
if os.path.isdir(raw_dir_path):
# Rename file with extension original
# Rename file with extension '_original'
renamed_file = rename_path(raw_dir_path, "", "")
renamed_file_path.append(renamed_file)
else:
Expand Down

0 comments on commit f7d6cef

Please sign in to comment.