1010from simvue .api .objects .folder import Folder
1111from simvue .sender import sender
1212from simvue .client import Client
13+ import logging
1314
1415@pytest .mark .api
1516@pytest .mark .online
16- def test_file_artifact_creation_online () -> None :
17+ @pytest .mark .parametrize (
18+ "snapshot" ,
19+ (True , False )
20+ )
21+ def test_file_artifact_creation_online (offline_cache_setup , snapshot ) -> None :
1722 _uuid : str = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
1823 _folder_name = f"/simvue_unit_testing/{ _uuid } "
1924 _folder = Folder .new (path = _folder_name )
@@ -32,7 +37,8 @@ def test_file_artifact_creation_online() -> None:
3237 file_path = _path ,
3338 storage = None ,
3439 mime_type = None ,
35- metadata = None
40+ metadata = None ,
41+ snapshot = snapshot
3642 )
3743 _artifact .attach_to_run (_run .id , "input" )
3844 time .sleep (1 )
@@ -45,6 +51,11 @@ def test_file_artifact_creation_online() -> None:
4551 _content = b"" .join (_artifact .download_content ()).decode ("UTF-8" )
4652 assert _content == f"Hello World! { _uuid } "
4753 assert _artifact .to_dict ()
54+
55+ # If snapshotting, check no local copy remains
56+ if snapshot :
57+ assert len (list (_artifact ._local_staging_file .parent .iterdir ())) == 0
58+
4859 _run .delete ()
4960 _folder .delete (recursive = True , delete_runs = True , runs_only = False )
5061 with contextlib .suppress (FileNotFoundError ):
@@ -55,7 +66,11 @@ def test_file_artifact_creation_online() -> None:
5566
5667@pytest .mark .api
5768@pytest .mark .offline
58- def test_file_artifact_creation_offline (offline_cache_setup ) -> None :
69+ @pytest .mark .parametrize (
70+ "snapshot" ,
71+ (True , False )
72+ )
73+ def test_file_artifact_creation_offline (offline_cache_setup , snapshot ) -> None :
5974 _uuid : str = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
6075 _folder_name = f"/simvue_unit_testing/{ _uuid } "
6176 _folder = Folder .new (path = _folder_name , offline = True )
@@ -74,7 +89,8 @@ def test_file_artifact_creation_offline(offline_cache_setup) -> None:
7489 storage = None ,
7590 mime_type = None ,
7691 offline = True ,
77- metadata = None
92+ metadata = None ,
93+ snapshot = snapshot
7894 )
7995 _artifact .attach_to_run (_run ._identifier , category = "input" )
8096
@@ -84,9 +100,15 @@ def test_file_artifact_creation_offline(offline_cache_setup) -> None:
84100 assert _local_data .get ("name" ) == f"test_file_artifact_{ _uuid } "
85101 assert _local_data .get ("runs" ) == {_run ._identifier : "input" }
86102
103+ # If snapshot, check artifact definition file and a copy of the actual file exist in staging area
104+ assert len (list (_artifact ._local_staging_file .parent .iterdir ())) == 2 if snapshot else 1
105+
87106 _id_mapping = sender (pathlib .Path (offline_cache_setup .name ), 1 , 10 )
88107 time .sleep (1 )
89108
109+ # Check file(s) deleted after upload
110+ assert len (list (_artifact ._local_staging_file .parent .iterdir ())) == 0
111+
90112 _online_artifact = Artifact (_id_mapping [_artifact .id ])
91113 assert _online_artifact .name == _artifact .name
92114 _content = b"" .join (_online_artifact .download_content ()).decode ("UTF-8" )
@@ -101,11 +123,11 @@ def test_file_artifact_creation_offline(offline_cache_setup) -> None:
101123 "snapshot" ,
102124 (True , False )
103125)
104- def test_file_artifact_creation_offline_snapshot (offline_cache_setup , snapshot ) -> None :
126+ def test_file_artifact_creation_offline_updated (offline_cache_setup , caplog , snapshot ) -> None :
105127 _uuid : str = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
106128 _folder_name = f"/simvue_unit_testing/{ _uuid } "
107129 _folder = Folder .new (path = _folder_name , offline = True )
108- _run = Run .new (name = f"test_file_artifact_creation_offline_snapshot_ { _uuid } " ,folder = _folder_name , offline = True )
130+ _run = Run .new (name = f"test_file_artifact_creation_offline_updated_ { _uuid } " ,folder = _folder_name , offline = True )
109131
110132 _path = pathlib .Path (offline_cache_setup .name ).joinpath ("hello_world.txt" )
111133
@@ -136,8 +158,9 @@ def test_file_artifact_creation_offline_snapshot(offline_cache_setup, snapshot)
136158 out_f .write ("File changed!" )
137159
138160 if not snapshot :
139- with pytest . raises ( RuntimeError ): # TODO: Make sender be resilient to this?
161+ with caplog . at_level ( logging . ERROR ):
140162 _id_mapping = sender (pathlib .Path (offline_cache_setup .name ), 1 , 10 )
163+ assert "The SHA256 you specified did not match the calculated checksum." in caplog .text
141164 return
142165 else :
143166 _id_mapping = sender (pathlib .Path (offline_cache_setup .name ), 1 , 10 )
0 commit comments