|
| 1 | +"""dvc-objects compatibility cases migrated for issue #51. |
| 2 | +
|
| 3 | +Source: dvc-objects 5.2.0, |
| 4 | +``tests/fs/test_generic.py::test_copy`` and |
| 5 | +``tests/fs/test_localfs.py::test_walk``. The operations pass an opendalfs |
| 6 | +instance through dvc-objects' existing ``MemoryFileSystem(fs=...)`` entry point. |
| 7 | +""" |
| 8 | + |
| 9 | +from dvc_objects.fs.memory import MemoryFileSystem |
| 10 | + |
| 11 | +from opendalfs import OpendalFileSystem |
| 12 | + |
| 13 | + |
| 14 | +def test_dvc_objects_find_walk_put_and_get(tmp_path): |
| 15 | + fs = MemoryFileSystem( |
| 16 | + fs=OpendalFileSystem( |
| 17 | + scheme="memory", |
| 18 | + asynchronous=False, |
| 19 | + skip_instance_cache=True, |
| 20 | + ) |
| 21 | + ) |
| 22 | + sources = { |
| 23 | + tmp_path / "sources" / "one.txt": b"one", |
| 24 | + tmp_path / "sources" / "nested" / "two.txt": b"two", |
| 25 | + } |
| 26 | + for path, content in sources.items(): |
| 27 | + path.parent.mkdir(parents=True, exist_ok=True) |
| 28 | + path.write_bytes(content) |
| 29 | + |
| 30 | + remote_paths = ["dataset/one.txt", "dataset/nested/two.txt"] |
| 31 | + fs.put([str(path) for path in sources], remote_paths) |
| 32 | + |
| 33 | + assert set(fs.find("dataset")) == set(remote_paths) |
| 34 | + assert [ |
| 35 | + (root, set(dirs), set(files)) for root, dirs, files in fs.walk("dataset") |
| 36 | + ] == [ |
| 37 | + ("dataset", {"nested"}, {"one.txt"}), |
| 38 | + ("dataset/nested", set(), {"two.txt"}), |
| 39 | + ] |
| 40 | + |
| 41 | + downloads = [tmp_path / "downloads" / path for path in ("one.txt", "two.txt")] |
| 42 | + fs.get(remote_paths, [str(path) for path in downloads]) |
| 43 | + |
| 44 | + assert [path.read_bytes() for path in downloads] == [b"one", b"two"] |
0 commit comments