Skip to content

[RFC] tests: make read_text() work with directories #4155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2020

Conversation

efiop
Copy link
Contributor

@efiop efiop commented Jul 2, 2020

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 is basically the same as what we feed
to TmpDir.gen and also 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.

  • ❗ I have followed the Contributing to DVC checklist.

  • 📖 If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here.

  • ❌ I will check DeepSource, CodeClimate, and other sanity checks below. (We consider them recommendatory and don't expect everything to be addressed. Please fix things that actually improve code or fix bugs.)

Thank you for the contribution - we'll try to review it as soon as possible. 🙏

@efiop efiop requested a review from a team July 2, 2020 18:55
@efiop
Copy link
Contributor Author

efiop commented Jul 2, 2020

@Suor what do you think, is this following your philosophy as TmpDir creator? 🙂

@efiop efiop requested review from pared, pmrowla, skshetry and Suor and removed request for a team July 2, 2020 19:14
@efiop efiop mentioned this pull request Jul 2, 2020
3 tasks
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.
efiop added a commit to efiop/dvc that referenced this pull request Jul 2, 2020
Copy link
Contributor

@pared pared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great idea, in my opinion.

@efiop efiop merged commit ec88fa8 into iterative:master Jul 3, 2020
efiop added a commit that referenced this pull request Jul 3, 2020
* [RFC] tests: make read_text() work with directories

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.

* status: pass tree as a kwarg

Fixes #4150

Depends on #4155
@efiop efiop deleted the dir_fixtures branch July 6, 2020 01:40
@Suor
Copy link
Contributor

Suor commented Jul 6, 2020

I looked at how you:

assert (tmp_dir / "file") == "contents"

and assumed you overloaded __eq__ :)

Overall, I thought about that for a while, simply never needed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants