@@ -119,11 +119,8 @@ async def test_multiple_input_file_formats_cause_error(input_test_configuration:
119119
120120 # Create two input files in the KVS directory
121121 kvs_path = Path (input_test_configuration .storage_dir ) / 'key_value_stores' / 'default'
122- with open (kvs_path / f'{ input_test_configuration .input_key } ' , 'wb' ) as f : # noqa: ASYNC230 # It is ok for a test to use sync I/O
123- f .write (EXAMPLE_BYTES_INPUT )
124-
125- with open (kvs_path / f'{ input_test_configuration .input_key } .json' , 'w' , encoding = 'utf-8' ) as f : # noqa: ASYNC230 # It is ok for a test to use sync I/O
126- f .write (EXAMPLE_JSON_INPUT )
122+ (kvs_path / f'{ input_test_configuration .input_key } ' ).write_bytes (EXAMPLE_BYTES_INPUT )
123+ (kvs_path / f'{ input_test_configuration .input_key } .json' ).write_text (EXAMPLE_JSON_INPUT )
127124
128125 with pytest .raises (RuntimeError , match = r'Only one input file is allowed. Following input files found: .*' ):
129126 await KeyValueStore .open (
@@ -138,8 +135,7 @@ async def test_txt_input_missing_metadata(input_test_configuration: Configuratio
138135 # Create custom key file without metadata in the KVS directory
139136 kvs_path = Path (input_test_configuration .storage_dir ) / 'key_value_stores' / 'default'
140137 input_file = kvs_path / f'{ input_test_configuration .input_key } .txt'
141- with open (input_file , 'w' , encoding = 'utf-8' ) as f : # noqa: ASYNC230 # It is ok for a test to use sync I/O
142- f .write (EXAMPLE_TXT_INPUT )
138+ input_file .write_text (EXAMPLE_TXT_INPUT )
143139 last_modified = input_file .stat ().st_mtime
144140
145141 # Make sure that filesystem has enough time to detect changes
@@ -159,8 +155,7 @@ async def test_json_input_missing_metadata(input_test_configuration: Configurati
159155 # Create custom key file without metadata in the KVS directory
160156 kvs_path = Path (input_test_configuration .storage_dir ) / 'key_value_stores' / 'default'
161157 input_file = kvs_path / f'{ input_test_configuration .input_key } { suffix } '
162- with open (input_file , 'w' , encoding = 'utf-8' ) as f : # noqa: ASYNC230 # It is ok for a test to use sync I/O
163- f .write (EXAMPLE_JSON_INPUT )
158+ input_file .write_text (EXAMPLE_JSON_INPUT )
164159 last_modified = input_file .stat ().st_mtime
165160
166161 # Make sure that filesystem has enough time to detect changes
@@ -180,8 +175,7 @@ async def test_bytes_input_missing_metadata(input_test_configuration: Configurat
180175 # Create custom key file without metadata in the KVS directory
181176 kvs_path = Path (input_test_configuration .storage_dir ) / 'key_value_stores' / 'default'
182177 input_file = kvs_path / f'{ input_test_configuration .input_key } { suffix } '
183- with open (input_file , 'wb' ) as f : # noqa: ASYNC230 # It is ok for a test to use sync I/O
184- f .write (EXAMPLE_BYTES_INPUT )
178+ input_file .write_bytes (EXAMPLE_BYTES_INPUT )
185179 last_modified = input_file .stat ().st_mtime
186180
187181 # Make sure that filesystem has enough time to detect changes
@@ -192,3 +186,19 @@ async def test_bytes_input_missing_metadata(input_test_configuration: Configurat
192186 )
193187 assert await kvs .get_value (input_test_configuration .input_key ) == EXAMPLE_BYTES_INPUT
194188 assert last_modified == input_file .stat ().st_mtime , 'File was modified or recreated.'
189+
190+
191+ async def test_pre_existing_input_not_deleted_in_actor_context (input_test_configuration : Configuration ) -> None :
192+ """Test that pre-existing INPUT file is never deleted as long as the Actor context was started first."""
193+
194+ # Create custom key file without metadata in the KVS directory
195+ kvs_path = Path (input_test_configuration .storage_dir ) / 'key_value_stores' / 'default'
196+ input_file = kvs_path / f'{ input_test_configuration .input_key } '
197+ input_file .write_bytes (EXAMPLE_BYTES_INPUT )
198+
199+ async with Actor (configuration = input_test_configuration ):
200+ # Storage client that is not aware of the input file and could delete it during purge.
201+ storage_client = FileSystemStorageClient ()
202+ # Unless already implicitly opened by Actor, the input file would be deleted.
203+ await KeyValueStore .open (storage_client = storage_client , configuration = input_test_configuration )
204+ assert await Actor .get_input () == EXAMPLE_BYTES_INPUT
0 commit comments