Skip to content

Commit

Permalink
add test files
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Nov 28, 2024
1 parent 802581a commit 3b5a990
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/files/configs/test_config_parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ data:
available:
- initial_conditions:
type: file
src: .
src: initial_conditions
- forcing:
type: file
src: .
src: forcing
generated:
- icon_output:
type: file
Expand Down
Empty file added tests/files/data/era5
Empty file.
Empty file added tests/files/data/file.ncdf
Empty file.
Empty file added tests/files/data/grid
Empty file.
Empty file added tests/files/data/input
Empty file.
Empty file added tests/files/data/obs_data
Empty file.
Empty file added tests/files/scripts/argparse
Empty file.
9 changes: 9 additions & 0 deletions tests/files/scripts/cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python

def main():
# Main script execution continues here
print("Cleaning")


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions tests/files/scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "cleanup" > output
1 change: 1 addition & 0 deletions tests/files/scripts/extpar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "extpar" > output
4 changes: 4 additions & 0 deletions tests/files/scripts/icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo "icon" > restart
echo "icon" > output
echo "icon" > output_1
echo "icon" > output_2
41 changes: 41 additions & 0 deletions tests/files/scripts/icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python

import argparse
from pathlib import Path

def main():
parser = argparse.ArgumentParser(description='A simple script with an optional restart argument.')
parser.add_argument('icon_input', type=str, help='The icon input.')
parser.add_argument('--restart', nargs='?', type=str, help='The icon restart file.')
#parser.add_argument('--restart', nargs='?', const='default', type=str, help='Initiate a restart operation with an optional string argument.')


args = parser.parse_args()

output = Path('output')
output.write_text("")

if args.restart:
restart = Path(args.restart)
restart.read_text()
text = "Restart operation initiated..."
print(text)
with output.open("a") as f:
f.write(text)
else:
text = "No restart option provided. Continuing without restart."
print(text)
with output.open("a") as f:
f.write(text)

# Main script execution continues here
text = "Script execution continues..."
print(text)
with output.open("a") as f:
f.write(text)

restart = Path('restart')
restart.write_text("")

if __name__ == '__main__':
main()
48 changes: 48 additions & 0 deletions tests/files/scripts/icon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Function to write text to the output file
write_to_output() {
local text="$1"
echo "$text"
echo "$text" >> output
}

# Check if at least one argument is provided
if [ "$#" -lt 1 ]; then
echo "Usage: $0 icon_input [--restart [restart_file]]"
exit 1
fi

# Positional argument
icon_input="$1"

# Optional restart argument
restart_file=""

if [ "$2" == "--restart" ]; then
if [ -n "$3" ]; then
restart_file="$3"
fi
fi

# Create/empty the output file
> output

# Handling restart if the argument is provided
if [ -n "$restart_file" ]; then
if [ -f "$restart_file" ]; then
cat "$restart_file" > /dev/null
write_to_output "Restart operation initiated..."
else
echo "Restart file $restart_file does not exist."
exit 1
fi
else
write_to_output "No restart option provided. Continuing without restart."
fi

# Main script execution continues here
write_to_output "Script execution continues..."

# Create/empty the restart file
> restart
1 change: 1 addition & 0 deletions tests/files/scripts/main_script_atm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "main_script_atm.sh" > postout
1 change: 1 addition & 0 deletions tests/files/scripts/main_script_ocn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "python main_script_ocn.sh" > postout
1 change: 1 addition & 0 deletions tests/files/scripts/post_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "store_and_clean" > stored_data
38 changes: 34 additions & 4 deletions tests/test_wc_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,47 @@ def pprinter():
return PrettyPrinter()


# configs that are tested only tested parsing
config_test_files = [
"tests/files/configs/test_config_small.yml",
#"tests/files/configs/test_config_large.yml",
"tests/files/configs/test_config_large.yml",
"tests/files/configs/test_config_parameters.yml",
]

def test_run_workgraph(config_case, aiida_profile): # noqa: ARG001
config_path, _ = config_case

@pytest.mark.parametrize("config_path", [
"tests/files/configs/test_config_small.yml",
#"tests/files/configs/test_config_parameters.yml",
])
def test_run_workgraph(config_path):
core_workflow = Workflow.from_yaml(config_path)
aiida_workflow = AiidaWorkGraph(core_workflow)
aiida_workflow.run()
# ERROR that is not shown if not run manually:
#
# Continue workgraph.
# ------------------------------------------------------------
# ------------------------------------------------------------
# task: icon_date_2026_01_01_00_00_00 RUNNING
# task: icon_date_2026_03_01_00_00_00 PLANNED
# task: icon_date_2026_05_01_00_00_00 PLANNED
# task: cleanup RUNNING
# is workgraph finished: False
# on awaitable finished: icon_date_2026_01_01_00_00_00
# update task state: icon_date_2026_01_01_00_00_00
# on awaitable finished: cleanup
# update task state: cleanup
# Continue workgraph.
# task: icon_date_2026_01_01_00_00_00 FAILED
# task: icon_date_2026_03_01_00_00_00 SKIPPED
# task: icon_date_2026_05_01_00_00_00 SKIPPED
# task: cleanup FAILED
# is workgraph finished: True
# {}
#
# Figure out why output is not generated
breakpoint()
out = aiida_workflow.run()
assert out != {} # should contain node id

@pytest.fixture(params=config_test_files)
def config_case(request):
Expand Down

0 comments on commit 3b5a990

Please sign in to comment.