99from unittest .mock import patch
1010
1111import bilby
12- from bilby .core .result import ResultError
12+ from bilby .core .result import ResultError , FileLoadError
1313from bilby .core .utils import logger
1414
1515
@@ -602,6 +602,8 @@ class NotAResult(bilby.core.result.Result):
602602 # result should be specified result_class
603603 assert isinstance (result , NotAResult )
604604
605+ # TODO: figure out why the caching message is not logged
606+ # with self.assertLogs(logger, "INFO") as cm:
605607 cached_result = bilby .run_sampler (
606608 likelihood ,
607609 priors ,
@@ -614,6 +616,7 @@ class NotAResult(bilby.core.result.Result):
614616 check_point_plot = False ,
615617 result_class = NotAResult
616618 )
619+ # self.assertIn("Using cached result", cm.output[0])
617620
618621 # so should a result loaded from cache
619622 assert isinstance (cached_result , NotAResult )
@@ -1006,6 +1009,24 @@ def test_save_to_file_defaults_to_pickle_with_incorrect_extension(self):
10061009 bilby .core .result .read_in_result (filename = expected )
10071010 os .remove (expected )
10081011
1012+ @parameterized .parameterized .expand ([
1013+ ("json" , "hdf5" ),
1014+ ("json" , "pkl" ),
1015+ ("hdf5" , "json" ),
1016+ ("pkl" , "json" ),
1017+ ("json" , "pkl" ),
1018+ ("hdf5" , "pkl" ),
1019+ ])
1020+ def test_save_and_read_incorrect_extension (self , save_extension , read_extension ):
1021+ """Test that an incorrect extension raises a somewhat helpful error"""
1022+ filename = os .path .join (self .result .outdir , "my_result" )
1023+ self .result .save_to_file (filename = filename , extension = save_extension )
1024+ with self .assertRaises (
1025+ (FileLoadError , IOError ), msg = f"Failed to read in file { filename } "
1026+ ):
1027+ bilby .core .result .read_in_result (filename = filename , extension = read_extension )
1028+ os .remove (filename )
1029+
10091030
10101031if __name__ == "__main__" :
10111032 unittest .main ()
0 commit comments