mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
[RFC] tests: make read_text() work with directories (#4155)
This PR is just a showcase to see how we like it. I've converted a few
tests to it, but there will be much more to come.
```
assert (tmp_dir / "file") == "contents"
assert (tmp_dir / "dir").read_text() == {"subdir": {"file": "hello"}}
```
This approach is nicer because it allows us to use a declaratory
asserts instead of relying on fs files. The problem becomes much more
apparent once you get into remote workspaces, where we `trees_equal`
doesn't work.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
from filecmp import dircmp
|
||||
|
||||
from dvc.scm import Git
|
||||
|
||||
@@ -20,15 +19,5 @@ def cd(newdir):
|
||||
os.chdir(prevdir)
|
||||
|
||||
|
||||
def trees_equal(dir_path_1, dir_path_2):
|
||||
|
||||
comparison = dircmp(dir_path_1, dir_path_2)
|
||||
|
||||
assert set(comparison.left_only) == set(comparison.right_only) == set()
|
||||
|
||||
for d in comparison.common_dirs:
|
||||
trees_equal(os.path.join(dir_path_1, d), os.path.join(dir_path_2, d))
|
||||
|
||||
|
||||
def to_posixpath(path):
|
||||
return path.replace("\\", "/")
|
||||
|
||||
Reference in New Issue
Block a user