@@ -383,3 +383,35 @@ def test_copy_on_init():
383
383
hdr .image_defs ['image pixel size' ] = 8
384
384
assert_array_equal (hdr .image_defs ['image pixel size' ], 8 )
385
385
assert_array_equal (HDR_DEFS ['image pixel size' ], 16 )
386
+
387
+
388
+ def assert_arr_dict_equal (dict1 , dict2 ):
389
+ assert_equal (set (dict1 ), set (dict2 ))
390
+ for key , value1 in dict1 .items ():
391
+ value2 = dict2 [key ]
392
+ assert_array_equal (value1 , value2 )
393
+
394
+
395
+ def test_header_copy ():
396
+ # Test header copying
397
+ hdr = PARRECHeader (HDR_INFO , HDR_DEFS )
398
+ hdr2 = hdr .copy ()
399
+
400
+ def assert_copy_ok (hdr1 , hdr2 ):
401
+ assert_false (hdr1 is hdr2 )
402
+ assert_equal (hdr1 .permit_truncated , hdr2 .permit_truncated )
403
+ assert_false (hdr1 .general_info is hdr2 .general_info )
404
+ assert_arr_dict_equal (hdr1 .general_info , hdr2 .general_info )
405
+ assert_false (hdr1 .image_defs is hdr2 .image_defs )
406
+ assert_array_equal (hdr1 .image_defs , hdr2 .image_defs )
407
+
408
+ assert_copy_ok (hdr , hdr2 )
409
+ assert_false (hdr .permit_truncated )
410
+ assert_false (hdr2 .permit_truncated )
411
+ with open (TRUNC_PAR , 'rt' ) as fobj :
412
+ assert_raises (PARRECError , PARRECHeader .from_fileobj , fobj )
413
+ with open (TRUNC_PAR , 'rt' ) as fobj :
414
+ trunc_hdr = PARRECHeader .from_fileobj (fobj , True )
415
+ assert_true (trunc_hdr .permit_truncated )
416
+ trunc_hdr2 = trunc_hdr .copy ()
417
+ assert_copy_ok (trunc_hdr , trunc_hdr2 )
0 commit comments