-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_random_config_generation.py
99 lines (91 loc) · 2.77 KB
/
test_random_config_generation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Tests that are not specific to any particular kind of task.
"""
import json
import logging
import pickle
import pytest
# bugfix: use same playwright instance in browsergym and pytest
from utils import setup_playwright
from playwright.sync_api import Page, TimeoutError
from tenacity import retry, stop_after_attempt, retry_if_exception_type
from browsergym.workarena.tasks.form import (
CreateChangeRequestTask,
CreateHardwareAssetTask,
CreateIncidentTask,
CreateProblemTask,
CreateUserTask,
)
from browsergym.workarena.tasks.list import (
FilterAssetListTask,
FilterChangeRequestListTask,
FilterHardwareListTask,
FilterIncidentListTask,
FilterServiceCatalogItemListTask,
FilterUserListTask,
SortAssetListTask,
SortChangeRequestListTask,
SortHardwareListTask,
SortIncidentListTask,
SortServiceCatalogItemListTask,
SortUserListTask,
)
from browsergym.workarena.tasks.service_catalog import (
OrderDeveloperLaptopTask,
OrderIpadMiniTask,
OrderIpadProTask,
OrderSalesLaptopTask,
OrderStandardLaptopTask,
OrderAppleWatchTask,
OrderAppleMacBookPro15Task,
OrderDevelopmentLaptopPCTask,
OrderLoanerLaptopTask,
)
RANDOMLY_CONFIGURALBE_TASKS = [
CreateChangeRequestTask,
CreateHardwareAssetTask,
CreateIncidentTask,
CreateProblemTask,
CreateUserTask,
FilterAssetListTask,
FilterChangeRequestListTask,
FilterHardwareListTask,
FilterIncidentListTask,
FilterServiceCatalogItemListTask,
FilterUserListTask,
SortAssetListTask,
SortChangeRequestListTask,
SortHardwareListTask,
SortIncidentListTask,
SortServiceCatalogItemListTask,
SortUserListTask,
OrderDeveloperLaptopTask,
OrderIpadMiniTask,
OrderIpadProTask,
OrderSalesLaptopTask,
OrderStandardLaptopTask,
OrderAppleWatchTask,
OrderAppleMacBookPro15Task,
OrderDevelopmentLaptopPCTask,
OrderLoanerLaptopTask,
]
@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_entrypoint", RANDOMLY_CONFIGURALBE_TASKS)
@pytest.mark.parametrize("random_seed", range(1))
@pytest.mark.slow
@pytest.mark.skip(reason="Tests are too slow")
def test_cheat_from_random_config(task_entrypoint, random_seed: int, page: Page):
task = task_entrypoint(seed=random_seed)
task._generate_random_config(page=page)
chat_messages = []
reward, done, message, info = task.validate(page, chat_messages)
assert done is False and reward == 0.0
task.cheat(page=page, chat_messages=chat_messages)
reward, done, message, info = task.validate(page, chat_messages)
assert done is True and reward == 1.0
task.teardown()