-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEST] Add integration test for training script (#11)
- Loading branch information
Showing
6 changed files
with
52 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Contains tests of the example.""" |
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,23 @@ | ||
"""Check that the training script is working.""" | ||
|
||
from os import environ, getenv, path | ||
from test.utils import run_verbose | ||
|
||
HERE_DIR = path.dirname(path.abspath(__file__)) | ||
TRAINING_SCRIPT = path.abspath(path.join(HERE_DIR, "..", "..", "example", "train.py")) | ||
|
||
|
||
def test_training_script(): | ||
"""Execute the training script.""" | ||
# Use wandb in offline mode. We do not want to upload the logs this test generates | ||
ORIGINAL_WANDB_MODE = getenv("WANDB_MODE") | ||
environ["WANDB_MODE"] = "offline" | ||
|
||
# Run the training script | ||
run_verbose(["python", TRAINING_SCRIPT, "--epochs=3"]) | ||
|
||
# Restore the original value of WANDB_MODE | ||
if ORIGINAL_WANDB_MODE is None: | ||
environ.pop("WANDB_MODE") | ||
else: | ||
environ["WANDB_MODE"] = ORIGINAL_WANDB_MODE |
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
"""Utility functions for tests.""" | ||
|
||
from subprocess import CalledProcessError, CompletedProcess, run | ||
from typing import List | ||
|
||
|
||
def run_verbose(cmd: List[str]) -> CompletedProcess: | ||
"""Run a command and print stdout & stderr if it fails. | ||
Args: | ||
cmd: The command to run. | ||
Returns: | ||
CompletedProcess: The result of the command. | ||
Raises: | ||
CalledProcessError: If the command fails. | ||
""" | ||
try: | ||
job = run(cmd, capture_output=True, text=True, check=True) | ||
print("STDOUT:", job.stdout) | ||
print("STDERR:", job.stderr) | ||
return job | ||
except CalledProcessError as e: | ||
print("STDOUT:", e.stdout) | ||
print("STDERR:", e.stderr) | ||
raise e |
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