Skip to content

Commit

Permalink
fix rm issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nosarthur committed Jun 14, 2019
1 parent 302274f commit 80c52f9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
3 changes: 1 addition & 2 deletions gita/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions gita/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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!')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 5 additions & 7 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from unittest.mock import patch, mock_open
from unittest.mock import patch
import argparse
import shlex

Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 80c52f9

Please sign in to comment.