def test_current_source_key(mocker, pygithub_match):
    mocker.patch("raincoat.source.get_branch_commit",
                 return_value="aaabbbcccdddeeefff")

    assert pygithub.PyGithubChecker().current_source_key(pygithub_match) == (
        "python/cpython", "aaabbbcccdddeeefff")

    assert pygithub_match.branch_commit == "aaabbbcc"
def test_current_source_key_cache(mocker, pygithub_match):
    get_branch_commit = mocker.patch("raincoat.source.get_branch_commit",
                                     return_value="aaabbbcccdddeeefff")

    checker = pygithub.PyGithubChecker()
    a = checker.current_source_key(pygithub_match)
    assert len(get_branch_commit.mock_calls) == 1

    get_branch_commit.reset_mock()

    b = checker.current_source_key(pygithub_match)

    assert get_branch_commit.mock_calls == []
    assert a == b
def test_get_source_installed(mocker):
    download = mocker.patch(
        "raincoat.match.pypi.source.download_files_from_repo",
        return_value={"file_1.py": ["yay"]})

    result = pygithub.PyGithubChecker().get_source(key=pygithub.PyGithubKey(
        "python/cpython", "123abc"),
                                                   files=["file_1.py"])

    assert result == {"file_1.py": ["yay"]}
    assert download.mock_calls == [
        mocker.call(repo="python/cpython",
                    commit="123abc",
                    files=["file_1.py"])
    ]
def test_match_source_key(pygithub_match):

    assert pygithub.PyGithubChecker().match_source_key(pygithub_match) == (
        "python/cpython", "abc123")