def testAdd(self, mock_write, *_): args = argparse.Namespace() args.to_group = ['a', 'c'] args.group_cmd = 'add' args.gname = 'zz' utils.get_groups.cache_clear() __main__.f_group(args) mock_write.assert_called_once_with({'zz': ['a', 'c']}, 'a+')
def testRenameError(self, *_): args = argparse.Namespace() args.gname = 'xx' args.new_name = 'yy' args.group_cmd = 'rename' utils.get_groups.cache_clear() with pytest.raises(SystemExit, match='yy already exists.'): __main__.f_group(args)
def testAdd(self, mock_write, _, __, monkeypatch): args = argparse.Namespace() args.to_group = ['a', 'c'] args.group_cmd = 'add' utils.get_groups.cache_clear() monkeypatch.setattr('builtins.input', lambda _: 'zz') __main__.f_group(args) mock_write.assert_called_once_with({'zz': ['a', 'c']}, 'a+')
def test_group_display(_, capfd): args = argparse.Namespace() args.to_group = None utils.get_groups.cache_clear() __main__.f_group(args) out, err = capfd.readouterr() assert err == '' assert 'xx: a, b\nyy: a, c, d\n' == out
def test_ls(self, _, capfd): args = argparse.Namespace() args.to_group = None args.group_cmd = "ls" utils.get_groups.cache_clear() __main__.f_group(args) out, err = capfd.readouterr() assert err == "" assert "xx yy\n" == out
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')
def testAddToExisting(self, mock_write, *_): args = argparse.Namespace() args.to_group = ['a', 'c'] args.group_cmd = 'add' args.gname = 'xx' utils.get_groups.cache_clear() __main__.f_group(args) mock_write.assert_called_once_with( {'xx': ['a', 'b', 'c'], 'yy': ['a', 'c', 'd']}, 'w')
def testRename(self, mock_write, _): args = argparse.Namespace() args.gname = 'xx' args.new_name = 'zz' args.group_cmd = 'rename' utils.get_groups.cache_clear() __main__.f_group(args) expected = {'yy': ['a', 'c', 'd'], 'zz': ['a', 'b']} mock_write.assert_called_once_with(expected, 'w')
def testLl(self, _, capfd): args = argparse.Namespace() args.to_group = None args.group_cmd = None utils.get_groups.cache_clear() __main__.f_group(args) out, err = capfd.readouterr() assert err == '' assert 'xx: a b\nyy: a c d\n' == out
def test_add(self, mock_write, *_): args = argparse.Namespace() args.to_group = ["a", "c"] args.group_cmd = "add" args.gname = "zz" utils.get_groups.cache_clear() __main__.f_group(args) mock_write.assert_called_once_with( {"zz": {"repos": ["a", "c"], "path": ""}}, "a+" )
def test_ll_with_group(self, _, __, capfd): args = argparse.Namespace() args.to_group = None args.group_cmd = None args.to_show = "yy" utils.get_groups.cache_clear() __main__.f_group(args) out, err = capfd.readouterr() assert err == "" assert "a c d\n" == out
def test_rename(self, mock_write, *_): args = argparse.Namespace() args.gname = "xx" args.new_name = "zz" args.group_cmd = "rename" utils.get_groups.cache_clear() __main__.f_group(args) expected = { "yy": {"repos": ["a", "c", "d"], "path": ""}, "zz": {"repos": ["a", "b"], "path": ""}, } mock_write.assert_called_once_with(expected, "w")
def test_ll(self, _, __, capfd): args = argparse.Namespace() args.to_group = None args.group_cmd = None args.to_show = None utils.get_groups.cache_clear() __main__.f_group(args) out, err = capfd.readouterr() assert err == "" assert ( out == "\x1b[4mxx\x1b[0m: \n - a\n - b\n\x1b[4myy\x1b[0m: \n - a\n - c\n - d\n" )
def test_rm_repo(self, mock_write, *_): args = argparse.Namespace() args.to_rm = ["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": {"repos": ["b"], "path": ""}, "yy": {"repos": ["a", "c", "d"], "path": ""}, }, "w", )