-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Run the examples and check their output
- Loading branch information
Showing
11 changed files
with
93 additions
and
2 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
1 change: 1 addition & 0 deletions
1
example/ex_2_running_certain_stages_by_default.py
100644 → 100755
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
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,81 @@ | ||
#!/usr/bin/env python3 | ||
"""Run all the examples and ensure their output is correct.""" | ||
|
||
# © 2024 National Technology & Engineering Solutions of Sandia, LLC | ||
# (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the | ||
# U.S. Government retains certain rights in this software. | ||
|
||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import re | ||
import shlex | ||
import subprocess | ||
from datetime import datetime, timedelta, timezone | ||
from pathlib import Path | ||
from typing import List | ||
|
||
|
||
def assert_output_in_order(stdout: str, output: List[str]) -> None: | ||
""" | ||
Ensure the output appears in the correct order. | ||
Args: | ||
stdout: The ``stdout`` of the command that was run. | ||
output: The list of terms that should appear in the output in | ||
the given order. | ||
Raises: | ||
ValueError: If any of the terms in the output list cannot be | ||
found. | ||
""" | ||
index = 0 | ||
for term in output: | ||
index = stdout.find(term, index) + len(term) | ||
|
||
|
||
def test_ex_0_the_basics_help() -> None: | ||
example = Path(__file__).parent / "ex_0_the_basics.py" | ||
result = subprocess.run( | ||
[example, "--help"], | ||
capture_output=True, | ||
check=True, | ||
text=True, | ||
) | ||
assert_output_in_order( | ||
result.stdout, | ||
[ | ||
"the ArgumentParser for the StagedScript base class.", | ||
"--stage {goodbye,hello}", | ||
"--goodbye-retry-attempts", | ||
"--goodbye-retry-delay", | ||
"--goodbye-retry-timeout", | ||
"--hello-retry-attempts", | ||
"--hello-retry-delay", | ||
"--hello-retry-timeout", | ||
], | ||
) | ||
|
||
|
||
def test_ex_0_the_basics() -> None: | ||
example = Path(__file__).parent / "ex_0_the_basics.py" | ||
result = subprocess.run( | ||
[example, "--stage", "hello"], | ||
capture_output=True, | ||
check=True, | ||
text=True, | ||
) | ||
assert_output_in_order( | ||
result.stdout, | ||
[ | ||
"Greeting the user", | ||
"Executing: echo 'Hello World'", | ||
"`hello` stage duration", | ||
"Bidding farewell", | ||
"Skipping this stage", | ||
"`goodbye` stage duration", | ||
"Ran the following", | ||
"Commands executed", | ||
"Timing results", | ||
"Script result", | ||
], | ||
) |
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