示例#1
0
def test_flags(mock_path_fname, _, __, path_fname, expected, capfd):
    mock_path_fname.return_value = path_fname
    utils.get_repos.cache_clear()
    __main__.main(["flags"])
    out, err = capfd.readouterr()
    assert err == ""
    assert out == expected
示例#2
0
def test_freeze(mock_repos, mock_run, input, expected, capfd):
    mock_repos.return_value = input
    __main__.main(["freeze"])
    assert mock_run.call_count == 2
    out, err = capfd.readouterr()
    assert err == ""
    assert out == expected
示例#3
0
def test_shell(mock_run, _, input):
    mock_run.reset_mock()
    args = ["shell", "repo7", input]
    __main__.main(args)
    expected_cmds = input
    mock_run.assert_called_once_with(
        expected_cmds, cwd="path7", shell=True, stderr=-2, stdout=-1
    )
示例#4
0
文件: test_main.py 项目: nwu63/gita
def test_rename(mock_rename, _, __):
    utils.get_repos.cache_clear()
    args = ['rename', 'repo1', 'abc']
    __main__.main(args)
    mock_rename.assert_called_once_with(
        {'repo1': '/a/bcd/repo1', 'repo2': '/e/fgh/repo2',
            'xxx': '/a/b/c/repo3'},
        'repo1', 'abc')
示例#5
0
文件: test_main.py 项目: nwu63/gita
def test_async_fetch(*_):
    __main__.main(['fetch'])
    mock_run = utils.run_async.mock
    assert mock_run.call_count == 2
    cmds = ['git', 'fetch']
    # print(mock_run.call_args_list)
    mock_run.assert_any_call('repo1', '/a/bc', cmds)
    mock_run.assert_any_call('repo2', '/d/efg', cmds)
示例#6
0
 def testWithPathFiles(self, mock_path_fname, _0, _1, _2, _3, path_fname,
                       expected, capfd):
     mock_path_fname.return_value = path_fname
     utils.get_repos.cache_clear()
     __main__.main(['ll'])
     out, err = capfd.readouterr()
     assert err == ''
     assert out == expected
示例#7
0
def test_async_fetch(*_):
    __main__.main(["fetch"])
    mock_run = utils.run_async.mock
    assert mock_run.call_count == 2
    cmds = ["git", "fetch"]
    # print(mock_run.call_args_list)
    mock_run.assert_any_call("repo1", "/a/bc", cmds)
    mock_run.assert_any_call("repo2", "/d/efg", cmds)
示例#8
0
文件: test_main.py 项目: lanquil/gita
 def testAdd(self, mock_path_fname, tmp_path, input, expected):
     def side_effect(input, _=None):
         return tmp_path / f'{input}.txt'
     mock_path_fname.side_effect = side_effect
     utils.get_repos.cache_clear()
     __main__.main(input)
     utils.get_repos.cache_clear()
     got = utils.get_repos()
     assert len(got) == 1
     assert got['gita']['type'] == expected
示例#9
0
文件: test_main.py 项目: ya-ty/gita
def test_shell(mock_run, _, input):
    mock_run.reset_mock()
    args = ['shell', 'repo7', input]
    __main__.main(args)
    expected_cmds = input
    mock_run.assert_called_once_with(expected_cmds,
                                     cwd='path7',
                                     check=True,
                                     shell=True,
                                     stderr=-2,
                                     stdout=-1)
示例#10
0
文件: test_main.py 项目: nwu63/gita
 def testLs(self, monkeypatch, capfd):
     monkeypatch.setattr(utils, 'get_repos',
             lambda: {'repo1': '/a/', 'repo2': '/b/'})
     monkeypatch.setattr(utils, 'describe', lambda x: x)
     __main__.main(['ls'])
     out, err = capfd.readouterr()
     assert err == ''
     assert out == "repo1 repo2\n"
     __main__.main(['ls', 'repo1'])
     out, err = capfd.readouterr()
     assert err == ''
     assert out == '/a/\n'
示例#11
0
def test_rename(mock_rename, _, __):
    utils.get_repos.cache_clear()
    args = ["rename", "repo1", "abc"]
    __main__.main(args)
    mock_rename.assert_called_once_with(
        {
            "repo1": {"path": "/a/bcd/repo1", "type": "", "flags": []},
            "xxx": {"path": "/a/b/c/repo3", "type": "", "flags": []},
            "repo2": {"path": "/e/fgh/repo2", "type": "", "flags": []},
        },
        "repo1",
        "abc",
    )
