From 475551b59a76df3d54821e1f4fcce1e49cb9b827 Mon Sep 17 00:00:00 2001 From: Sebastien Delaux Date: Wed, 22 Jan 2025 02:36:57 +1300 Subject: [PATCH] Altering test_storage to make it pass --- tests/test_storage.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/test_storage.py b/tests/test_storage.py index ee90079..4191b66 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -55,9 +55,15 @@ def test_ls(fs, dummy_files): assert len(files) == 1 assert files[0]["type"] == "directory" - paths = list(fs.walk(REMOTE_PATH)) - assert len(paths) == 2 - + # As the bucket tends to contain many things + # just make sure that the expected folder contains + # the expected file. Shows ls gives us those files + found = False + for p in fs.walk(REMOTE_PATH): + if p[0] == 'test_storage/test': + found = ("file1.txt" in p[-1]) and ("file2.txt" in p[-1]) + break + assert found def test_get(fs, dummy_files): fs.mkdirs(REMOTE_PATH, exist_ok=True) @@ -77,3 +83,26 @@ def test_open(fs, dummy_files): "oceanum://" + os.path.join(REMOTE_PATH, "test", "file1.txt"), "r" ) as f: assert f.read() == "hello" + + +def test_copy(fs, dummy_files): + fs.mkdirs(REMOTE_PATH, exist_ok=True) + fs.put(os.path.join(dummy_files.name, "test"), REMOTE_PATH, recursive=True) + + fs.copy( + os.path.join(REMOTE_PATH, "test", "file1.txt"), + os.path.join(REMOTE_PATH, "test", "file_copy.txt"), + ) + + with fsspec.open( + "oceanum://" + os.path.join(REMOTE_PATH, "test", "file_copy.txt"), "r" + ) as f: + assert f.read() == "hello" + + +def test_copy_fails(fs): + with pytest.raises(FileNotFoundError): + fs.copy( + os.path.join(REMOTE_PATH, "test", "file_not_there.txt"), + os.path.join(REMOTE_PATH, "test", "file_copy.txt"), + )