From 85cebf7af1712dfc8214564045d68317656cf03b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 25 Jan 2021 13:57:06 +0100 Subject: Merging upstream version 0.12.9. Signed-off-by: Daniel Baumann --- tests/test_main.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_main.py b/tests/test_main.py index 1c30eec..ad501f7 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -43,7 +43,7 @@ class TestLsLl: assert info.Color.end in out # no color on branch name - __main__.main(['ll', '-n']) + __main__.main(['ll', '-C']) out, err = capfd.readouterr() assert err == '' assert 'gita' in out @@ -95,6 +95,16 @@ class TestLsLl: assert out == expected +@patch('subprocess.run') +@patch('gita.utils.get_repos', return_value={'repo1': '/a/', 'repo2': '/b/'}) +def test_freeze(_, mock_run, capfd): + __main__.main(['freeze']) + assert mock_run.call_count == 2 + out, err = capfd.readouterr() + assert err == '' + assert out == ',repo1,/a/\n,repo2,/b/\n' + + @patch('os.path.isfile', return_value=True) @patch('gita.common.get_config_fname', return_value='some path') @patch('gita.utils.get_repos', return_value={'repo1': '/a/', 'repo2': '/b/'}) @@ -149,6 +159,20 @@ def test_superman(mock_run, _, input): mock_run.assert_called_once_with(expected_cmds, cwd='path7') +@pytest.mark.parametrize('input', [ + 'diff --name-only --staged', + "commit -am 'lala kaka'", +]) +@patch('gita.utils.get_repos', return_value={'repo7': 'path7'}) +@patch('subprocess.run') +def test_shell(mock_run, _, input): + mock_run.reset_mock() + args = ['shell', 'repo7'] + shlex.split(input) + __main__.main(args) + expected_cmds = shlex.split(input) + mock_run.assert_called_once_with(expected_cmds, cwd='path7', check=True, stderr=-2, stdout=-1) + + class TestContext: @patch('gita.utils.get_context', return_value=None) @@ -273,6 +297,19 @@ class TestGroupCmd: mock_write.assert_called_once_with( {'xx': ['a', 'b', 'c'], 'yy': ['a', 'c', 'd']}, 'w') + @patch('gita.utils.get_repos', return_value={'a': '', 'b': '', 'c': '', 'd': ''}) + @patch('gita.common.get_config_fname', return_value=GROUP_FNAME) + @patch('gita.utils.write_to_groups_file') + def testRmRepo(self, mock_write, *_): + args = argparse.Namespace() + args.from_group = ['a', 'c'] + args.group_cmd = 'rmrepo' + args.gname = 'xx' + utils.get_groups.cache_clear() + __main__.f_group(args) + mock_write.assert_called_once_with( + {'xx': ['b'], 'yy': ['a', 'c', 'd']}, 'w') + @patch('gita.utils.is_git', return_value=True) @patch('gita.common.get_config_fname', return_value=PATH_FNAME) -- cgit v1.2.3