Skip to content

Commit 65dfac4

Browse files
committed
Added deepmerge to dependencies and extra tests
1 parent 5a94ff9 commit 65dfac4

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

poetry.lock

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies = [
5353
"psutil (>=6.1.1,<7.0.0)",
5454
"tenacity (>=9.0.0,<10.0.0)",
5555
"typing-extensions (>=4.12.2,<5.0.0) ; python_version < \"3.11\"",
56+
"deepmerge (>=2.0,<3.0)",
5657
]
5758

5859
[project.urls]

simvue/api/objects/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import msgpack
1818
import pydantic
19+
from deepmerge import always_merger
1920

2021
from simvue.config.user import SimvueConfiguration
2122
from simvue.exception import ObjectNotFoundError
@@ -524,9 +525,10 @@ def _cache(self) -> None:
524525
with self._local_staging_file.open() as in_f:
525526
_local_data = json.load(in_f)
526527

527-
_local_data |= self._staging
528+
_cache_data = always_merger.merge(_local_data, self._staging)
529+
528530
with self._local_staging_file.open("w", encoding="utf-8") as out_f:
529-
json.dump(_local_data, out_f, indent=2)
531+
json.dump(_cache_data, out_f, indent=2)
530532

531533
def to_dict(self) -> dict[str, typing.Any]:
532534
return self._get() | self._staging

tests/functional/test_run_class.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,14 @@ def test_offline_tags(create_plain_run_offline: tuple[sv_run.Run, dict]) -> None
220220

221221
@pytest.mark.run
222222
def test_update_metadata_running(create_test_run: tuple[sv_run.Run, dict]) -> None:
223-
METADATA = {"a": 10, "b": 1.2, "c": "word"}
223+
METADATA = {"a": 1, "b": 1.2, "c": "word", "d": "new"}
224224
run, _ = create_test_run
225-
run.update_metadata(METADATA)
225+
# Add an initial set of metadata
226+
run.update_metadata({"a": 10, "b": 1.2, "c": "word"})
227+
# Try updating a second time, check original dict isnt overwritten
228+
run.update_metadata({"d": "new"})
229+
# Try updating an already defined piece of metadata
230+
run.update_metadata({"a": 1})
226231
run.close()
227232
time.sleep(1.0)
228233
client = sv_cl.Client()
@@ -234,9 +239,14 @@ def test_update_metadata_running(create_test_run: tuple[sv_run.Run, dict]) -> No
234239

235240
@pytest.mark.run
236241
def test_update_metadata_created(create_pending_run: tuple[sv_run.Run, dict]) -> None:
237-
METADATA = {"a": 10, "b": 1.2, "c": "word"}
242+
METADATA = {"a": 1, "b": 1.2, "c": "word", "d": "new"}
238243
run, _ = create_pending_run
239-
run.update_metadata(METADATA)
244+
# Add an initial set of metadata
245+
run.update_metadata({"a": 10, "b": 1.2, "c": "word"})
246+
# Try updating a second time, check original dict isnt overwritten
247+
run.update_metadata({"d": "new"})
248+
# Try updating an already defined piece of metadata
249+
run.update_metadata({"a": 1})
240250
time.sleep(1.0)
241251
client = sv_cl.Client()
242252
run_info = client.get_run(run.id)
@@ -250,13 +260,21 @@ def test_update_metadata_created(create_pending_run: tuple[sv_run.Run, dict]) ->
250260
def test_update_metadata_offline(
251261
create_plain_run_offline: tuple[sv_run.Run, dict],
252262
) -> None:
253-
METADATA = {"a": 10, "b": 1.2, "c": "word"}
263+
METADATA = {"a": 1, "b": 1.2, "c": "word", "d": "new"}
254264
run, _ = create_plain_run_offline
255265
run_name = run._name
256-
run.update_metadata(METADATA)
266+
# Add an initial set of metadata
267+
run.update_metadata({"a": 10, "b": 1.2, "c": "word"})
268+
# Try updating a second time, check original dict isnt overwritten
269+
run.update_metadata({"d": "new"})
270+
# Try updating an already defined piece of metadata
271+
run.update_metadata({"a": 1})
272+
257273
sv_send.sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10)
274+
import pdb; pdb.set_trace()
258275
run.close()
259276
time.sleep(1.0)
277+
import pdb; pdb.set_trace()
260278
client = sv_cl.Client()
261279
run_info = client.get_run(client.get_run_id_from_name(run_name))
262280

@@ -655,6 +673,29 @@ def test_update_tags_created(
655673
assert sorted(run_data.tags) == sorted(tags + ["additional"])
656674

657675

676+
@pytest.mark.offline
677+
@pytest.mark.run
678+
def test_update_tags_offline(
679+
create_plain_run_offline: typing.Tuple[sv_run.Run, dict],
680+
) -> None:
681+
simvue_run, _ = create_plain_run_offline
682+
run_name = simvue_run._name
683+
684+
simvue_run.set_tags(["simvue_client_unit_tests",])
685+
686+
simvue_run.update_tags(["additional"])
687+
688+
sv_send.sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10)
689+
simvue_run.close()
690+
time.sleep(1.0)
691+
692+
client = sv_cl.Client()
693+
run_data = client.get_run(client.get_run_id_from_name(run_name))
694+
695+
time.sleep(1)
696+
run_data = client.get_run(simvue_run._id)
697+
assert sorted(run_data.tags) == sorted(["simvue_client_unit_tests", "additional"])
698+
658699
@pytest.mark.run
659700
@pytest.mark.parametrize("object_type", ("DataFrame", "ndarray"))
660701
def test_save_object(

0 commit comments

Comments
 (0)