@@ -41,6 +41,7 @@ def test_create_variable(
4141
4242 assert all (test_dataset [group_name ]["first_var" ][:]) == all (xs )
4343 assert len (test_dataset [group_name ]["first_var" ][:]) == len (xs )
44+ test_dataset .close ()
4445
4546
4647@pytest .mark .netcdf
@@ -56,6 +57,7 @@ def test_creat_variable_already_exists_should_fail(
5657 create_variable_in_group (
5758 test_dataset [group_name ], "first_var" , xs , "f"
5859 )
60+ test_dataset .close ()
5961
6062
6163@pytest .mark .netcdf
@@ -78,6 +80,7 @@ def test_create_1d_variables(
7880 assert len (test_dataset [group_name ]["sin1" ][:]) == len (xs )
7981 assert all (test_dataset [group_name ]["cos1" ][:]) == all (coss )
8082 assert len (test_dataset [group_name ]["cos1" ][:]) == len (xs )
83+ test_dataset .close ()
8184
8285
8386@pytest .mark .parametrize (
@@ -110,6 +113,7 @@ def test_create_1d_variables_already_exists_should_fail(
110113 ["f" , "f" ],
111114 variable_xname = args [0 ],
112115 )
116+ test_dataset .close ()
113117
114118
115119def test_create_3d_variable (
@@ -139,6 +143,7 @@ def test_create_3d_variable(
139143 assert var [0 ] in test_dataset [group_name ].variables .keys ()
140144 assert all (test_dataset [group_name ][var [0 ]][:]) == all (vars ()[var [1 ]])
141145 assert test_dataset [group_name ]["data" ][:].shape == (nx , ny , nz )
146+ test_dataset .close ()
142147
143148
144149@pytest .mark .netcdf
@@ -186,6 +191,7 @@ def test_create_3d_variable_already_exist_should_fail(
186191 variable_yname = args [2 ],
187192 variable_zname = args [3 ],
188193 )
194+ test_dataset .close ()
189195
190196
191197def test_create_2d_variables (
@@ -213,6 +219,7 @@ def test_create_2d_variables(
213219 assert var [0 ] in test_dataset [group_name ].variables .keys ()
214220 assert all (test_dataset [group_name ][var [0 ]][:]) == all (vars ()[var [1 ]])
215221 assert test_dataset [group_name ]["data" ][:].shape == (nx , ny )
222+ test_dataset .close ()
216223
217224
218225@pytest .mark .netcdf
@@ -255,6 +262,7 @@ def test_create_2d_variables_already_exist_should_fail(
255262 variable_xname = args [1 ],
256263 variable_yname = args [2 ],
257264 )
265+ test_dataset .close ()
258266
259267
260268@pytest .mark .netcdf
@@ -271,6 +279,7 @@ def test_create_nested_groups(
271279 for grp in groups :
272280 assert grp in new_dts .groups .keys ()
273281 new_dts = new_dts [grp ]
282+ test_dataset .close ()
274283
275284
276285@pytest .mark .xfail (reason = "read_array function not yet implemented" )
@@ -328,17 +337,19 @@ def test_write_array(
328337 )
329338
330339 netCDF_file = netCDF4 .Dataset (netcdf_handle ["path" ], "r" , format = "NETCDF4" )
340+ new_netCDF_file = netCDF_file
331341 groups = [grp for grp in args [0 ].split ("/" ) if grp != "" ]
332342 for group in groups :
333343 current = group
334- netCDF_file = netCDF_file [current ]
335- assert netCDF_file [array_name ].name == array_name
336- assert netCDF_file [array_name ].title == args [1 ]
337- assert netCDF_file [array_name ].units == "m"
344+ new_netCDF_file = new_netCDF_file [current ]
345+ assert new_netCDF_file [array_name ].name == array_name
346+ assert new_netCDF_file [array_name ].title == args [1 ]
347+ assert new_netCDF_file [array_name ].units == "m"
338348
339- assert len (netCDF_file [array_name ].ncattrs ()) == 5
349+ assert len (new_netCDF_file [array_name ].ncattrs ()) == 5
340350
341351 assert isinstance (handle , dict )
352+ netCDF_file .close ()
342353 # following code is to test what happens when you call write again with same parameters, execpt one (kg instead of m). array is updated.
343354 netcdf_handle = pipeline .write_array (
344355 data ** 2 ,
@@ -354,17 +365,19 @@ def test_write_array(
354365 array_name = array_name ,
355366 )
356367 netCDF_file = netCDF4 .Dataset (netcdf_handle ["path" ], "r" , format = "NETCDF4" )
368+ new_netCDF_file = netCDF_file
357369 groups = [grp for grp in args [0 ].split ("/" ) if grp != "" ]
358370 for group in groups :
359371 current = group
360- netCDF_file = netCDF_file [current ]
361- assert netCDF_file [array_name ].name == array_name
362- assert netCDF_file [array_name ].title == args [1 ]
363- assert netCDF_file [array_name ].units == "kg"
364- assert np .isclose (data , np .sqrt (netCDF_file [array_name ][:]).data ).all ()
365- assert len (netCDF_file [array_name ].ncattrs ()) == 5
372+ new_netCDF_file = new_netCDF_file [current ]
373+ assert new_netCDF_file [array_name ].name == array_name
374+ assert new_netCDF_file [array_name ].title == args [1 ]
375+ assert new_netCDF_file [array_name ].units == "kg"
376+ assert np .isclose (data , np .sqrt (new_netCDF_file [array_name ][:]).data ).all ()
377+ assert len (new_netCDF_file [array_name ].ncattrs ()) == 5
366378
367379 assert isinstance (handle , dict )
380+ netCDF_file .close ()
368381
369382
370383@pytest .mark .netcdf
@@ -401,6 +414,7 @@ def test_set_attribute(
401414 )
402415 assert "test_attribute" in test_dataset [group_name ]["data" ].ncattrs ()
403416 assert len (test_dataset [group_name ]["data" ].test_attribute ) == 10
417+ test_dataset .close ()
404418
405419
406420@pytest .mark .netcdf
@@ -442,6 +456,7 @@ def test_set_attribute_already_exists(
442456 )
443457 assert "test_attribute" in test_dataset [group_name ]["data" ].ncattrs ()
444458 assert len (test_dataset [group_name ]["data" ].test_attribute ) == 5
459+ test_dataset .close ()
445460
446461
447462@pytest .mark .netcdf
@@ -475,6 +490,7 @@ def test_create_nd_variables_in_group_w_attribute(
475490 assert test_dataset [group_name ]["data3d" ].units == "Unknown"
476491 assert test_dataset [group_name ]["data3d" ].title == "Unknown"
477492 assert len (test_dataset [group_name ]["data3d_3" ].ncattrs ()) == 6
493+ test_dataset .close ()
478494
479495
480496@pytest .mark .netcdf
@@ -502,6 +518,7 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail1(
502518 other_attribute_names = ["a novel way to be me" ],
503519 other_attribute_data = ["lallero" ],
504520 )
521+ test_dataset .close ()
505522
506523
507524@pytest .mark .netcdf
@@ -529,6 +546,7 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail2(
529546 other_attribute_names = ["a novel way to be me" ],
530547 other_attribute_data = ["lallero" ],
531548 )
549+ test_dataset .close ()
532550
533551
534552@pytest .mark .netcdf
@@ -556,6 +574,7 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail3(
556574 other_attribute_names = ["a novel way to be me" ],
557575 other_attribute_data = ["lallero" ],
558576 )
577+ test_dataset .close ()
559578
560579
561580@pytest .mark .netcdf
@@ -583,6 +602,7 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail4(
583602 other_attribute_names = ["a novel way to be me" ],
584603 other_attribute_data = ["lallero" ],
585604 )
605+ test_dataset .close ()
586606
587607
588608@pytest .mark .netcdf
@@ -611,6 +631,7 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail5(
611631 other_attribute_names = ["a novel way to be me" ],
612632 other_attribute_data = ["lallero" ],
613633 )
634+ test_dataset .close ()
614635
615636
616637@pytest .mark .netcdf
@@ -651,6 +672,7 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail6(
651672 other_attribute_names = ["a novel way to be me" ],
652673 other_attribute_data = ["lallero" ],
653674 )
675+ test_dataset .close ()
654676
655677
656678@pytest .mark .netcdf
@@ -691,6 +713,7 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail7(
691713 other_attribute_names = ["a novel way to be me" ],
692714 other_attribute_data = ["lallero" ],
693715 )
716+ test_dataset .close ()
694717
695718
696719@pytest .mark .netcdf
@@ -718,3 +741,4 @@ def test_create_nd_variables_in_group_w_attribute_shouldfail8(
718741 other_attribute_names = ["a novel way to be me" ],
719742 other_attribute_data = ["lallero" , "seciao" ],
720743 )
744+ test_dataset .close ()
0 commit comments