diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 9 | ||||
-rw-r--r-- | tests/test_info.py | 7 | ||||
-rw-r--r-- | tests/test_main.py | 9 | ||||
-rw-r--r-- | tests/test_utils.py | 8 |
4 files changed, 19 insertions, 14 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index b3e59ed..5236a90 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,10 +8,11 @@ def fullpath(fname: str): return str(TEST_DIR / fname) -PATH_FNAME = fullpath('mock_path_file') -PATH_FNAME_EMPTY = fullpath('empty_path_file') -PATH_FNAME_CLASH = fullpath('clash_path_file') -GROUP_FNAME = fullpath('mock_group_file') +PATH_FNAME = fullpath("mock_path_file") +PATH_FNAME_EMPTY = fullpath("empty_path_file") +PATH_FNAME_CLASH = fullpath("clash_path_file") +GROUP_FNAME = fullpath("mock_group_file") + def async_mock(): """ diff --git a/tests/test_info.py b/tests/test_info.py index c234d78..0af8a47 100644 --- a/tests/test_info.py +++ b/tests/test_info.py @@ -4,13 +4,14 @@ from unittest.mock import patch, MagicMock from gita import info -@patch('subprocess.run') +@patch("subprocess.run") def test_run_quiet_diff(mock_run): mock_return = MagicMock() mock_run.return_value = mock_return - got = info.run_quiet_diff(['--flags'], ['my', 'args']) + got = info.run_quiet_diff(["--flags"], ["my", "args"], "/a/b/c") mock_run.assert_called_once_with( - ['git', '--flags', 'diff', '--quiet', 'my', 'args'], + ["git", "--flags", "diff", "--quiet", "my", "args"], stderr=subprocess.DEVNULL, + cwd="/a/b/c", ) assert got == mock_return.returncode diff --git a/tests/test_main.py b/tests/test_main.py index 0f2eeb5..441c14a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -71,6 +71,7 @@ class TestLsLl: """ functional test """ + # avoid modifying the local configuration def side_effect(input, _=None): return tmp_path / f"{input}.txt" @@ -129,12 +130,12 @@ class TestLsLl: [ ( PATH_FNAME, - "repo1 cmaster dsu\x1b[0m msg \nrepo2 cmaster dsu\x1b[0m msg \nxxx cmaster dsu\x1b[0m msg \n", + "repo1 cmaster [dsu] \x1b[0m msg \nrepo2 cmaster [dsu] \x1b[0m msg \nxxx cmaster [dsu] \x1b[0m msg \n", ), (PATH_FNAME_EMPTY, ""), ( PATH_FNAME_CLASH, - "repo1 cmaster dsu\x1b[0m msg \nrepo2 cmaster dsu\x1b[0m msg \n", + "repo1 cmaster [dsu] \x1b[0m msg \nrepo2 cmaster [dsu] \x1b[0m msg \n", ), ], ) @@ -527,7 +528,9 @@ class TestInfo: args.info_cmd = None __main__.f_info(args) out, err = capfd.readouterr() - assert "In use: branch,commit_msg,commit_time\nUnused: path\n" == out + assert ( + "In use: branch,commit_msg,commit_time\nUnused: branch_name,path\n" == out + ) assert err == "" @patch("gita.common.get_config_fname") diff --git a/tests/test_utils.py b/tests/test_utils.py index 9679116..acf9853 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -115,17 +115,17 @@ def test_auto_group(repos, paths, expected): ( [{"abc": {"path": "/root/repo/", "type": "", "flags": []}}, False], True, - "abc \x1b[31mrepo *+_ \x1b[0m msg xx", + "abc \x1b[31mrepo [*+?] \x1b[0m msg xx", ), ( [{"abc": {"path": "/root/repo/", "type": "", "flags": []}}, True], True, - "abc repo *+_ msg xx", + "abc repo [*+?] msg xx", ), ( [{"repo": {"path": "/root/repo2/", "type": "", "flags": []}}, False], False, - "repo \x1b[32mrepo _ \x1b[0m msg xx", + "repo \x1b[32mrepo [?] \x1b[0m msg xx", ), ], ) @@ -135,7 +135,7 @@ def test_describe(test_input, diff_return, expected, monkeypatch): monkeypatch.setattr(info, "get_commit_msg", lambda *_: "msg") monkeypatch.setattr(info, "get_commit_time", lambda *_: "xx") monkeypatch.setattr(info, "has_untracked", lambda *_: True) - monkeypatch.setattr("os.chdir", lambda x: None) + monkeypatch.setattr(info, "get_common_commit", lambda x: "") info.get_color_encoding.cache_clear() # avoid side effect assert expected == next(utils.describe(*test_input)) |