Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dvc/scm/git/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _walk(
tree.abspath, ignore_file_handler=ignore_file_handler
)
dirs, nondirs = dvc_ignore_filter(tree.path, dirs, nondirs)
yield os.path.normpath(tree.path), dirs, nondirs
yield os.path.normpath(tree.abspath), dirs, nondirs

for i in dirs:
for x in self._walk(
Expand All @@ -121,7 +121,7 @@ def _walk(
yield x

if not topdown:
yield os.path.normpath(tree.path), dirs, nondirs
yield os.path.normpath(tree.abspath), dirs, nondirs

def walk(self, top, topdown=True, ignore_file_handler=None):
"""Directory tree generator.
Expand Down
2 changes: 1 addition & 1 deletion dvc/scm/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def onerror(e):
raise e

for root, dirs, files in dvc_walk(
top,
os.path.abspath(top),
topdown=topdown,
onerror=onerror,
ignore_file_handler=ignore_file_handler,
Expand Down
27 changes: 27 additions & 0 deletions tests/func/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,33 @@ def test_formatted_output(self):
assert expected_txt in stdout
assert expected_json in stdout

def test_show_all_should_be_current_dir_agnostic(self):
os.chdir(self.DATA_DIR)

metrics = self.dvc.metrics.show(all_branches=True)
self.assertMetricsHaveRelativePaths(metrics)
Copy link
Contributor

@efiop efiop Apr 22, 2019

Choose a reason for hiding this comment

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

But mfile is not even in metrics. Are you using it at all then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, at the beggining I didn't realize that this test sets up few metrics. There is no need for additional one. Also, there is no need to run any command, as we already have metrics on different branches.


def assertMetricsHaveRelativePaths(self, metrics):
root_relpath = os.path.relpath(self.dvc.root_dir)
metric_path = os.path.join(root_relpath, "metric")
metric_json_path = os.path.join(root_relpath, "metric_json")
metric_tsv_path = os.path.join(root_relpath, "metric_tsv")
metric_htsv_path = os.path.join(root_relpath, "metric_htsv")
metric_csv_path = os.path.join(root_relpath, "metric_csv")
metric_hcsv_path = os.path.join(root_relpath, "metric_hcsv")
for branch in ["bar", "baz", "foo"]:
self.assertEqual(
set(metrics[branch].keys()),
{
metric_path,
metric_json_path,
metric_tsv_path,
metric_htsv_path,
metric_csv_path,
metric_hcsv_path,
},
)


class TestMetricsRecursive(TestDvc):
def setUp(self):
Expand Down
70 changes: 54 additions & 16 deletions tests/func/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,38 +97,66 @@ def convert_to_sets(walk_results):

class TestWalkInNoSCM(AssertWalkEqualMixin, TestDir):
def test(self):
tree = WorkingTree()
tree = WorkingTree(self._root_dir)
self.assertWalkEqual(
tree.walk("."),
tree.walk(self._root_dir),
[
(".", ["data_dir"], ["code.py", "bar", "тест", "foo"]),
(join("data_dir"), ["data_sub_dir"], ["data"]),
(join("data_dir", "data_sub_dir"), [], ["data_sub"]),
(
self._root_dir,
["data_dir"],
["code.py", "bar", "тест", "foo"],
),
(join(self._root_dir, "data_dir"), ["data_sub_dir"], ["data"]),
(
join(self._root_dir, "data_dir", "data_sub_dir"),
[],
["data_sub"],
),
],
)

def test_subdir(self):
tree = WorkingTree()
tree = WorkingTree(self._root_dir)
self.assertWalkEqual(
tree.walk(join("data_dir", "data_sub_dir")),
[(join("data_dir", "data_sub_dir"), [], ["data_sub"])],
[
(
join(self._root_dir, "data_dir", "data_sub_dir"),
[],
["data_sub"],
)
],
)


class TestWalkInGit(AssertWalkEqualMixin, TestGit):
def test_nobranch(self):
tree = WorkingTree()
tree = WorkingTree(self._root_dir)
self.assertWalkEqual(
tree.walk("."),
[
(".", ["data_dir"], ["bar", "тест", "code.py", "foo"]),
("data_dir", ["data_sub_dir"], ["data"]),
(join("data_dir", "data_sub_dir"), [], ["data_sub"]),
(
self._root_dir,
["data_dir"],
["bar", "тест", "code.py", "foo"],
),
(join(self._root_dir, "data_dir"), ["data_sub_dir"], ["data"]),
(
join(self._root_dir, "data_dir", "data_sub_dir"),
[],
["data_sub"],
),
],
)
self.assertWalkEqual(
tree.walk(join("data_dir", "data_sub_dir")),
[(join("data_dir", "data_sub_dir"), [], ["data_sub"])],
[
(
join(self._root_dir, "data_dir", "data_sub_dir"),
[],
["data_sub"],
)
],
)

def test_branch(self):
Expand All @@ -139,12 +167,22 @@ def test_branch(self):
self.assertWalkEqual(
tree.walk("."),
[
(".", ["data_dir"], ["code.py"]),
("data_dir", ["data_sub_dir"], []),
(join("data_dir", "data_sub_dir"), [], ["data_sub"]),
(self._root_dir, ["data_dir"], ["code.py"]),
(join(self._root_dir, "data_dir"), ["data_sub_dir"], []),
(
join(self._root_dir, "data_dir", "data_sub_dir"),
[],
["data_sub"],
),
],
)
self.assertWalkEqual(
tree.walk(join("data_dir", "data_sub_dir")),
[(join("data_dir", "data_sub_dir"), [], ["data_sub"])],
[
(
join(self._root_dir, "data_dir", "data_sub_dir"),
[],
["data_sub"],
)
],
)