@@ -2210,3 +2210,48 @@ def test_write_max_concurrency(storage, max_concurrency, blob_size, blocksize):
22102210 with fs .open (path , "rb" ) as f :
22112211 assert f .read () == data
22122212 fs .rm (container_name , recursive = True )
2213+
2214+
2215+ def test_rm_file (storage ):
2216+ fs = AzureBlobFileSystem (
2217+ account_name = storage .account_name ,
2218+ connection_string = CONN_STR ,
2219+ )
2220+ path = "data/test_file.txt"
2221+ with fs .open (path , "wb" ) as f :
2222+ f .write (b"test content" )
2223+
2224+ assert fs .exists (path )
2225+ fs .rm_file (path )
2226+ with pytest .raises (FileNotFoundError ):
2227+ fs .ls (path )
2228+ assert not fs .exists (path )
2229+ assert path not in fs .dircache
2230+
2231+
2232+ def test_rm_file_versioned_blob (storage , mocker ):
2233+ from azure .storage .blob .aio import ContainerClient
2234+
2235+ fs = AzureBlobFileSystem (
2236+ account_name = storage .account_name ,
2237+ connection_string = CONN_STR ,
2238+ version_aware = True ,
2239+ )
2240+ mock_delete_blob = mocker .patch .object (
2241+ ContainerClient , "delete_blob" , return_value = None
2242+ )
2243+ path = f"data/test_file.txt?versionid={ DEFAULT_VERSION_ID } "
2244+ fs .rm_file (path )
2245+ mock_delete_blob .assert_called_once_with (
2246+ "test_file.txt" , version_id = DEFAULT_VERSION_ID
2247+ )
2248+
2249+
2250+ def test_rm_file_does_not_exist (storage ):
2251+ fs = AzureBlobFileSystem (
2252+ account_name = storage .account_name ,
2253+ connection_string = CONN_STR ,
2254+ )
2255+ path = "data/non_existent_file.txt"
2256+ with pytest .raises (FileNotFoundError ):
2257+ fs .rm_file (path )
0 commit comments