-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* pull/fetch/push: add stats * fix typo: s/logging/logger * pull: make stats detailed, with summary at the bottom * tests: mock properly, set return_value * add a line space
- Loading branch information
Showing
9 changed files
with
149 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from funcy import is_seq | ||
|
||
|
||
def join(words): | ||
words = list(words) | ||
if not words: | ||
return "" | ||
|
||
return ( | ||
"{before} and {after}".format( | ||
before=", ".join(words[:-1]), after=words[-1], | ||
) | ||
if len(words) > 1 | ||
else words[0] | ||
) | ||
|
||
|
||
def get_summary(stats): | ||
status = ( | ||
(state, len(data) if is_seq(data) else data) | ||
for state, data in stats | ||
if data | ||
) | ||
return join( | ||
"{} file{} {}".format(num, "s" if num > 1 else "", state) | ||
for state, num in status | ||
) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from collections import OrderedDict | ||
|
||
from dvc.utils.humanize import get_summary | ||
|
||
|
||
def test_get_summary(): | ||
# dict, so that we could delete from it easily | ||
stats = OrderedDict( | ||
[ | ||
("fetched", 3), | ||
("added", ["file1", "file2", "file3"]), | ||
("deleted", ["file4", "file5"]), | ||
("modified", ["file6", "file7"]), | ||
] | ||
) | ||
|
||
assert get_summary(stats.items()) == ( | ||
"3 files fetched, " | ||
"3 files added, " | ||
"2 files deleted " | ||
"and " | ||
"2 files modified" | ||
) | ||
|
||
del stats["fetched"] | ||
del stats["deleted"][1] | ||
assert ( | ||
get_summary(stats.items()) | ||
== "3 files added, 1 file deleted and 2 files modified" | ||
) | ||
|
||
del stats["deleted"][0] | ||
assert get_summary(stats.items()) == "3 files added and 2 files modified" | ||
|
||
del stats["modified"] | ||
assert get_summary(stats.items()) == "3 files added" | ||
|
||
assert get_summary([]) == "" | ||
assert get_summary([("x", 0), ("y", [])]) == "" | ||
assert get_summary([("x", 1), ("y", [])]) == "1 file x" |