mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
dvcfs: add tests for fsid
This commit is contained in:
+3
-1
@@ -166,9 +166,11 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
|
||||
def fsid(self) -> str:
|
||||
from fsspec.utils import tokenize
|
||||
|
||||
from dvc.scm import NoSCM
|
||||
|
||||
return "dvcfs_" + tokenize(
|
||||
self.repo.url or self.repo.root_dir,
|
||||
self.repo.get_rev() if self.repo.scm else None,
|
||||
self.repo.get_rev() if not isinstance(self.repo.scm, NoSCM) else None,
|
||||
)
|
||||
|
||||
def _get_key(self, path: "StrPath") -> Key:
|
||||
|
||||
@@ -3,6 +3,7 @@ import posixpath
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
from fsspec.utils import tokenize
|
||||
|
||||
from dvc.fs import localfs
|
||||
from dvc.fs.dvc import DVCFileSystem
|
||||
@@ -652,3 +653,37 @@ def test_walk_nested_subrepos(tmp_dir, dvc, scm, traverse_subrepos):
|
||||
for root, dirs, files in fs.walk("/", ignore_subrepos=not traverse_subrepos):
|
||||
actual[root] = set(dirs + files)
|
||||
assert expected == actual
|
||||
|
||||
|
||||
def test_fsid_noscm(tmp_dir, dvc):
|
||||
fs = DVCFileSystem(repo=dvc)
|
||||
assert fs.fsid == "dvcfs_" + tokenize(dvc.root_dir, None)
|
||||
|
||||
|
||||
def test_fsid(tmp_dir, dvc, scm):
|
||||
fs = DVCFileSystem(repo=dvc)
|
||||
assert fs.fsid == "dvcfs_" + tokenize(dvc.root_dir, scm.get_rev())
|
||||
old_fsid = fs.fsid
|
||||
|
||||
tmp_dir.dvc_gen({"foo": "foo"}, commit="foo")
|
||||
fs = DVCFileSystem(repo=dvc)
|
||||
assert fs.fsid != old_fsid
|
||||
assert fs.fsid == "dvcfs_" + tokenize(dvc.root_dir, scm.get_rev())
|
||||
|
||||
|
||||
def test_fsid_url(erepo_dir):
|
||||
from dvc.repo import Repo
|
||||
|
||||
url = f"file://{erepo_dir.as_posix()}"
|
||||
with Repo.open(url) as dvc:
|
||||
fs = DVCFileSystem(repo=dvc)
|
||||
assert fs.fsid == "dvcfs_" + tokenize(url, erepo_dir.scm.get_rev())
|
||||
old_fsid = fs.fsid
|
||||
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen({"foo": "foo"}, commit="foo")
|
||||
|
||||
with Repo.open(url) as dvc:
|
||||
fs = DVCFileSystem(repo=dvc)
|
||||
assert fs.fsid != old_fsid
|
||||
assert fs.fsid == "dvcfs_" + tokenize(url, erepo_dir.scm.get_rev())
|
||||
|
||||
Reference in New Issue
Block a user