@@ -1404,23 +1404,12 @@ def test_refresh_from_disk(self) -> None:
1404
1404
a .close ()
1405
1405
b .close ()
1406
1406
1407
- def test_byte_attrs (self ) -> None :
1408
- with create_tmp_file () as tmp_file :
1409
- try :
1410
- null_byte = b"\x00 "
1411
- other_bytes = bytes (range (1 , 256 ))
1412
- ds = Dataset ({"x" : 1 }, coords = {"x_coord" : [1 ]})
1413
- ds ["x" ].attrs ["null_byte" ] = null_byte
1414
- ds ["x" ].attrs ["other_bytes" ] = other_bytes
1415
- self .save (ds , tmp_file )
1416
- except ValueError :
1417
- assert self .engine == "h5netcdf"
1418
- else :
1419
- with self .open (tmp_file ) as ds_out :
1420
- assert ds_out ["x" ].attrs ["null_byte" ] == ""
1421
- assert ds_out ["x" ].attrs ["other_bytes" ] == other_bytes .decode (
1422
- errors = "replace"
1423
- )
1407
+ def test_byte_attrs (self , byte_attrs_dataset : dict [str , Any ]) -> None :
1408
+ # test for issue #9407
1409
+ input = byte_attrs_dataset ["input" ]
1410
+ expected = byte_attrs_dataset ["expected" ]
1411
+ with self .roundtrip (input ) as actual :
1412
+ assert_identical (actual , expected )
1424
1413
1425
1414
1426
1415
_counter = itertools .count ()
@@ -3879,6 +3868,10 @@ def test_decode_utf8_warning(self) -> None:
3879
3868
assert ds .title == title
3880
3869
assert "attribute 'title' of h5netcdf object '/'" in str (w [0 ].message )
3881
3870
3871
+ def test_byte_attrs (self , byte_attrs_dataset : dict [str , Any ]) -> None :
3872
+ with pytest .raises (ValueError , match = byte_attrs_dataset ["h5netcdf_error" ]):
3873
+ super ().test_byte_attrs (byte_attrs_dataset )
3874
+
3882
3875
3883
3876
@requires_h5netcdf
3884
3877
@requires_netCDF4
0 commit comments