(s3_connection, s3fs, tempdir)
| 2005 | |
| 2006 | @pytest.mark.s3 |
| 2007 | def test_copy_files(s3_connection, s3fs, tempdir): |
| 2008 | fs = s3fs["fs"] |
| 2009 | pathfn = s3fs["pathfn"] |
| 2010 | |
| 2011 | # create test file on S3 filesystem |
| 2012 | path = pathfn('c.txt') |
| 2013 | with fs.open_output_stream(path) as f: |
| 2014 | f.write(b'test') |
| 2015 | |
| 2016 | # create URI for created file |
| 2017 | host, port, access_key, secret_key = s3_connection |
| 2018 | source_uri = ( |
| 2019 | f"s3://{access_key}:{secret_key}@{path}" |
| 2020 | f"?scheme=http&endpoint_override={host}:{port}" |
| 2021 | ) |
| 2022 | # copy from S3 URI to local file |
| 2023 | local_path1 = str(tempdir / "c_copied1.txt") |
| 2024 | copy_files(source_uri, local_path1) |
| 2025 | |
| 2026 | localfs = LocalFileSystem() |
| 2027 | with localfs.open_input_stream(local_path1) as f: |
| 2028 | assert f.read() == b"test" |
| 2029 | |
| 2030 | # copy from S3 path+filesystem to local file |
| 2031 | local_path2 = str(tempdir / "c_copied2.txt") |
| 2032 | copy_files(path, local_path2, source_filesystem=fs) |
| 2033 | with localfs.open_input_stream(local_path2) as f: |
| 2034 | assert f.read() == b"test" |
| 2035 | |
| 2036 | # copy to local file with URI |
| 2037 | local_path3 = str(tempdir / "c_copied3.txt") |
| 2038 | destination_uri = _filesystem_uri(local_path3) # file:// |
| 2039 | copy_files(source_uri, destination_uri) |
| 2040 | |
| 2041 | with localfs.open_input_stream(local_path3) as f: |
| 2042 | assert f.read() == b"test" |
| 2043 | |
| 2044 | # copy to local file with path+filesystem |
| 2045 | local_path4 = str(tempdir / "c_copied4.txt") |
| 2046 | copy_files(source_uri, local_path4, destination_filesystem=localfs) |
| 2047 | |
| 2048 | with localfs.open_input_stream(local_path4) as f: |
| 2049 | assert f.read() == b"test" |
| 2050 | |
| 2051 | # copy with additional options |
| 2052 | local_path5 = str(tempdir / "c_copied5.txt") |
| 2053 | copy_files(source_uri, local_path5, chunk_size=1, use_threads=False) |
| 2054 | |
| 2055 | with localfs.open_input_stream(local_path5) as f: |
| 2056 | assert f.read() == b"test" |
| 2057 | |
| 2058 | |
| 2059 | def test_copy_files_directory(tempdir): |
nothing calls this directly
no test coverage detected