-
Notifications
You must be signed in to change notification settings - Fork 110
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
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os.path | ||
import subprocess | ||
from metadrive import MetaDrive_PACKAGE_DIR | ||
import time | ||
import pytest | ||
|
||
examples = ["draw_maps.py", | ||
"drive_in_multi_agent_env.py --top_down", | ||
"drive_in_waymo_env.py --top_down", | ||
"drive_in_waymo_env.py --reactive_traffic", | ||
"drive_in_safe_metadrive_env.py", | ||
"drive_in_single_agent_env.py", | ||
"procedural_generation.py", | ||
"profile_metadrive.py", | ||
"profile_metadrive_marl.py", | ||
"top_down_metadrive.py"] | ||
examples_dir_path = os.path.join(MetaDrive_PACKAGE_DIR, "examples") | ||
scripts = [os.path.join(examples_dir_path, exp) for exp in examples] | ||
|
||
|
||
@pytest.mark.parametrize("script", scripts, ids=examples) | ||
def test_script(script, timeout=60): | ||
""" | ||
Run script in a subprocess and check its running time. | ||
Args: | ||
script: the path to the script | ||
timeout: script that can run over `timeout` seconds can pass the test | ||
Returns: None | ||
""" | ||
start_time = time.time() | ||
|
||
# Run your script using subprocess | ||
process = subprocess.Popen(['python', script]) | ||
|
||
# Wait for the script to finish or timeout after 60 seconds | ||
try: | ||
process.wait(timeout=timeout) | ||
except subprocess.TimeoutExpired: | ||
# If the script is still running after 60 seconds, terminate it and pass the test | ||
process.kill() | ||
finally: | ||
runtime = time.time() - start_time | ||
assert runtime >= 0, "Script terminated unexpectedly" |