-
Notifications
You must be signed in to change notification settings - Fork 1.2k
tests: use dir_helpers on repo #2950
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
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c178e77
tests/repo: use pytest
655b79b
tests/repo: move .destroy to unit test
b3a5251
tests/repo: move .collect to unit
37a2844
tests/repo: move .stages to unit
299fb90
:nail_care: black
df9f3de
tests/repo: stringify stage.relpath
08b335d
tests/repo: move unit tests to func tests
6ed61ef
tests/repo: refactor some tests
576290a
restyled: bump black to v19.10
a7525fc
:nail_care: black and flake
59072f4
:nail_care: revert black upgrade
5194543
tests/repo: windows compat
0de183d
tests/repo: reload cache properly
a83e440
tests/repo: remove unnecessary os.path.join
1bd66fa
tests/repo: old params in is_dvc_internal
d2469f7
tests/repo: str -> fspath
7dedd7f
tests/repo: bring back the old branch logic
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,73 @@ | ||
| from dvc.ignore import DvcIgnore | ||
| from dvc.main import main | ||
| import os | ||
|
|
||
| from dvc.scm.git.tree import GitTree | ||
| from dvc.cache import Cache | ||
| from dvc.repo import Repo | ||
| from dvc.scm.git import GitTree | ||
| from dvc.scm.tree import WorkingTree | ||
| from dvc.stage import Stage | ||
| from tests.basic_env import TestDvcGit | ||
|
|
||
|
|
||
| class TestCollect(TestDvcGit): | ||
| def setUp(self): | ||
| super(TestCollect, self).setUp() | ||
| self.dvc.add(self.FOO) | ||
| self.dvc.run( | ||
| deps=[self.FOO], | ||
| outs=[self.BAR], | ||
| cmd="python code.py {} {}".format(self.FOO, self.BAR), | ||
| ) | ||
| self.dvc.scm.add([".gitignore", self.FOO + ".dvc", self.BAR + ".dvc"]) | ||
| self.dvc.scm.commit("foo.dvc and bar.dvc") | ||
| self.dvc.scm.checkout("new_branch", True) | ||
| self.dvc.run( | ||
| deps=[self.BAR], | ||
| outs=["buzz"], | ||
| cmd="python code.py {} {}".format(self.BAR, "buzz"), | ||
| ) | ||
| self.dvc.scm.add([".gitignore", "buzz.dvc"]) | ||
| self.dvc.scm.commit("add buzz") | ||
| self.dvc.scm.checkout("master") | ||
|
|
||
| def _check(self, branch, target, with_deps, expected): | ||
| if branch: | ||
| self.dvc.tree = GitTree(self.dvc.scm.repo, branch) | ||
| else: | ||
| self.dvc.tree = WorkingTree() | ||
| result = self.dvc.collect(target + ".dvc", with_deps=with_deps) | ||
| self.assertEqual([[str(j) for j in i.outs] for i in result], expected) | ||
| return result | ||
|
|
||
| def test(self): | ||
| self._check("", self.BAR, True, [[self.FOO], [self.BAR]]) | ||
| self._check("master", self.BAR, True, [[self.FOO], [self.BAR]]) | ||
| self._check( | ||
| "new_branch", "buzz", True, [[self.FOO], [self.BAR], ["buzz"]] | ||
| from dvc.system import System | ||
| from dvc.utils.compat import fspath | ||
|
|
||
|
|
||
| def test_destroy(tmp_dir, dvc): | ||
| dvc.config.set("cache", "type", "symlink") | ||
| dvc.cache = Cache(dvc) | ||
|
|
||
| tmp_dir.dvc_gen("file", "text") | ||
| tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}}) | ||
|
|
||
| dvc.destroy() | ||
|
|
||
| # Remove all the files related to DVC | ||
| for path in [".dvc", "file.dvc", "dir.dvc"]: | ||
| assert not (tmp_dir / path).exists() | ||
|
|
||
| # Leave the rest of the files | ||
| for path in ["file", "dir/file", "dir/subdir/file"]: | ||
| assert (tmp_dir / path).is_file() | ||
|
|
||
| # Make sure that data was unprotected after `destroy` | ||
| for path in ["file", "dir", "dir/file", "dir/subdir", "dir/subdir/file"]: | ||
| assert not System.is_symlink(fspath(tmp_dir / path)) | ||
|
|
||
|
|
||
| def test_collect(tmp_dir, scm, dvc, run_copy): | ||
| def collect_outs(*args, **kwargs): | ||
| return set( | ||
| str(out.path_info) | ||
| for stage in dvc.collect(*args, **kwargs) | ||
| for out in stage.outs | ||
| ) | ||
| result = self._check("new_branch", "buzz", False, [["buzz"]]) | ||
| self.assertEqual([str(i) for i in result[0].deps], ["bar"]) | ||
|
|
||
| tmp_dir.dvc_gen("foo", "foo") | ||
| run_copy("foo", "bar") | ||
| scm.add([".gitignore", "foo.dvc", "bar.dvc"]) | ||
| scm.commit("Add foo and bar") | ||
|
|
||
| scm.checkout("new-branch", create_new=True) | ||
|
|
||
| run_copy("bar", "buzz") | ||
| scm.add([".gitignore", "buzz.dvc"]) | ||
| scm.commit("Add buzz") | ||
|
|
||
| assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"} | ||
|
|
||
| dvc.tree = GitTree(scm.repo, "new-branch") | ||
|
|
||
| assert collect_outs("buzz.dvc", with_deps=True) == {"foo", "bar", "buzz"} | ||
| assert collect_outs("buzz.dvc", with_deps=False) == {"buzz"} | ||
|
|
||
| class TestIgnore(TestDvcGit): | ||
| def _stage_name(self, file): | ||
| return file + Stage.STAGE_FILE_SUFFIX | ||
|
|
||
| def test_should_not_gather_stage_files_from_ignored_dir(self): | ||
| ret = main(["add", self.FOO, self.BAR, self.DATA, self.DATA_SUB]) | ||
| self.assertEqual(0, ret) | ||
| def test_stages(tmp_dir, dvc): | ||
| def stages(): | ||
| return set(stage.relpath for stage in Repo(fspath(tmp_dir)).stages) | ||
|
|
||
| stages = self.dvc.stages | ||
| self.assertEqual(4, len(stages)) | ||
| tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) | ||
|
|
||
| self.create(DvcIgnore.DVCIGNORE_FILE, self.DATA_DIR) | ||
| assert stages() == { | ||
| "file.dvc", | ||
| os.path.join("dir", "file.dvc"), | ||
| os.path.join("dir", "subdir", "file.dvc"), | ||
| } | ||
|
|
||
| self.dvc = Repo(self.dvc.root_dir) | ||
| stages = self.dvc.stages | ||
| self.assertEqual(2, len(stages)) | ||
| tmp_dir.gen(".dvcignore", "dir") | ||
|
|
||
| stagenames = [s.relpath for s in stages] | ||
| self.assertIn(self._stage_name(self.FOO), stagenames) | ||
| self.assertIn(self._stage_name(self.BAR), stagenames) | ||
| self.assertNotIn(self._stage_name(self.DATA), stagenames) | ||
| self.assertNotIn(self._stage_name(self.DATA_SUB), stagenames) | ||
| assert stages() == {"file.dvc"} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,6 @@ | ||
| import os | ||
|
|
||
| from tests.basic_env import TestDvc | ||
|
|
||
|
|
||
| class TestIsDvcInternal(TestDvc): | ||
| def test_return_false_on_non_dvc_file(self): | ||
| path = os.path.join("path", "to-non-.dvc", "file") | ||
| self.assertFalse(self.dvc.is_dvc_internal(path)) | ||
|
|
||
| def test_return_true_on_dvc_internal_file(self): | ||
| path = os.path.join("path", "to", ".dvc", "file") | ||
| self.assertTrue(path) | ||
| def test_is_dvc_internal(dvc): | ||
| assert dvc.is_dvc_internal(os.path.join("path", "to", ".dvc", "file")) | ||
| assert not dvc.is_dvc_internal(os.path.join("path", "to-non-.dvc", "file")) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dvc.cache = Cache(dvc)setting cache type does not reload it, and last check is always true