-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: "Run cucumber tests" | ||
description: "Run cucumber tests" | ||
inputs: | ||
feature: | ||
description: 'Feature file or folder to run (default runs all features in "features" folder)' | ||
required: false | ||
default: 'features' | ||
tags: | ||
description: 'Tags to run (default skips tests marked @flaky)' | ||
required: false | ||
default: '~@flaky' | ||
mpi_path: | ||
description: "Mpi install directory" | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
|
||
- name: Run tests | ||
shell: bash | ||
run: | | ||
export PATH="${{ inputs.mpi_path }}:$PATH" | ||
cd tests/end_to_end | ||
behave --tags ${{ inputs.tags }} cucumber/${{ inputs.feature }} --no-capture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
pytest | ||
numpy | ||
pytest-cov | ||
behave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/end_to_end/cucumber/features/outer_loop_tests.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: outer loop tests | ||
|
||
@fast @short @outerloop | ||
Scenario: a system with 4 nodes, on 1 timestep, 2 scenarios | ||
Given the study path is "data_test/external_loop_test" | ||
When I run outer loop with 1 proc(s) | ||
Then the simulation takes less than 5 seconds | ||
And the simulation succeeds | ||
And the expected overall cost is 92.70005 | ||
And the solution is | ||
| variable | value | | ||
| G_p_max_0_0 | 2.900004 | |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import json | ||
import os | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
from behave import * | ||
|
||
from utils_functions import get_mpi_command, get_conf | ||
|
||
|
||
@given('the study path is "{string}"') | ||
def study_path_is(context, string): | ||
context.study_path = os.path.join(Path() / "../../", | ||
string.replace("/", os.sep)) | ||
|
||
|
||
def build_outer_loop_command(context): | ||
command = get_mpi_command(allow_run_as_root=context.allow_run_as_root, nproc=context.nproc) | ||
exe_path = Path(get_conf("DEFAULT_INSTALL_DIR")) / get_conf("OUTER_LOOP") | ||
command.append(str(exe_path)) | ||
command.append("options.json") | ||
return command | ||
|
||
|
||
|
||
def read_outputs(output_path): | ||
with open(output_path, 'r') as file: | ||
outputs = json.load(file) | ||
|
||
return outputs | ||
|
||
|
||
@when('I run outer loop with {n} proc(s)') | ||
def run_outer_loop(context, n): | ||
context.nproc = int(n) | ||
context.allow_run_as_root = get_conf("allow_run_as_root") | ||
command = build_outer_loop_command(context) | ||
print(f"Running command: {command}") | ||
old_cwd = os.getcwd() | ||
lp_path = Path(context.study_path) / "lp" | ||
|
||
os.chdir(lp_path) | ||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) | ||
out, err = process.communicate() | ||
# print(out) | ||
# print("*****") | ||
# print(err) | ||
context.return_code = process.returncode | ||
context.outputs = read_outputs(Path("..") / "expansion" / "out.json") | ||
os.chdir(old_cwd) | ||
|
||
|
||
@then("the simulation takes less than {seconds} seconds") | ||
def check_simu_time(context, seconds): | ||
assert context.outputs["run_duration"] <= float(seconds) | ||
|
||
|
||
@then("the simulation succeeds") | ||
def simu_success(context): | ||
return context.return_code == 0 | ||
|
||
|
||
@then("the expected overall cost is {value}") | ||
def check_overall_cost(context, value): | ||
np.testing.assert_allclose(float(value), | ||
context.outputs["solution"]["overall_cost"], rtol=1e-6, atol=0) | ||
|
||
|
||
def assert_dict_allclose(actual, expected, rtol=1e-06, atol=0): | ||
for key in expected: | ||
np.testing.assert_allclose( | ||
actual[key], | ||
expected[key], | ||
rtol=rtol, | ||
atol=atol, | ||
err_msg=f"Mismatch found at key '{key}'" | ||
) | ||
|
||
|
||
@then("the solution is") | ||
def check_solution(context): | ||
expected_solution = {row['variable']: float(row['value']) for row in context.table} | ||
assert_dict_allclose(context.outputs["solution"]["values"], expected_solution) |