@@ -551,12 +551,45 @@ def save_figure(self, item, fig, filename):
551
551
filename = str (filename )
552
552
compare = get_compare (item )
553
553
savefig_kwargs = compare .kwargs .get ('savefig_kwargs' , {})
554
- deterministic = compare .kwargs .get ('deterministic' , False )
554
+ deterministic = compare .kwargs .get ('deterministic' , None )
555
555
556
556
original_source_date_epoch = os .environ .get ('SOURCE_DATE_EPOCH' , None )
557
557
558
558
extra_rcparams = {}
559
559
560
+ ext = self ._file_extension (item )
561
+
562
+ if deterministic is None :
563
+
564
+ # The deterministic option should only matter for hash-based tests,
565
+ # so we first check if a hash library is being used
566
+
567
+ if self .hash_library or compare .kwargs .get ('hash_library' , None ):
568
+
569
+ if ext == 'png' :
570
+ if 'metadata' not in savefig_kwargs or 'Software' not in savefig_kwargs ['metadata' ]:
571
+ warnings .warn ("deterministic option not set (currently defaulting to False), "
572
+ "in future this will default to True to give consistent "
573
+ "hashes across Matplotlib versions. To suppress this warning, "
574
+ "set deterministic to True if you are happy with the future "
575
+ "behavior or to False if you want to preserve the old behavior." ,
576
+ FutureWarning )
577
+ else :
578
+ # Set to False but in practice because Software is set to a constant value
579
+ # by the caller, the output will be deterministic (we don't want to change
580
+ # Software to None if the caller set it to e.g. 'test')
581
+ deterministic = False
582
+ else :
583
+ deterministic = True
584
+
585
+ else :
586
+
587
+ # We can just default to True since it shouldn't matter and in
588
+ # case generated images are somehow used in future to compute
589
+ # hashes
590
+
591
+ deterministic = True
592
+
560
593
if deterministic :
561
594
562
595
# Make sure we don't modify the original dictionary in case is a common
@@ -566,8 +599,6 @@ def save_figure(self, item, fig, filename):
566
599
if 'metadata' not in savefig_kwargs :
567
600
savefig_kwargs ['metadata' ] = {}
568
601
569
- ext = self ._file_extension (item )
570
-
571
602
if ext == 'png' :
572
603
extra_metadata = {"Software" : None }
573
604
elif ext == 'pdf' :
0 commit comments