From f4d780e9a9dbbc96875d71b211ea651babf2c5e2 Mon Sep 17 00:00:00 2001 From: karajan1001 Date: Mon, 20 Jun 2022 18:40:04 +0800 Subject: [PATCH] queue status: add some unit test to increase the coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followed by #7903 Add a new unit test to increase the coverage of test Co-authored-by: Peter Rowlands (변기호) --- tests/unit/command/test_queue.py | 52 +++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/unit/command/test_queue.py b/tests/unit/command/test_queue.py index bc9ebac40a..332d0c1e49 100644 --- a/tests/unit/command/test_queue.py +++ b/tests/unit/command/test_queue.py @@ -1,3 +1,5 @@ +import pytest + from dvc.cli import parse_args from dvc.commands.queue.kill import CmdQueueKill from dvc.commands.queue.logs import CmdQueueLogs @@ -99,7 +101,55 @@ def test_experiments_stop(dvc, scm, mocker): m.assert_called_once_with(kill=True) -def test_experiments_status(dvc, scm, mocker, capsys, caplog): +@pytest.mark.parametrize( + "worker_status, output", + [ + ( + {"worker1": [], "worker2": []}, + "No worker active, 2 workers idle at present.", + ), + ( + { + "worker1": [{"id": "1"}], + "worker2": [{"id": "2"}], + "worker3": [], + }, + "There are 2 workers active, 1 worker idle at present.", + ), + ( + {"worker1": [{"id": "1"}]}, + "There is 1 worker active, no worker idle at present.", + ), + ], +) +def test_worker_status(dvc, scm, worker_status, output, mocker, capsys): + + cli_args = parse_args( + [ + "queue", + "status", + ] + ) + assert cli_args.func == CmdQueueStatus + + cmd = cli_args.func(cli_args) + mocker.patch( + "dvc.repo.experiments.queue.local.LocalCeleryQueue.status", + return_value=[], + ) + m = mocker.patch( + "dvc.repo.experiments.queue.local.LocalCeleryQueue.worker_status", + return_value=worker_status, + ) + + assert cmd.run() == 0 + m.assert_called_once_with() + log, _ = capsys.readouterr() + assert "No experiments in task queue for now." in log + assert output in log + + +def test_experiments_status(dvc, scm, mocker, capsys): from datetime import datetime cli_args = parse_args(