[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:
Ruslan Kuprieiev
2020-07-03 16:16:43 +03:00
committed by GitHub
parent fb99f2e332
commit ec88fa8dec
4 changed files with 16 additions and 24 deletions
-11
View File
@@ -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("\\", "/")