summaryrefslogtreecommitdiffstats
path: root/tests/test_main.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_main.py')
-rw-r--r--tests/test_main.py68
1 files changed, 20 insertions, 48 deletions
diff --git a/tests/test_main.py b/tests/test_main.py
index d000e1a..b39ed47 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -26,7 +26,6 @@ class TestAdd:
@pytest.mark.parametrize('input, expected', [
(['add', '.'], ''),
- (['add', '-m', '.'], 'm'),
])
@patch('gita.common.get_config_fname')
def test_add(self, mock_path_fname, tmp_path, input, expected):
@@ -40,35 +39,6 @@ class TestAdd:
assert len(got) == 1
assert got['gita']['type'] == expected
- @patch('gita.utils.is_git', return_value=True)
- def test_add_main(self, _, tmp_path, monkeypatch, tmpdir):
- def side_effect(root=None):
- if root is None:
- return os.path.join(tmp_path, "gita")
- else:
- return os.path.join(root, ".gita")
-
- def desc(repos, **_):
- print(len(repos), repos.keys())
- assert len(repos) > 0
- for r, prop in repos.items():
- if prop['type'] == 'm':
- assert 'test_add_main' in r
- break
- else:
- assert 0, 'no main repo found'
- return ''
-
- monkeypatch.setattr(common, 'get_config_dir', side_effect)
- monkeypatch.setattr(utils, 'describe', desc)
-
- utils.get_repos.cache_clear()
-
- with tmpdir.as_cwd():
- __main__.main(['add', '-m', '.'])
- utils.get_repos.cache_clear()
- __main__.main(['ll'])
-
@pytest.mark.parametrize('path_fname, expected', [
(PATH_FNAME, ''),
@@ -293,14 +263,14 @@ def test_shell(mock_run, _, input):
class TestContext:
@patch('gita.utils.get_context', return_value=None)
- def testDisplayNoContext(self, _, capfd):
+ def test_display_no_context(self, _, capfd):
__main__.main(['context'])
out, err = capfd.readouterr()
assert err == ''
assert 'Context is not set\n' == out
@patch('gita.utils.get_context', return_value=Path('gname.context'))
- @patch('gita.utils.get_groups', return_value={'gname': ['a', 'b']})
+ @patch('gita.utils.get_groups', return_value={'gname': {'repos': ['a', 'b']}})
def test_display_context(self, _, __, capfd):
__main__.main(['context'])
out, err = capfd.readouterr()
@@ -353,7 +323,7 @@ class TestGroupCmd:
__main__.f_group(args)
out, err = capfd.readouterr()
assert err == ''
- assert 'xx: a b\nyy: a c d\n' == out
+ assert out == '\x1b[4mxx\x1b[0m: \n - a\n - b\n\x1b[4myy\x1b[0m: \n - a\n - c\n - d\n'
@patch('gita.common.get_config_fname', return_value=GROUP_FNAME)
def test_ll_with_group(self, _, capfd):
@@ -376,21 +346,19 @@ class TestGroupCmd:
args.group_cmd = 'rename'
utils.get_groups.cache_clear()
__main__.f_group(args)
- expected = {'yy': ['a', 'c', 'd'], 'zz': ['a', 'b']}
+ expected = {'yy': {'repos': ['a', 'c', 'd'], 'path': ''},
+ 'zz': {'repos': ['a', 'b'], 'path': ''}}
mock_write.assert_called_once_with(expected, 'w')
+ @patch('gita.info.get_color_encoding', return_value=info.default_colors)
@patch('gita.common.get_config_fname', return_value=GROUP_FNAME)
def test_rename_error(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)
+ with pytest.raises(SystemExit, match="1"):
+ __main__.main('group rename xx yy'.split())
@pytest.mark.parametrize('input, expected', [
- ('xx', {'yy': ['a', 'c', 'd']}),
+ ('xx', {'yy': {'repos': ['a', 'c', 'd'], 'path': ''}}),
("xx yy", {}),
])
@patch('gita.utils.get_repos', return_value={'a': '', 'b': '', 'c': '', 'd': ''})
@@ -412,7 +380,8 @@ class TestGroupCmd:
args.gname = 'zz'
utils.get_groups.cache_clear()
__main__.f_group(args)
- mock_write.assert_called_once_with({'zz': ['a', 'c']}, 'a+')
+ mock_write.assert_called_once_with(
+ {'zz': {'repos': ['a', 'c'], 'path': ''}}, 'a+')
@patch('gita.utils.get_repos', return_value={'a': '', 'b': '', 'c': '', 'd': ''})
@patch('gita.common.get_config_fname', return_value=GROUP_FNAME)
@@ -425,20 +394,22 @@ class TestGroupCmd:
utils.get_groups.cache_clear()
__main__.f_group(args)
mock_write.assert_called_once_with(
- {'xx': ['a', 'b', 'c'], 'yy': ['a', 'c', 'd']}, 'w')
+ {'xx': {'repos': ['a', 'b', 'c'], 'path': ''},
+ 'yy': {'repos': ['a', 'c', 'd'], 'path': ''}}, '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 test_rm_repo(self, mock_write, *_):
args = argparse.Namespace()
- args.from_group = ['a', 'c']
+ 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': ['b'], 'yy': ['a', 'c', 'd']}, 'w')
+ {'xx': {'repos': ['b'], 'path': ''},
+ 'yy': {'repos': ['a', 'c', 'd'], 'path': ''}}, 'w')
@patch('gita.common.get_config_fname')
def test_integration(self, mock_path_fname, tmp_path, capfd):
@@ -510,15 +481,16 @@ class TestInfo:
def test_set_color(mock_get_fname, tmpdir):
args = argparse.Namespace()
args.color_cmd = 'set'
- args.color = 'redrum' # this color doesn't exist
- args.situation = 'in-sync'
+ args.color = 'b_white'
+ args.situation = 'no-remote'
with tmpdir.as_cwd():
csv_config = Path.cwd() / 'colors.csv'
mock_get_fname.return_value = csv_config
__main__.f_color(args)
+
info.get_color_encoding.cache_clear() # avoid side effect
items = info.get_color_encoding()
info.get_color_encoding.cache_clear() # avoid side effect
- assert items == {'no-remote': 'white', 'in-sync': 'redrum',
+ assert items == {'no-remote': 'b_white', 'in-sync': 'green',
'diverged': 'red', 'local-ahead': 'purple',
'remote-ahead': 'yellow'}