88"""
99from __future__ import annotations
1010
11- import logging
1211import pathlib
1312
13+ import distributed
1414import numpy
1515import pytest
1616
@@ -168,7 +168,7 @@ def test_view_update(
168168 dask_client , # pylint: disable=redefined-outer-name,unused-argument
169169 fs ,
170170 request ,
171- caplog ):
171+ tmpdir ):
172172 """Test the creation of a view."""
173173 tested_fs = request .getfixturevalue (fs )
174174
@@ -190,37 +190,49 @@ def test_view_update(
190190
191191 def to_zero (zds : dataset .Dataset , varname ):
192192 """Update function used to set a variable to 0."""
193- logging .info (log_msg )
194193 return {varname : zds .variables ['var1' ].values * 0 }
195194
196195 instance .update (to_zero , var_name ) # type: ignore
197196
198197 data = instance .load (delayed = False )
199198 assert numpy .all (data .variables [var_name ].values == 0 )
200199
200+ test_dir = tmpdir / 'test'
201+ test_dir .mkdir ()
202+
201203 def plus_one_with_log (zds : dataset .Dataset , varname ):
202- """Update function increasing a variable by 1."""
203- logging .info (log_msg )
204- return {varname : zds .variables [var_name ].values + 1 }
204+ """Update function increasing a variable by 1.
205+
206+ This update function create a new file each time its called.
207+ """
208+ with distributed .Lock ('update' ):
209+ i = 0
210+ f = test_dir / f'file_{ i } '
211+ while f .exists ():
212+ i += 1
213+ f = test_dir / f'file_{ i } '
205214
206- caplog .set_level (logging .INFO )
207- caplog .clear ()
215+ pathlib .Path (f ).touch ()
216+
217+ return {varname : zds .variables [var_name ].values + 1 }
208218
209219 instance .update (plus_one_with_log , var_name ) # type: ignore
210220
211221 # One log per partition + 1 log for the initial call
212- assert caplog .text .count (log_msg ) == len (list (instance .partitions ())) + 1
222+ assert len (test_dir .listdir ()) == len (list (instance .partitions ())) + 1
223+
224+ test_dir .remove ()
225+ test_dir .mkdir ()
213226
214227 data = instance .load (delayed = False )
215228 assert numpy .all (data .variables [var_name ].values == 1 )
216229
217- caplog .clear ()
218230 instance .update (
219231 plus_one_with_log , # type: ignore
220232 var_name ,
221233 variables = [var_name ])
222234
223- assert caplog . text . count ( log_msg ) == len (list (instance .partitions ()))
235+ assert len ( test_dir . listdir () ) == len (list (instance .partitions ()))
224236
225237 data = instance .load (delayed = False )
226238 assert numpy .all (data .variables [var_name ].values == 2 )
0 commit comments