Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Feb 7, 2022
1 parent 73df067 commit 5511734
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 13 deletions.
3 changes: 3 additions & 0 deletions renku/cli/log.py
Expand Up @@ -105,6 +105,9 @@ def _print_dataset_log(log_entry: DatasetLogViewModel) -> str:
if change:
results.append(click.style("Changes: ", bold=True, fg="magenta") + ", ".join(change))

if log_entry.details.source:
results.append(click.style("Source: ", bold=True, fg="magenta") + log_entry.details.source)

if log_entry.details.title_changed:
results.append(click.style("Title set to: ", bold=True, fg="magenta") + log_entry.details.title_changed)

Expand Down
6 changes: 4 additions & 2 deletions renku/core/commands/view_model/log.py
Expand Up @@ -82,6 +82,7 @@ class DatasetChangeDetailsViewModel:
keywords_added: Optional[List[str]] = None
keywords_removed: Optional[List[str]] = None
images_changed_to: Optional[List[str]] = None
source: Optional[str] = None


class LogViewModel:
Expand Down Expand Up @@ -162,6 +163,7 @@ def from_dataset(cls, dataset: "Dataset"):
elif dataset.change_type & DatasetChangeType.IMPORTED:
descriptions.append("imported")
details.imported = True
details.source = dataset.same_as.value
elif dataset.change_type & DatasetChangeType.INVALIDATED:
descriptions.append("deleted")
details.deleted = True
Expand Down Expand Up @@ -249,8 +251,8 @@ def from_dataset(cls, dataset: "Dataset"):

return DatasetLogViewModel(
id=dataset.name,
date=dataset.date_modified,
description=descriptions[0] + " ".join(descriptions[1:]),
date=dataset.date_removed if dataset.change_type & DatasetChangeType.INVALIDATED else dataset.date_modified,
description=descriptions[0] + ", ".join(descriptions[1:]),
details=details,
agents=[c.full_identity for c in dataset.creators],
)
Expand Down
48 changes: 45 additions & 3 deletions tests/cli/test_log.py
Expand Up @@ -28,12 +28,54 @@ def test_activity_log(runner, project):

result = runner.invoke(cli, ["log"])
assert 0 == result.exit_code, format_result_exception(result)
assert "Run touch foo" in result.output
assert "Activity /activities/" in result.output
assert "Command: touch foo" in result.output
assert "output-1: foo" in result.output
assert "Start Time:" in result.output
assert "Renku Version:" in result.output

result = runner.invoke(cli, ["run", "--name", "run2", "cp", "foo", "bar"])
assert 0 == result.exit_code, format_result_exception(result)

result = runner.invoke(cli, ["log"])
assert 0 == result.exit_code, format_result_exception(result)
assert "Run touch foo" in result.output
assert "Run cp foo bar" in result.output
assert "Activity /activities/" in result.output
assert "Command: touch foo" in result.output
assert "output-1: foo" in result.output
assert "Start Time:" in result.output
assert "Renku Version:" in result.output
assert "Command: cp foo bar" in result.output
assert "input-1: foo" in result.output
assert "output-2: bar" in result.output


def test_dataset_log(runner, project, client):
"""Test renku log for dataset."""
result = runner.invoke(cli, ["dataset", "create", "testset"])
assert 0 == result.exit_code, format_result_exception(result)

with (client.path / "my_file").open("w") as fp:
fp.write("dataset file")

result = runner.invoke(cli, ["dataset", "add", "testset", "my_file"])
assert 0 == result.exit_code, format_result_exception(result)
result = runner.invoke(
cli, ["dataset", "edit", "testset", "-t", "new title", "-d", "new description", "-k", "a", "-k", "b"]
)
assert 0 == result.exit_code, format_result_exception(result)
result = runner.invoke(cli, ["dataset", "unlink", "testset", "--include", "my_file"], input="y")
assert 0 == result.exit_code, format_result_exception(result)

result = runner.invoke(cli, ["log"])

assert 0 == result.exit_code, format_result_exception(result)
assert "Dataset testset" in result.output
assert "Changes: created" in result.output
assert "Changes: modified" in result.output
assert "Files modified" in result.output
assert "- my_file" in result.output
assert "+ my_file" in result.output
assert "Title set to: new title" in result.output
assert "Description set to: new description" in result.output
assert "Keywords modified" in result.output
assert "Creators modified" in result.output

0 comments on commit 5511734

Please sign in to comment.