@@ -581,3 +581,43 @@ async def test_async_walk(server):
581581 pass
582582
583583 await fs ._session .close ()
584+
585+
586+ def test_pipe_file (server , tmpdir , reset_files ):
587+ """Test that the pipe_file method works correctly."""
588+ import io
589+
590+ import fsspec
591+
592+ # Create test data
593+ test_content = b"This is test data to pipe to a file"
594+
595+ # Initialize filesystem
596+ fs = fsspec .filesystem ("http" , headers = {"accept_put" : "true" })
597+
598+ # Test that the file doesn't exist yet
599+ with pytest .raises (FileNotFoundError ):
600+ fs .info (server .address + "/piped_file" )
601+
602+ # Pipe data to the file
603+ fs .pipe_file (server .address + "/piped_file" , test_content )
604+
605+ # Verify the file exists now
606+ assert fs .exists (server .address + "/piped_file" )
607+
608+ # Verify content
609+ assert fs .cat (server .address + "/piped_file" ) == test_content
610+
611+ # Test with different modes and headers
612+ fs .pipe_file (
613+ server .address + "/piped_file2" ,
614+ test_content ,
615+ mode = "overwrite" ,
616+ headers = {"Content-Type" : "text/plain" },
617+ )
618+ assert fs .cat (server .address + "/piped_file2" ) == test_content
619+
620+ # Test with byte-like object
621+ bytesio = io .BytesIO (b"BytesIO content" )
622+ fs .pipe_file (server .address + "/piped_bytes" , bytesio .getvalue ())
623+ assert fs .cat (server .address + "/piped_bytes" ) == b"BytesIO content"
0 commit comments