From 52e09365241c3b17ae6f411a9bfdefcd3b1a9409 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 31 Oct 2021 21:28:27 +0100 Subject: [PATCH] Add unit test for git integration tests/test_git.py: Add unit test for `git_changed_files()`. --- tests/test_git.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/test_git.py diff --git a/tests/test_git.py b/tests/test_git.py new file mode 100644 index 0000000..13b204e --- /dev/null +++ b/tests/test_git.py @@ -0,0 +1,45 @@ +from pathlib import Path +from typing import List +from typing import Optional +from unittest.mock import Mock +from unittest.mock import patch + +from pytest import mark + +from libkeyringctl import git + + +@mark.parametrize( + "git_path, base, paths", + [ + (None, None, None), + (Path("git_path"), None, None), + (Path("git_path"), "base", None), + (Path("git_path"), "base", [Path("foo"), Path("bar")]), + ], +) +@patch("libkeyringctl.git.system") +def test_git_changed_files( + system_mock: Mock, + git_path: Optional[Path], + base: Optional[str], + paths: Optional[List[Path]], +) -> None: + system_mock.return_value = "create some thing foo\n" "delete some thing bar\n" "some thing baz\n" + + assert git.git_changed_files(git_path=git_path, base=base, paths=paths) == ( + [Path("foo")], + [Path("bar")], + [Path("baz")], + ) + + name, args, kwargs = system_mock.mock_calls[0] + if git_path: + assert "-C" in args[0] + assert str(git_path) in args[0] + if base: + assert base in args[0] + if paths: + assert "--" in args[0] + for path in paths: + assert str(path) in args[0]