mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/charliermarsh/ruff-pre-commit: v0.0.254 → v0.0.257](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.254...v0.0.257) - [github.com/codespell-project/codespell: v2.2.2 → v2.2.4](https://github.com/codespell-project/codespell/compare/v2.2.2...v2.2.4) * pre-commit: fix ruff errors * pre-commit: fix flake8 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: David de la Iglesia Castro <[email protected]>
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
from collections import OrderedDict
|
|
|
|
import pytest
|
|
|
|
from dvc.utils.humanize import get_summary, truncate_text
|
|
|
|
|
|
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 not get_summary([])
|
|
assert not get_summary([("x", 0), ("y", [])])
|
|
assert get_summary([("x", 1), ("y", [])]) == "1 file x"
|
|
|
|
|
|
def test_truncate_text():
|
|
text = "lorem ipsum"
|
|
length = 5
|
|
|
|
truncated = truncate_text(text, length)
|
|
# length should not cross the max length
|
|
assert len(truncated) == length
|
|
assert truncated[:-1] == text[: length - 1]
|
|
# last character should be ellipsis
|
|
assert truncated[-1] == "…"
|
|
|
|
truncated = truncate_text(text, length, with_ellipsis=False)
|
|
# length should not cross the max length
|
|
assert len(truncated) == length
|
|
assert truncated == text[:length]
|
|
|
|
|
|
@pytest.mark.parametrize("with_ellipsis", [True, False])
|
|
def test_truncate_text_smaller_than_max_length(with_ellipsis):
|
|
text = "lorem ipsum"
|
|
|
|
# exact match as length
|
|
truncated = truncate_text(text, len(text), with_ellipsis=with_ellipsis)
|
|
assert len(truncated) == len(text)
|
|
assert truncated == text
|
|
|
|
# max_length > len(text)
|
|
truncated = truncate_text(text, len(text) + 1, with_ellipsis=with_ellipsis)
|
|
assert len(truncated) == len(text)
|
|
assert truncated == text
|