summaryrefslogtreecommitdiffstats
path: root/tests/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 3128041..886ddb9 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -4,17 +4,14 @@ from unittest.mock import patch, mock_open
from gita import utils, info
from conftest import (
- PATH_FNAME, PATH_FNAME_EMPTY, PATH_FNAME_CLASH, GROUP_FNAME,
+ PATH_FNAME, PATH_FNAME_EMPTY, PATH_FNAME_CLASH, GROUP_FNAME, TEST_DIR,
)
@pytest.mark.parametrize('test_input, diff_return, expected', [
- ({
- 'abc': '/root/repo/'
- }, True, 'abc \x1b[31mrepo *+_ \x1b[0m msg'),
- ({
- 'repo': '/root/repo2/'
- }, False, 'repo \x1b[32mrepo _ \x1b[0m msg'),
+ ([{'abc': '/root/repo/'}, False], True, 'abc \x1b[31mrepo *+_ \x1b[0m msg'),
+ ([{'abc': '/root/repo/'}, True], True, 'abc repo *+_ msg'),
+ ([{'repo': '/root/repo2/'}, False], False, 'repo \x1b[32mrepo _ \x1b[0m msg'),
])
def test_describe(test_input, diff_return, expected, monkeypatch):
monkeypatch.setattr(info, 'get_head', lambda x: 'repo')
@@ -23,8 +20,8 @@ def test_describe(test_input, diff_return, expected, monkeypatch):
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))))
- assert expected == next(utils.describe(test_input))
+ print('got: ', repr(next(utils.describe(*test_input))))
+ assert expected == next(utils.describe(*test_input))
@pytest.mark.parametrize('path_fname, expected', [
@@ -41,17 +38,28 @@ def test_describe(test_input, diff_return, expected, monkeypatch):
}),
])
@patch('gita.utils.is_git', return_value=True)
-@patch('gita.utils.get_config_fname')
+@patch('gita.common.get_config_fname')
def test_get_repos(mock_path_fname, _, path_fname, expected):
mock_path_fname.return_value = path_fname
utils.get_repos.cache_clear()
assert utils.get_repos() == expected
+@patch('gita.common.get_config_dir')
+def test_get_context(mock_config_dir):
+ mock_config_dir.return_value = TEST_DIR
+ utils.get_context.cache_clear()
+ assert utils.get_context() == TEST_DIR / 'xx.context'
+
+ mock_config_dir.return_value = '/'
+ utils.get_context.cache_clear()
+ assert utils.get_context() == None
+
+
@pytest.mark.parametrize('group_fname, expected', [
(GROUP_FNAME, {'xx': ['a', 'b'], 'yy': ['a', 'c', 'd']}),
])
-@patch('gita.utils.get_config_fname')
+@patch('gita.common.get_config_fname')
def test_get_groups(mock_group_fname, group_fname, expected):
mock_group_fname.return_value = group_fname
utils.get_groups.cache_clear()