Skip to content

Commit

Permalink
Update draft of pipeline test - first exit 0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGering committed Jan 8, 2024
1 parent 1fc5da3 commit ec73c7b
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
output_file_path = os.path.join(os.getcwd(), output_rule)


def check_if_output_exists(path):
return os.path.exists(path)


def rename_file(before, after):
def rename_file(file_path, before, after):
# Split the path and file name
directory, filename = os.path.split(output_file_path)
directory, filename = os.path.split(file_path)

# Add "_original" before the file extension
new_filename = filename.replace(before, after)
Expand All @@ -23,21 +19,25 @@ def rename_file(before, after):
new_file_path = os.path.join(directory, new_filename)

# Check if file with name after already exists
if check_if_output_exists(new_file_path):
if os.path.exists(new_file_path):
raise FileExistsError(
f"File {new_file_path} already exists and therefore we can not rename your file"
f" {filename}.\n"
f"Please rename the file {new_filename} first."
)

# Rename the file
os.rename(output_file_path, new_file_path)
os.rename(file_path, new_file_path)
print(f"File '{filename}' has been")

return new_file_path


def test_empty_scalars():
if check_if_output_exists(output_file_path):
rename_file(".csv", "_original.csv")
rename = False
if os.path.exists(output_file_path):
rename = True
renamed_file_path = rename_file(output_file_path, ".csv", "_original.csv")

try:
# Run the snakemake rule: create_empty_scalars
Expand All @@ -53,16 +53,18 @@ def test_empty_scalars():

os.remove(output_file_path)

rename_file("_original.csv", ".csv")
if rename:
rename_file(renamed_file_path, "_original.csv", ".csv")

except (BaseException):
except BaseException:
print(
f"The workflow {output_rule} could not be executed correctly. "
f"Changes will be reverted."
)

# Revert changes
if check_if_output_exists():
if os.path.exists(output_file_path):
os.remove(output_file_path)

rename_file("_original.csv", ".csv")
if rename:
rename_file(renamed_file_path, "_original.csv", ".csv")

0 comments on commit ec73c7b

Please sign in to comment.