summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/mock_group_file4
-rw-r--r--tests/test_main.py68
-rw-r--r--tests/test_utils.py17
3 files changed, 32 insertions, 57 deletions
diff --git a/tests/mock_group_file b/tests/mock_group_file
index 1187366..d0d950c 100644
--- a/tests/mock_group_file
+++ b/tests/mock_group_file
@@ -1,2 +1,2 @@
-xx:a b
-yy:a c d
+xx:a b
+yy:a c d
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'}
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 39430b0..3ff0cb1 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -11,7 +11,7 @@ from conftest import (
@pytest.mark.parametrize('repo_path, paths, expected', [
- ('/a/b/c/repo', ['/a/b'], ('b', 'c')),
+ ('/a/b/c/repo', ['/a/b'], (('b', 'c'), '/a')),
])
def test_generate_dir_hash(repo_path, paths, expected):
got = utils._generate_dir_hash(repo_path, paths)
@@ -20,11 +20,13 @@ def test_generate_dir_hash(repo_path, paths, expected):
@pytest.mark.parametrize('repos, paths, expected', [
({'r1': {'path': '/a/b//repo1'}, 'r2': {'path': '/a/b/repo2'}},
- ['/a/b'], {'b': ['r1', 'r2']}),
+ ['/a/b'], {'b': {'repos': ['r1', 'r2'], 'path': '/a/b'}}),
({'r1': {'path': '/a/b//repo1'}, 'r2': {'path': '/a/b/c/repo2'}},
- ['/a/b'], {'b': ['r1', 'r2'], 'b-c': ['r2']}),
+ ['/a/b'], {'b': {'repos': ['r1', 'r2'], 'path': '/a/b'},
+ 'b-c': {'repos': ['r2'], 'path': "/a/b/c"}}),
({'r1': {'path': '/a/b/c/repo1'}, 'r2': {'path': '/a/b/c/repo2'}},
- ['/a/b'], {'b-c': ['r1', 'r2'], 'b': ['r1', 'r2']}),
+ ['/a/b'], {'b-c': {'repos': ['r1', 'r2'], 'path': '/a/b/c'},
+ 'b': {'path': '/a/b', 'repos': ['r1', 'r2']}}),
])
def test_auto_group(repos, paths, expected):
got = utils.auto_group(repos, paths)
@@ -46,8 +48,8 @@ def test_describe(test_input, diff_return, expected, monkeypatch):
monkeypatch.setattr(info, 'get_commit_time', lambda *_: "xx")
monkeypatch.setattr(info, 'has_untracked', lambda *_: True)
monkeypatch.setattr('os.chdir', lambda x: None)
- print('expected: ', repr(expected))
- print('got: ', repr(next(utils.describe(*test_input))))
+
+ info.get_color_encoding.cache_clear() # avoid side effect
assert expected == next(utils.describe(*test_input))
@@ -83,7 +85,8 @@ def test_get_context(mock_config_dir):
@pytest.mark.parametrize('group_fname, expected', [
- (GROUP_FNAME, {'xx': ['a', 'b'], 'yy': ['a', 'c', 'd']}),
+ (GROUP_FNAME, {'xx': {'repos': ['a', 'b'], 'path': ''},
+ 'yy': {'repos': ['a', 'c', 'd'], 'path': ''}}),
])
@patch('gita.common.get_config_fname')
def test_get_groups(mock_group_fname, group_fname, expected):