@@ -924,3 +924,28 @@ def test_str():
924924 lfs = LocalFileSystem ()
925925 cfs = CachingFileSystem (fs = lfs )
926926 assert "CachingFileSystem" in str (cfs )
927+
928+
929+ def test_getitems_errors (tmpdir ):
930+ tmpdir = str (tmpdir )
931+ os .makedirs (os .path .join (tmpdir , "afolder" ))
932+ open (os .path .join (tmpdir , "afile" ), "w" ).write ("test" )
933+ open (os .path .join (tmpdir , "afolder" , "anotherfile" ), "w" ).write ("test2" )
934+ m = fsspec .get_mapper ("file://" + tmpdir )
935+ assert m .getitems (["afile" , "bfile" ], on_error = "omit" ) == {"afile" : b"test" }
936+
937+ # my code
938+ m2 = fsspec .get_mapper ("simplecache::file://" + tmpdir )
939+ assert m2 .getitems (["afile" ], on_error = "omit" ) == {"afile" : b"test" } # works
940+ assert m2 .getitems (["afile" , "bfile" ], on_error = "omit" ) == {
941+ "afile" : b"test"
942+ } # throws KeyError
943+
944+ with pytest .raises (KeyError ):
945+ m .getitems (["afile" , "bfile" ])
946+ out = m .getitems (["afile" , "bfile" ], on_error = "return" )
947+ assert isinstance (out ["bfile" ], KeyError )
948+ m = fsspec .get_mapper ("file://" + tmpdir , missing_exceptions = ())
949+ assert m .getitems (["afile" , "bfile" ], on_error = "omit" ) == {"afile" : b"test" }
950+ with pytest .raises (FileNotFoundError ):
951+ m .getitems (["afile" , "bfile" ])
0 commit comments