generated from allenai/python-package-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
207 lines (136 loc) · 5.19 KB
/
conftest.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import logging
import uuid
from pathlib import Path
from typing import Generator
import petname
import pytest
from beaker import exceptions
from beaker.client import Beaker
from beaker.data_model import *
logger = logging.getLogger(__name__)
def unique_name() -> str:
return petname.generate() + "-" + str(uuid.uuid4())[:8] # type: ignore
def beaker_object_fixture(client: Beaker, service: str, prefix: str = ""):
name = prefix + unique_name()
service_client = getattr(client, service)
not_found_exception = getattr(exceptions, f"{service.title()}NotFound")
yield name
try:
logger.info("Attempting to remove %s '%s' from Beaker", service, name)
service_client.delete(name)
logger.info("Successfully deleted %s '%s' from Beaker", service, name)
except not_found_exception:
logger.info("%s '%s' not found on Beaker", service.title(), name)
@pytest.fixture()
def workspace_name() -> str:
name = "ai2/beaker-py-testing"
return name
@pytest.fixture()
def alternate_workspace_name() -> str:
name = "ai2/beaker-py-testing-alternative"
return name
@pytest.fixture()
def client(workspace_name):
beaker_client = Beaker.from_env(
session=True, default_workspace=workspace_name, default_org="ai2"
)
return beaker_client
@pytest.fixture()
def alternate_workspace(client: Beaker, alternate_workspace_name: str) -> Workspace:
return client.workspace.get(alternate_workspace_name)
@pytest.fixture
def beaker_org_name() -> str:
return "ai2"
@pytest.fixture()
def beaker_org(client: Beaker, beaker_org_name: str) -> Organization:
return client.organization.get(beaker_org_name)
@pytest.fixture()
def docker_image_name(client: Beaker):
image = "hello-world"
client.docker.images.pull(image)
return image
@pytest.fixture()
def beaker_image_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "image")
@pytest.fixture()
def beaker_python_image_name() -> str:
return "petew/python-3-10-alpine"
@pytest.fixture()
def alternate_beaker_image_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "image")
@pytest.fixture()
def beaker_cluster_name() -> str:
return "ai2/canary"
@pytest.fixture()
def beaker_on_prem_cluster_name() -> str:
return "ai2/allennlp-cirrascale"
@pytest.fixture()
def experiment_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "experiment")
@pytest.fixture()
def alternate_experiment_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "experiment")
@pytest.fixture()
def dataset_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "dataset")
@pytest.fixture()
def alternate_dataset_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "dataset")
@pytest.fixture()
def download_path(dataset_name, tmp_path) -> Path:
path = tmp_path / dataset_name
return path
@pytest.fixture()
def hello_world_experiment_name() -> str:
return "hello-world-1"
@pytest.fixture()
def hello_world_experiment_id() -> str:
return "01GRYY998GG0VP97MKRE574GKA"
@pytest.fixture()
def hello_world_image_name() -> str:
return "petew/hello-world"
@pytest.fixture()
def hello_world_job_id() -> str:
return "01GRYY9P9G5ZJ0F66NV3AHN9AN"
@pytest.fixture()
def beaker_node_id(client: Beaker, beaker_on_prem_cluster_name: str) -> str:
return client.cluster.nodes(beaker_on_prem_cluster_name)[0].id
@pytest.fixture()
def secret_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "secret")
@pytest.fixture()
def archived_workspace_name() -> str:
return "ai2/beaker-py-testing-archived"
@pytest.fixture()
def archived_workspace(client: Beaker, archived_workspace_name: str) -> Workspace:
workspace = client.workspace.ensure(archived_workspace_name)
if not workspace.archived:
return client.workspace.archive(archived_workspace_name)
else:
return workspace
@pytest.fixture()
def squad_dataset_file_name() -> str:
return "squad-train.arrow"
@pytest.fixture()
def squad_dataset_name(client: Beaker, squad_dataset_file_name) -> Generator[str, None, None]:
for dataset_name in beaker_object_fixture(client, "dataset", prefix="squad"):
dataset = client.dataset.create(dataset_name, commit=False)
client.dataset.upload(dataset, b"blahblahblah", squad_dataset_file_name)
client.dataset.commit(dataset)
yield dataset_name
@pytest.fixture()
def alternate_user(client: Beaker) -> Account:
return client.account.get("epwalsh10")
@pytest.fixture()
def group_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "group")
@pytest.fixture()
def alternate_group_name(client: Beaker) -> Generator[str, None, None]:
yield from beaker_object_fixture(client, "group")
@pytest.fixture()
def experiment_id_with_metrics() -> str:
return "01G371J03VGJGK720TMZWFQNV3"
# experiment was deleted
# @pytest.fixture()
# def experiment_id_with_results() -> str:
# return "01G371J03VGJGK720TMZWFQNV3"