@@ -639,12 +639,45 @@ def save_figure(self, item, fig, filename):
639639 filename = str (filename )
640640 compare = get_compare (item )
641641 savefig_kwargs = compare .kwargs .get ('savefig_kwargs' , {})
642- deterministic = compare .kwargs .get ('deterministic' , False )
642+ deterministic = compare .kwargs .get ('deterministic' , None )
643643
644644 original_source_date_epoch = os .environ .get ('SOURCE_DATE_EPOCH' , None )
645645
646646 extra_rcparams = {}
647647
648+ ext = self ._file_extension (item )
649+
650+ if deterministic is None :
651+
652+ # The deterministic option should only matter for hash-based tests,
653+ # so we first check if a hash library is being used
654+
655+ if self .hash_library or compare .kwargs .get ('hash_library' , None ):
656+
657+ if ext == 'png' :
658+ if 'metadata' not in savefig_kwargs or 'Software' not in savefig_kwargs ['metadata' ]:
659+ warnings .warn ("deterministic option not set (currently defaulting to False), "
660+ "in future this will default to True to give consistent "
661+ "hashes across Matplotlib versions. To suppress this warning, "
662+ "set deterministic to True if you are happy with the future "
663+ "behavior or to False if you want to preserve the old behavior." ,
664+ FutureWarning )
665+ else :
666+ # Set to False but in practice because Software is set to a constant value
667+ # by the caller, the output will be deterministic (we don't want to change
668+ # Software to None if the caller set it to e.g. 'test')
669+ deterministic = False
670+ else :
671+ deterministic = True
672+
673+ else :
674+
675+ # We can just default to True since it shouldn't matter and in
676+ # case generated images are somehow used in future to compute
677+ # hashes
678+
679+ deterministic = True
680+
648681 if deterministic :
649682
650683 # Make sure we don't modify the original dictionary in case is a common
@@ -654,8 +687,6 @@ def save_figure(self, item, fig, filename):
654687 if 'metadata' not in savefig_kwargs :
655688 savefig_kwargs ['metadata' ] = {}
656689
657- ext = self ._file_extension (item )
658-
659690 if ext == 'png' :
660691 extra_metadata = {"Software" : None }
661692 elif ext == 'pdf' :
0 commit comments