Skip to content

Commit 88bdd86

Browse files
authored
Merge pull request #758 from simvue-io/dev
2.0.0 release
2 parents 68d5fdb + 74ce7ee commit 88bdd86

File tree

6 files changed

+132
-85
lines changed

6 files changed

+132
-85
lines changed

simvue/api/objects/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ def delete(
479479
if self._offline:
480480
return {"id": self._identifier}
481481

482+
if not self._identifier:
483+
raise RuntimeError(f"Object of type '{self._label}' has no identifier.")
484+
482485
if not self.url:
483486
raise RuntimeError(f"Identifier for instance of {self._label} Unknown")
484487
_response = sv_delete(url=f"{self.url}", headers=self._headers, params=kwargs)

simvue/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ def save_object(
13601360
allow_pickling=allow_pickle,
13611361
storage=self._storage_id,
13621362
metadata=metadata,
1363+
offline=self._user_config.run.mode == "offline",
13631364
)
13641365
_artifact.attach_to_run(self.id, category)
13651366
except (ValueError, RuntimeError) as e:

simvue/utilities.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ def parse_validation_response(
9292

9393
out: list[list[str]] = []
9494

95+
if isinstance(issues, str):
96+
return tabulate.tabulate(
97+
["Unknown", "N/A", issues],
98+
headers=["Type", "Location", "Message"],
99+
tablefmt="fancy_grid",
100+
)
101+
95102
for issue in issues:
96103
obj_type: str = issue["type"]
97104
location: list[str] = issue["loc"]

tests/conftest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def create_test_run(request) -> typing.Generator[typing.Tuple[sv_run.Run, dict],
7171

7272
@pytest.fixture
7373
def create_test_run_offline(mocker: pytest_mock.MockerFixture, request, monkeypatch: pytest.MonkeyPatch) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
74+
def testing_exit(status: int) -> None:
75+
raise SystemExit(status)
76+
mocker.patch("os._exit", testing_exit)
7477
with tempfile.TemporaryDirectory() as temp_d:
7578
monkeypatch.setenv("SIMVUE_OFFLINE_DIRECTORY", temp_d)
7679
with sv_run.Run("offline") as run:
@@ -79,7 +82,10 @@ def create_test_run_offline(mocker: pytest_mock.MockerFixture, request, monkeypa
7982

8083

8184
@pytest.fixture
82-
def create_plain_run(request) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
85+
def create_plain_run(request, mocker: pytest_mock.MockFixture) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
86+
def testing_exit(status: int) -> None:
87+
raise SystemExit(status)
88+
mocker.patch("os._exit", testing_exit)
8389
with sv_run.Run() as run:
8490
yield run, setup_test_run(run, False, request)
8591
clear_out_files()
@@ -102,7 +108,10 @@ def create_plain_run_offline(mocker: pytest_mock.MockerFixture, request, monkeyp
102108

103109

104110
@pytest.fixture
105-
def create_run_object() -> sv_api_obj.Run:
111+
def create_run_object(mocker: pytest_mock.MockFixture) -> sv_api_obj.Run:
112+
def testing_exit(status: int) -> None:
113+
raise SystemExit(status)
114+
mocker.patch("os._exit", testing_exit)
106115
_fix_use_id: str = str(uuid.uuid4()).split('-', 1)[0]
107116
_folder = sv_api_obj.Folder.new(path=f"/simvue_unit_testing/{_fix_use_id}")
108117
_folder.commit()
@@ -114,22 +123,24 @@ def create_run_object() -> sv_api_obj.Run:
114123

115124
def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.FixtureRequest, created_only: bool=False):
116125
fix_use_id: str = str(uuid.uuid4()).split('-', 1)[0]
126+
_test_name: str = request.node.name.replace("[", "_").replace("]", "")
117127
TEST_DATA = {
118128
"event_contains": "sent event",
119129
"metadata": {
120130
"test_engine": "pytest",
121-
"test_identifier": fix_use_id
131+
"test_identifier": f"{_test_name}_{fix_use_id}"
122132
},
123133
"folder": f"/simvue_unit_testing/{fix_use_id}",
124-
"tags": ["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "")]
134+
"tags": ["simvue_client_unit_tests", _test_name]
125135
}
126136

127137
if os.environ.get("CI"):
128138
TEST_DATA["tags"].append("ci")
129139

130140
run.config(suppress_errors=False)
141+
run._heartbeat_interval = 1
131142
run.init(
132-
name=f"test_run_{TEST_DATA['metadata']['test_identifier']}_{uuid.uuid4()}",
143+
name=TEST_DATA['metadata']['test_identifier'],
133144
tags=TEST_DATA["tags"],
134145
folder=TEST_DATA["folder"],
135146
visibility="tenant" if os.environ.get("CI") else None,

tests/functional/test_client.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import glob
88
import pathlib
99
import time
10+
import pytest_mock
1011
import tempfile
1112
import simvue.client as svc
1213
from simvue.exception import ObjectNotFoundError
@@ -383,19 +384,14 @@ def test_alert_deletion() -> None:
383384

384385

385386
@pytest.mark.client
386-
def test_abort_run() -> None:
387+
def test_abort_run(create_plain_run: tuple[sv_run.Run, dict]) -> None:
388+
run, run_data = create_plain_run
387389
_uuid = f"{uuid.uuid4()}".split("-")[0]
388-
_folder = sv_api_obj.Folder.new(path=f"/simvue_unit_testing/{_uuid}")
389-
_run = sv_api_obj.Run.new(folder=f"/simvue_unit_testing/{_uuid}")
390-
_run.status = "running"
391-
_folder.commit()
392-
_run.commit()
390+
run.update_tags([f"delete_me_{_uuid}"])
393391
time.sleep(1)
394392
_client = svc.Client()
395-
_client.abort_run(_run.id, reason="Test abort")
393+
_client.abort_run(run.id, reason="Test abort")
396394
time.sleep(1)
397-
assert _run.abort_trigger
398-
_run.delete()
399-
_folder.delete(recursive=True, delete_runs=True, runs_only=False)
395+
assert run._status == "terminated"
400396

401397

0 commit comments

Comments
 (0)