示例#12
0
文件: test_main.py 项目: nwu63/gita
 def testWithPathFiles(self, mock_path_fname, _0, _1, _2, _3, path_fname,
                       expected, capfd):
     def side_effect(input):
         if input == 'repo_path':
             return path_fname
         return f'/{input}'
     mock_path_fname.side_effect = side_effect
     utils.get_repos.cache_clear()
     __main__.main(['ll'])
     out, err = capfd.readouterr()
     print(out)
     assert err == ''
     assert out == expected
示例#13
0
    def testLl(self, mock_path_fname, capfd, tmp_path):
        """ functional test """
        # avoid modifying the local configuration
        mock_path_fname.return_value = tmp_path / 'path_config.txt'
        __main__.main(['add', '.'])
        out, err = capfd.readouterr()
        assert err == ''
        assert 'Found 1 new repo(s).\n' == out

        # in production this is not needed
        utils.get_repos.cache_clear()

        __main__.main(['ls'])
        out, err = capfd.readouterr()
        assert err == ''
        assert 'gita\n' == out

        __main__.main(['ll'])
        out, err = capfd.readouterr()
        assert err == ''
        assert 'gita' in out

        __main__.main(['ls', 'gita'])
        out, err = capfd.readouterr()
        assert err == ''
        assert out.strip() == utils.get_repos()['gita']
示例#14
0
 def test_ls(self, monkeypatch, capfd):
     monkeypatch.setattr(
         utils,
         "get_repos",
         lambda: {"repo1": {"path": "/a/"}, "repo2": {"path": "/b/"}},
     )
     monkeypatch.setattr(utils, "describe", lambda x: x)
     __main__.main(["ls"])
     out, err = capfd.readouterr()
     assert err == ""
     assert out == "repo1 repo2\n"
     __main__.main(["ls", "repo1"])
     out, err = capfd.readouterr()
     assert err == ""
     assert out == "/a/\n"
示例#15
0
    def test_with_path_files(
        self, mock_path_fname, _0, _1, _2, _3, _4, path_fname, expected, capfd
    ):
        def side_effect(input, _=None):
            if input == "repos.csv":
                return path_fname
            return f"/{input}"

        mock_path_fname.side_effect = side_effect
        utils.get_repos.cache_clear()
        __main__.main(["ll"])
        out, err = capfd.readouterr()
        print(out)
        assert err == ""
        assert out == expected
示例#16
0
def test_clear(
    mock_repos,
    mock_write_to_repo_file,
    mock_write_to_groups_file,
    input,
    expected,
    capfd,
):
    mock_repos.return_value = input
    __main__.main(["clear"])
    assert mock_write_to_repo_file.call_count == 1
    mock_write_to_repo_file.assert_called_once_with({}, "w")
    assert mock_write_to_groups_file.call_count == 1
    mock_write_to_groups_file.assert_called_once_with({}, "w")
    out, err = capfd.readouterr()
    assert err == ""
    assert out == expected
示例#17
0
文件: test_main.py 项目: tmack0/gita
    def testLl(self, mock_path_fname, capfd, tmp_path):
        """
        functional test
        """

        # avoid modifying the local configuration
        def side_effect(input):
            return tmp_path / f'{input}.txt'

        #mock_path_fname.return_value = tmp_path / 'path_config.txt'
        mock_path_fname.side_effect = side_effect
        __main__.main(['add', '.'])
        out, err = capfd.readouterr()
        assert err == ''
        assert 'Found 1 new repo(s).\n' == out

        # in production this is not needed
        utils.get_repos.cache_clear()

        __main__.main(['ls'])
        out, err = capfd.readouterr()
        assert err == ''
        assert 'gita\n' == out

        __main__.main(['ll'])
        out, err = capfd.readouterr()
        assert err == ''
        assert 'gita' in out
        assert info.Color.end in out

        # no color on branch name
        __main__.main(['ll', '-C'])
        out, err = capfd.readouterr()
        assert err == ''
        assert 'gita' in out
        assert info.Color.end not in out

        __main__.main(['ls', 'gita'])
        out, err = capfd.readouterr()
        assert err == ''
        assert out.strip() == utils.get_repos()['gita']
