@@ -55,6 +55,16 @@ def mdat(d1):
5555 return op2 .MixedDat ([d1 , d1 ])
5656
5757
58+ @pytest .fixture (scope = 'module' )
59+ def s2 (s ):
60+ return op2 .DataSet (s , 2 )
61+
62+
63+ @pytest .fixture
64+ def vdat (s2 ):
65+ return op2 .Dat (s2 , np .zeros (2 * nelems ), dtype = np .float64 )
66+
67+
5868class TestDat :
5969
6070 """
@@ -254,6 +264,60 @@ def test_accessing_data_with_halos_increments_dat_version(self, d1):
254264 assert d1 .dat_version == 1
255265
256266
267+ class TestDatView ():
268+
269+ def test_dat_view_assign (self , vdat ):
270+ vdat .data [:, 0 ] = 3
271+ vdat .data [:, 1 ] = 4
272+ comp = op2 .DatView (vdat , 1 )
273+ comp .data [:] = 7
274+ assert not vdat .halo_valid
275+ assert not comp .halo_valid
276+
277+ expected = np .zeros_like (vdat .data )
278+ expected [:, 0 ] = 3
279+ expected [:, 1 ] = 7
280+ assert all (comp .data == expected [:, 1 ])
281+ assert all (vdat .data [:, 0 ] == expected [:, 0 ])
282+ assert all (vdat .data [:, 1 ] == expected [:, 1 ])
283+
284+ def test_dat_view_zero (self , vdat ):
285+ vdat .data [:, 0 ] = 3
286+ vdat .data [:, 1 ] = 4
287+ comp = op2 .DatView (vdat , 1 )
288+ comp .zero ()
289+ assert vdat .halo_valid
290+ assert comp .halo_valid
291+
292+ expected = np .zeros_like (vdat .data )
293+ expected [:, 0 ] = 3
294+ expected [:, 1 ] = 0
295+ assert all (comp .data == expected [:, 1 ])
296+ assert all (vdat .data [:, 0 ] == expected [:, 0 ])
297+ assert all (vdat .data [:, 1 ] == expected [:, 1 ])
298+
299+ def test_dat_view_halo_valid (self , vdat ):
300+ """Check halo validity for DatView"""
301+ comp = op2 .DatView (vdat , 1 )
302+ assert vdat .halo_valid
303+ assert comp .halo_valid
304+ assert vdat .dat_version == 0
305+ assert comp .dat_version == 0
306+
307+ comp .data_ro_with_halos
308+ assert vdat .halo_valid
309+ assert comp .halo_valid
310+ assert vdat .dat_version == 0
311+ assert comp .dat_version == 0
312+
313+ # accessing comp.data_with_halos should mark the parent halo as dirty
314+ comp .data_with_halos
315+ assert not vdat .halo_valid
316+ assert not comp .halo_valid
317+ assert vdat .dat_version == 1
318+ assert comp .dat_version == 1
319+
320+
257321if __name__ == '__main__' :
258322 import os
259323 pytest .main (os .path .abspath (__file__ ))
0 commit comments