From 9c59689aa706967db8b2709dd3c44cd4bfd09c37 Mon Sep 17 00:00:00 2001 From: karajan1001 Date: Fri, 1 Jul 2022 16:58:39 +0800 Subject: [PATCH] Gc: Move old unittest gc tests to pytest --- tests/func/test_cli.py | 22 --------------- tests/unit/command/test_gc.py | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 tests/unit/command/test_gc.py diff --git a/tests/func/test_cli.py b/tests/func/test_cli.py index d24cc0a65..e6bdfad43 100644 --- a/tests/func/test_cli.py +++ b/tests/func/test_cli.py @@ -6,7 +6,6 @@ from dvc.commands.add import CmdAdd from dvc.commands.checkout import CmdCheckout from dvc.commands.config import CmdConfig from dvc.commands.data_sync import CmdDataPull, CmdDataPush -from dvc.commands.gc import CmdGC from dvc.commands.init import CmdInit from dvc.commands.remove import CmdRemove from dvc.commands.repro import CmdRepro @@ -144,27 +143,6 @@ class TestAdd(TestDvc): cmd.repo.close() -class TestGC(TestDvc): - def test(self): - args = parse_args(["gc"]) - cmd = args.func(args) - self.assertIsInstance(cmd, CmdGC) - - cmd.repo.close() - - -class TestGCMultipleDvcRepos(TestDvc): - def test(self): - args = parse_args(["gc", "-p", "/tmp/asdf", "/tmp/xyz"]) - - cmd = args.func(args) - self.assertIsInstance(cmd, CmdGC) - - self.assertEqual(args.repos, ["/tmp/asdf", "/tmp/xyz"]) - - cmd.repo.close() - - class TestConfig(TestDvc): def test(self): name = "section.option" diff --git a/tests/unit/command/test_gc.py b/tests/unit/command/test_gc.py new file mode 100644 index 000000000..bddff3e32 --- /dev/null +++ b/tests/unit/command/test_gc.py @@ -0,0 +1,51 @@ +import pytest + +from dvc.cli import parse_args +from dvc.commands.gc import CmdGC +from dvc.exceptions import InvalidArgumentError + + +def test_(dvc, scm, mocker): + cli_args = parse_args( + [ + "gc", + "--workspace", + "--all-tags", + "--all-branches", + "--all-commits", + "--all-experiments", + "--cloud", + "--remote", + "origin", + "--force", + "--jobs", + "3", + "--projects", + "project1", + "project2", + ] + ) + assert cli_args.func == CmdGC + + cmd = cli_args.func(cli_args) + m = mocker.patch("dvc.repo.Repo.gc", return_value={}) + + assert cmd.run() == 0 + + m.assert_called_once_with( + workspace=True, + all_tags=True, + all_branches=True, + all_commits=True, + all_experiments=True, + cloud=True, + remote="origin", + force=True, + jobs=3, + repos=["project1", "project2"], + ) + + cli_args = parse_args(["gc"]) + cmd = cli_args.func(cli_args) + with pytest.raises(InvalidArgumentError): + cmd.run()