示例#18
0
    def test_ll(self, mock_path_fname, capfd, tmp_path):
        """
        functional test
        """
        # avoid modifying the local configuration
        def side_effect(input, _=None):
            return tmp_path / f"{input}.txt"

        mock_path_fname.side_effect = side_effect
        utils.get_repos.cache_clear()
        __main__.main(["add", "."])
        out, err = capfd.readouterr()
        assert err == ""
        assert "Found 1 new repo(s).\n" == out

        # in production this is not needed
        utils.get_repos.cache_clear()

        __main__.main(["ls"])
        out, err = capfd.readouterr()
        assert err == ""
        assert "gita\n" == out

        __main__.main(["ll"])
        out, err = capfd.readouterr()
        assert err == ""
        assert "gita" in out
        assert info.Color.end in out

        # no color on branch name
        __main__.main(["ll", "-C"])
        out, err = capfd.readouterr()
        assert err == ""
        assert "gita" in out
        assert info.Color.end not in out

        __main__.main(["ls", "gita"])
        out, err = capfd.readouterr()
        assert err == ""
        assert out.strip() == utils.get_repos()["gita"]["path"]
示例#19
0
    def test_integration(self, mock_path_fname, tmp_path, capfd):
        def side_effect(input, _=None):
            return tmp_path / f"{input}.csv"

        mock_path_fname.side_effect = side_effect

        __main__.main("add .".split())
        utils.get_repos.cache_clear()
        __main__.main("group add gita -n test".split())
        utils.get_groups.cache_clear()
        __main__.main("ll test".split())
        out, err = capfd.readouterr()
        assert err == ""
        assert "gita" in out
示例#20
0
 def test_display_no_context(self, _, capfd):
     __main__.main(["context"])
     out, err = capfd.readouterr()
     assert err == ""
     assert "Context is not set\n" == out
示例#21
0
def test_not_add():
    # this won't write to disk because the repo is not valid
    __main__.main(["add", "/home/some/repo/"])
示例#22
0
 def test_rename_error(self, *_):
     utils.get_groups.cache_clear()
     with pytest.raises(SystemExit, match="1"):
         __main__.main("group rename xx yy".split())
示例#23
0
 def test_rm(self, mock_write, _, __, input, expected):
     utils.get_groups.cache_clear()
     args = ["group", "rm"] + shlex.split(input)
     __main__.main(args)
     mock_write.assert_called_once_with(expected, "w")
示例#24
0
 def test_set_second_time(self, mock_ctx, *_):
     __main__.main(["context", "kaka"])
     mock_ctx.return_value.rename.assert_called()
示例#25
0
 def test_set_first_time(self, *_):
     ctx = TEST_DIR / "lala.context"
     assert not ctx.is_file()
     __main__.main(["context", "lala"])
     assert ctx.is_file()
     ctx.unlink()
示例#26
0
 def test_reset(self, mock_ctx):
     __main__.main(["context", "none"])
     mock_ctx.return_value.unlink.assert_called()
示例#27
0
def test_fetch(mock_run, *_):
    asyncio.set_event_loop(asyncio.new_event_loop())
    __main__.main(["fetch"])
    mock_run.assert_called_once_with(["git", "fetch"], cwd="/d/efg", shell=False)
示例#28
0
def test_superman(mock_run, _, input):
    mock_run.reset_mock()
    args = ["super", "repo7"] + shlex.split(input)
    __main__.main(args)
    expected_cmds = ["git"] + shlex.split(input)
    mock_run.assert_called_once_with(expected_cmds, cwd="path7", shell=False)
示例#29
0
 def test_display_context(self, _, __, capfd):
     __main__.main(["context"])
     out, err = capfd.readouterr()
     assert err == ""
     assert "gname: a b\n" == out
示例#30
0
文件: test_main.py 项目: nwu63/gita
def test_freeze(_, mock_run, capfd):
    __main__.main(['freeze'])
    assert mock_run.call_count == 2
    out, err = capfd.readouterr()
    assert err == ''
    assert out == ',repo1,/a/\n,repo2,/b/\n'