live fixes

also rename branches to has_remotes method and change return type
This commit is contained in:
2021-10-12 21:11:48 +03:00
parent 8d95ac5e9f
commit ea9c031e0c
4 changed files with 40 additions and 39 deletions

View File

@ -168,8 +168,9 @@ def test_add_local(application: Application, package_ahriman: Package, mocker: M
application.add([package_ahriman.base], PackageSource.Local, True)
init_mock.assert_called_once()
copytree_mock.assert_has_calls([
mock.call(Path(package_ahriman.base), application.repository.paths.manual_for(package_ahriman.base)),
mock.call(Path(package_ahriman.base), application.repository.paths.cache_for(package_ahriman.base)),
mock.call(application.repository.paths.cache_for(package_ahriman.base),
application.repository.paths.manual_for(package_ahriman.base)),
])
@ -321,7 +322,7 @@ def test_unknown_no_aur(application: Application, package_ahriman: Package, mock
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman])
mocker.patch("ahriman.models.package.Package.from_aur", side_effect=Exception())
mocker.patch("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.branches", return_value=[])
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", return_value=False)
assert not application.unknown()

View File

@ -22,26 +22,6 @@ def test_add(mocker: MockerFixture) -> None:
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
def test_branches(mocker: MockerFixture) -> None:
"""
must ask for available branches
"""
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="b\na")
local = Path("local")
branches = Sources.branches(local)
check_output_mock.assert_called_with("git", "branch", exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
assert branches == ["a", "b"]
def test_branches_empty(mocker: MockerFixture) -> None:
"""
must ask for available branches and do not fail if no branches found
"""
mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="")
assert Sources.branches(Path("local")) == []
def test_diff(mocker: MockerFixture) -> None:
"""
must calculate diff
@ -60,7 +40,7 @@ def test_fetch_empty(mocker: MockerFixture) -> None:
must do nothing in case if no branches available
"""
mocker.patch("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.branches", return_value=[])
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", return_value=False)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
Sources.fetch(Path("local"), "remote")
@ -72,7 +52,7 @@ def test_fetch_existing(mocker: MockerFixture) -> None:
must fetch new package via fetch command
"""
mocker.patch("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.branches", return_value=["master"])
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", return_value=True)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
local = Path("local")
@ -105,6 +85,25 @@ def test_fetch_new(mocker: MockerFixture) -> None:
])
def test_has_remotes(mocker: MockerFixture) -> None:
"""
must ask for remotes
"""
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="origin")
local = Path("local")
assert Sources.has_remotes(local)
check_output_mock.assert_called_with("git", "remote", exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
def test_has_remotes_empty(mocker: MockerFixture) -> None:
"""
must ask for remotes and return false in case if no remotes found
"""
mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="")
assert not Sources.has_remotes(Path("local"))
def test_init(mocker: MockerFixture) -> None:
"""
must create empty repository at the specified path