|
16 | 16 | # under the License. |
17 | 17 |
|
18 | 18 | import os |
| 19 | +import pickle |
19 | 20 | import tempfile |
20 | 21 | import uuid |
21 | 22 |
|
@@ -229,6 +230,11 @@ def test_writing_avro_file(generated_manifest_entry_file: str, fsspec_fileio: Fs |
229 | 230 | fsspec_fileio.delete(f"s3://warehouse/{filename}") |
230 | 231 |
|
231 | 232 |
|
| 233 | +@pytest.mark.s3 |
| 234 | +def test_fsspec_pickle_round_trip_s3(fsspec_fileio: FsspecFileIO) -> None: |
| 235 | + _test_fsspec_pickle_round_trip(fsspec_fileio, "s3://warehouse/foo.txt") |
| 236 | + |
| 237 | + |
232 | 238 | @pytest.mark.adlfs |
233 | 239 | def test_fsspec_new_input_file_adlfs(adlfs_fsspec_fileio: FsspecFileIO) -> None: |
234 | 240 | """Test creating a new input file from an fsspec file-io""" |
@@ -410,6 +416,11 @@ def test_writing_avro_file_adlfs(generated_manifest_entry_file: str, adlfs_fsspe |
410 | 416 | adlfs_fsspec_fileio.delete(f"abfss://tests/{filename}") |
411 | 417 |
|
412 | 418 |
|
| 419 | +@pytest.mark.adlfs |
| 420 | +def test_fsspec_pickle_round_trip_aldfs(adlfs_fsspec_fileio: FsspecFileIO) -> None: |
| 421 | + _test_fsspec_pickle_round_trip(adlfs_fsspec_fileio, "abfss://tests/foo.txt") |
| 422 | + |
| 423 | + |
413 | 424 | @pytest.mark.gcs |
414 | 425 | def test_fsspec_new_input_file_gcs(fsspec_fileio_gcs: FsspecFileIO) -> None: |
415 | 426 | """Test creating a new input file from a fsspec file-io""" |
@@ -586,6 +597,26 @@ def test_writing_avro_file_gcs(generated_manifest_entry_file: str, fsspec_fileio |
586 | 597 | fsspec_fileio_gcs.delete(f"gs://warehouse/{filename}") |
587 | 598 |
|
588 | 599 |
|
| 600 | +@pytest.mark.gcs |
| 601 | +def test_fsspec_pickle_roundtrip_gcs(fsspec_fileio_gcs: FsspecFileIO) -> None: |
| 602 | + _test_fsspec_pickle_round_trip(fsspec_fileio_gcs, "gs://warehouse/foo.txt") |
| 603 | + |
| 604 | + |
| 605 | +def _test_fsspec_pickle_round_trip(fsspec_fileio: FsspecFileIO, location: str) -> None: |
| 606 | + serialized_file_io = pickle.dumps(fsspec_fileio) |
| 607 | + deserialized_file_io = pickle.loads(serialized_file_io) |
| 608 | + output_file = deserialized_file_io.new_output(location) |
| 609 | + with output_file.create() as f: |
| 610 | + f.write(b"foo") |
| 611 | + |
| 612 | + input_file = deserialized_file_io.new_input(location) |
| 613 | + with input_file.open() as f: |
| 614 | + data = f.read() |
| 615 | + assert data == b"foo" |
| 616 | + assert len(input_file) == 3 |
| 617 | + deserialized_file_io.delete(location) |
| 618 | + |
| 619 | + |
589 | 620 | TEST_URI = "https://iceberg-test-signer" |
590 | 621 |
|
591 | 622 |
|
|
0 commit comments