@@ -318,3 +318,41 @@ def test_cat_file_seekable_override(fs, remote_dir):
318318 # Test with explicit seekable=False
319319 result = fs .cat_file (remote_dir + "/test_cat.txt" , seekable = False )
320320 assert result == data
321+
322+
323+ def test_seekable_true_allows_size_method (fs , remote_dir ):
324+ """Test that size() method works when seekable=True."""
325+ data = b"test data for size method" * 10
326+
327+ # Create a test file
328+ test_file = remote_dir + "/test_size.txt"
329+ with fs .open (test_file , "wb" ) as f :
330+ f .write (data )
331+
332+ # Open with seekable=True - size() should work
333+ with fs .open (test_file , "rb" , seekable = True ) as f :
334+ assert f .seekable () is True
335+ # Verify size() method works and returns correct size
336+ file_size = f .size ()
337+ assert file_size == len (data )
338+ # Also verify we can read the data
339+ assert f .read () == data
340+
341+
342+ def test_seekable_false_prevents_size_method (fs , remote_dir ):
343+ """Test that size() method raises OSError when seekable=False."""
344+ data = b"test data for size method" * 10
345+
346+ # Create a test file
347+ test_file = remote_dir + "/test_size.txt"
348+ with fs .open (test_file , "wb" ) as f :
349+ f .write (data )
350+
351+ # Open with seekable=False - size() should raise OSError
352+ with fs .open (test_file , "rb" , seekable = False ) as f :
353+ assert f .seekable () is False
354+ # Verify size() raises OSError
355+ with pytest .raises (OSError , match = "only valid on seekable files" ):
356+ f .size ()
357+ # Verify we can still read the data
358+ assert f .read () == data
0 commit comments