diff --git a/gita/__main__.py b/gita/__main__.py index fec01b3..b02d16a 100644 --- a/gita/__main__.py +++ b/gita/__main__.py @@ -58,8 +58,7 @@ def f_rm(args: argparse.Namespace): repos = utils.get_repos() for repo in args.repo: del repos[repo] - with open(path_file, 'w') as f: - f.write(os.pathsep.join(repos.values())) + utils.write_to_repo_file(repos, 'w') def f_git_cmd(args: argparse.Namespace): diff --git a/gita/utils.py b/gita/utils.py index 5978f51..bb516f1 100644 --- a/gita/utils.py +++ b/gita/utils.py @@ -96,10 +96,10 @@ def rename_repo(repos: Dict[str, str], repo: str, new_name: str): path = repos[repo] del repos[repo] repos[new_name] = path - _write_to_repo_file(repos, 'w') + write_to_repo_file(repos, 'w') -def _write_to_repo_file(repos: Dict[str, str], mode: str): +def write_to_repo_file(repos: Dict[str, str], mode: str): """ """ data = ''.join(f'{path},{name}\n' for name, path in repos.items()) @@ -121,7 +121,7 @@ def add_repos(repos: Dict[str, str], new_paths: List[str]): new_repos = { os.path.basename(os.path.normpath(path)): path for path in new_paths} - _write_to_repo_file(new_repos, 'a+') + write_to_repo_file(new_repos, 'a+') else: print('No new repos found!') diff --git a/setup.py b/setup.py index e1ba09d..ab38aad 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='gita', packages=['gita'], - version='0.9.8', + version='0.9.9', license='MIT', description='Manage multiple git repos', long_description=long_description, diff --git a/tests/test_main.py b/tests/test_main.py index b64ac99..19f7cd5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,5 +1,5 @@ import pytest -from unittest.mock import patch, mock_open +from unittest.mock import patch import argparse import shlex @@ -77,14 +77,12 @@ def testWithPathFiles(self, mock_path_fname, _0, _1, _2, _3, path_fname, @patch('os.path.isfile', return_value=True) @patch('gita.utils.get_path_fname', return_value='some path') @patch('gita.utils.get_repos', return_value={'repo1': '/a/', 'repo2': '/b/'}) -def test_rm(*_): +@patch('gita.utils.write_to_repo_file') +def test_rm(mock_write, *_): args = argparse.Namespace() args.repo = ['repo1'] - with patch('builtins.open', mock_open()) as mock_file: - __main__.f_rm(args) - mock_file.assert_called_with('some path', 'w') - handle = mock_file() - handle.write.assert_called_once_with('/b/') + __main__.f_rm(args) + mock_write.assert_called_once_with({'repo2': '/b/'}, 'w') def test_not_add(): diff --git a/tests/test_utils.py b/tests/test_utils.py index 4c4c099..98febdd 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -95,7 +95,7 @@ def test_add_repos(_0, _1, path_input, expected, monkeypatch): assert not kwargs -@patch('gita.utils._write_to_repo_file') +@patch('gita.utils.write_to_repo_file') def test_rename_repo(mock_write): utils.rename_repo({'r1': '/a/b', 'r2': '/c/c'}, 'r2', 'xxx') mock_write.assert_called_once_with({'r1': '/a/b', 'xxx': '/c/c'}, 'w')