-
Notifications
You must be signed in to change notification settings - Fork 39
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
53 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,53 @@ | ||
import gymnasium as gym | ||
import logging | ||
import os | ||
import pytest | ||
import random | ||
|
||
from tenacity import retry, stop_after_attempt, retry_if_exception_type | ||
|
||
# register gym environments | ||
import browsergym.webarena | ||
|
||
# bugfix: use same playwright instance in browsergym and pytest | ||
from utils import setup_playwright | ||
|
||
|
||
__SLOW_MO = 1000 if "DISPLAY_BROWSER" in os.environ else None | ||
__HEADLESS = False if "DISPLAY_BROWSER" in os.environ else True | ||
|
||
INFEAS_TASK_IDS = [101, 115, 166] | ||
FEAS_TASK_IDS = [165, 187, 199] | ||
|
||
|
||
@retry( | ||
stop=stop_after_attempt(5), | ||
retry=retry_if_exception_type(TimeoutError), | ||
reraise=True, | ||
before_sleep=lambda _: logging.info("Retrying due to a TimeoutError..."), | ||
) | ||
@pytest.mark.parametrize( | ||
"task_id,infeasible", | ||
[(task_id, True) for task_id in INFEAS_TASK_IDS] | ||
+ [(task_id, False) for task_id in FEAS_TASK_IDS], | ||
) | ||
@pytest.mark.slow | ||
def test_infeasible(task_id, infeasible): | ||
env = gym.make( | ||
f"browsergym/webarena.{task_id}", | ||
headless=__HEADLESS, | ||
slow_mo=__SLOW_MO, | ||
) | ||
obs, info = env.reset() | ||
|
||
action = 'report_infeasible("Unachievable task.")' | ||
|
||
obs, reward, term, trunc, info = env.step(action) | ||
|
||
if infeasible: | ||
assert term == True and reward == 1.0 | ||
|
||
else: | ||
assert term == True and reward == 0.0 | ||
|
||
env.close() |