-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_run.py
More file actions
211 lines (182 loc) · 7.09 KB
/
test_run.py
File metadata and controls
211 lines (182 loc) · 7.09 KB
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
208
209
210
211
import contextlib
import json
import pytest
import time
import datetime
import uuid
from simvue.api.objects.run import RunBatchArgs
from simvue.sender import sender
from simvue.api.objects import Run, Folder
from simvue.client import Client
@pytest.mark.api
@pytest.mark.online
def test_run_creation_online() -> None:
_uuid: str = f"{uuid.uuid4()}".split("-")[0]
_folder_name = f"/simvue_unit_testing/{_uuid}"
_folder = Folder.new(path=_folder_name)
_run = Run.new(folder=_folder_name)
_folder.commit()
_run.commit()
assert _run.folder == _folder_name
_run.delete()
_folder.delete(recursive=True, delete_runs=True, runs_only=False)
@pytest.mark.api
@pytest.mark.offline
def test_run_creation_offline(offline_cache_setup) -> None:
_uuid: str = f"{uuid.uuid4()}".split("-")[0]
_run_name = f"simvue_offline_run_{_uuid}"
_folder_name = f"/simvue_unit_testing/{_uuid}"
_folder = Folder.new(path=_folder_name, offline=True)
_run = Run.new(name=_run_name,folder=_folder_name, offline=True)
_folder.commit()
_run.commit()
assert _run.name == _run_name
assert _run.folder == _folder_name
with _run._local_staging_file.open() as in_f:
_local_data = json.load(in_f)
assert _local_data.get("name") == f"simvue_offline_run_{_uuid}"
assert _local_data.get("folder") == _folder_name
sender(_run._local_staging_file.parents[1], 1, 10, ["folders", "runs"])
time.sleep(1)
# Get online ID and retrieve run
_online_id = _run._local_staging_file.parents[1].joinpath("server_ids", f"{_run._local_staging_file.name.split('.')[0]}.txt").read_text()
_online_run = Run(_online_id)
assert _online_run.name == _run_name
assert _online_run.folder == _folder_name
_run.delete()
_run._local_staging_file.parents[1].joinpath("server_ids", f"{_run._local_staging_file.name.split('.')[0]}.txt").unlink()
client = Client()
client.delete_folder(_folder_name, recursive=True, remove_runs=True)
@pytest.mark.api
@pytest.mark.online
def test_run_modification_online() -> None:
_uuid: str = f"{uuid.uuid4()}".split("-")[0]
_folder_name = f"/simvue_unit_testing/{_uuid}"
_folder = Folder.new(path=_folder_name)
_run = Run.new(folder=_folder_name)
_folder.commit()
_run.commit()
assert _run.folder == _folder_name
time.sleep(1)
_now = datetime.datetime.now()
_new_run = Run(identifier=_run.id)
assert _new_run.status == "created"
_new_run.read_only(False)
_new_run.status = "running"
_new_run.name = "simvue_test_run"
_new_run.description = "Simvue test run"
_new_run.tags = ["simvue", "test", "tag"]
_new_run.ttl = 120
assert _new_run.ttl != 120
_new_run.commit()
time.sleep(1)
assert _run.ttl == 120
assert _run.description == "Simvue test run"
assert sorted(_run.tags) == sorted(["simvue", "test", "tag"])
assert _run.name == "simvue_test_run"
assert _run.status == "running"
_run.abort("test_run_abort")
assert _new_run.abort_trigger
_run.delete()
_folder.delete(recursive=True, delete_runs=True, runs_only=False)
@pytest.mark.api
@pytest.mark.offline
def test_run_modification_offline(offline_cache_setup) -> None:
_uuid: str = f"{uuid.uuid4()}".split("-")[0]
_run_name = f"simvue_offline_run_{_uuid}"
_folder_name = f"/simvue_unit_testing/{_uuid}"
_folder = Folder.new(path=_folder_name, offline=True)
_run = Run.new(name=_run_name, folder=_folder_name, offline=True)
_folder.commit()
_run.commit()
assert _run.name == _run_name
assert _run.folder == _folder_name
time.sleep(1)
_new_run = Run(identifier=_run.id, offline=True)
# Property has not been committed to offline
# object so not yet available
with pytest.raises(AttributeError):
_new_run.ttl
_new_run.read_only(False)
_new_run.name = "simvue_test_run"
_new_run.description = "Simvue test run"
_new_run.ttl = 120
_new_run.commit()
assert _new_run.ttl == 120
assert _new_run.description == "Simvue test run"
assert _new_run.name == "simvue_test_run"
sender(_run._local_staging_file.parents[1], 1, 10, ["folders", "runs"])
time.sleep(1)
# Get online ID and retrieve run
_online_id = _run._local_staging_file.parents[1].joinpath("server_ids", f"{_run._local_staging_file.name.split('.')[0]}.txt").read_text()
_online_run = Run(_online_id)
assert _online_run.ttl == 120
assert _online_run.description == "Simvue test run"
assert _online_run.name == "simvue_test_run"
assert _online_run.folder == _folder_name
# Now add a new set of tags in offline mode and send
_new_run.tags = ["simvue", "test", "tag"]
_new_run.commit()
# Shouldn't yet be available in the online run since it hasnt been sent
_online_run.refresh()
assert _online_run.tags == []
sender(_run._local_staging_file.parents[1], 1, 10, ["folders", "runs"])
time.sleep(1)
_online_run.refresh()
assert sorted(_new_run.tags) == sorted(["simvue", "test", "tag"])
assert sorted(_online_run.tags) == sorted(["simvue", "test", "tag"])
_run.delete()
_run._local_staging_file.parents[1].joinpath("server_ids", f"{_run._local_staging_file.name.split('.')[0]}.txt").unlink()
client = Client()
client.delete_folder(_folder_name, recursive=True, remove_runs=True)
@pytest.mark.api
@pytest.mark.online
def test_get_run_count() -> None:
_uuid: str = f"{uuid.uuid4()}".split("-")[0]
_folder_name = f"/simvue_unit_testing/{_uuid}"
_folder = Folder.new(path=_folder_name)
_run_1 = Run.new(folder=_folder_name)
_run_2 = Run.new(folder=_folder_name)
assert len(list(Run.get(count=2, offset=None))) == 2
@pytest.mark.api
@pytest.mark.online
def test_run_get_properties() -> None:
_uuid: str = f"{uuid.uuid4()}".split("-")[0]
_folder_name = f"/simvue_unit_testing/{_uuid}"
_folder = Folder.new(path=_folder_name)
_run = Run.new(name="test_run_get_properties", folder=_folder_name)
_run.status = "running"
_run.ttl = 60
_folder.commit()
_run.commit()
_failed = []
assert _run.to_dict()
for member in _run._properties:
try:
getattr(_run, member)
except Exception as e:
_failed.append((member, f"{e}"))
with contextlib.suppress(Exception):
_run.delete()
_folder.delete()
if _failed:
raise AssertionError("\n" + "\n\t- ".join(": ".join(i) for i in _failed))
@pytest.mark.api
@pytest.mark.online
def test_batch_run_creation() -> None:
_uuid: str = f"{uuid.uuid4()}".split("-")[0]
_folder: Folder = Folder.new(path=f"/simvue_unit_testing/{_uuid}")
_folder.commit()
_runs = [
RunBatchArgs(name=f"batched_run_{i}")
for i in range(10)
]
_counter: int = 0
for i, _id in enumerate(Run.batch_create(entries=_runs, folder=f"/simvue_unit_testing/{_uuid}", metadata={"batch_id": 0})):
_run = Run(identifier=_id)
assert _run.name == f"batched_run_{i}"
assert _run.metadata["batch_id"] == 0
_counter +=1
assert _counter == 10
with contextlib.suppress(Exception):
_folder.delete(recursive=True, delete_runs=True)