def test_githuborg_getrepos(githuborg_fixture):
    """ Test getting GitHub repos """
    githuborg_mock, _, _ = githuborg_fixture
    githubrepo1 = GitHubRepo('repo1', 'clone_url1', 'ssh_url1')
    githubrepo2 = GitHubRepo('repo2', 'clone_url2', 'ssh_url2')
    githuborg_mock.return_value.get_organization.return_value \
        .get_repos.return_value = [githubrepo1, githubrepo2]
    githuborg = GitHubOrg('org')
    repos = githuborg.get_repos(r'repo1')
    assert repos == {'repo1': githubrepo1}
def test_kodiaddondescriptions_push(gitrepomock):
    """ Test pushing addon descriptions """
    KodiAddonDescriptions('path/repo').push('branch')
    gitrepomock.assert_called_once_with(GitHubRepo('repo', '', ''), 'path')
    gitrepomock.return_value.commit.assert_called_once_with(
        mock.ANY, KodiAddonDescriptions.DESCRIPTION_PATH, force=True)
    gitrepomock.return_value.push.assert_called_once_with('branch')
def test_kodigameaddon_gitrevisionnorepo(kodigameaddon, gitrepomock):
    """ Test loading git revision when not a Git repository """
    gitrepomock.is_git_repo.return_value = False
    kodigameaddon.load_git_revision()
    assert mock.call(GitHubRepo(kodigameaddon.game_name, '', ''), mock.ANY) \
        not in gitrepomock.mock_calls
    assert not kodigameaddon.info['libretro_repo']['hexsha']
def test_kodigameaddon_gitrevision(kodigameaddon, gitrepomock):
    """ Test loading git revision """
    gitrepomock.is_git_repo.return_value = True
    gitrepomock.return_value.get_hexsha.return_value = '1234567'
    kodigameaddon.load_git_revision()
    gitrepomock.assert_has_calls(
        [mock.call(GitHubRepo(kodigameaddon.game_name, '', ''), mock.ANY)])
    assert kodigameaddon.info['libretro_repo']['hexsha'] == '1234567'
def gitrepo_remote(tmpdir):
    """ Setup a git repository serving as remote repository for other tests """
    gitrepo = GitRepo(GitHubRepo('remote-repo', '', ''), str(tmpdir))
    create_file(os.path.join(gitrepo.path, 'upstream-file'))
    gitrepo.commit('Commit upstream-file')
    # Allow pushing into a non-bare repository.
    with open(os.path.join(gitrepo.path, '.git', 'config'), 'a') as gitconfig:
        gitconfig.write('[receive]\ndenyCurrentBranch=updateInstead\n')
    return gitrepo
def test_githuborg_createrepo(githuborg_fixture):
    """ Test creating a repo on GitHub """
    githuborg_mock, _, _ = githuborg_fixture
    githubrepo = GitHubRepo('repo', 'clone_url', 'ssh_url')
    githuborg_mock.return_value.get_organization.return_value \
        .create_repo.return_value = githubrepo
    githuborg = GitHubOrg('org')
    repo = githuborg.create_repo('repo')
    assert repo == githubrepo
def test_gitrepo_local_nohead(tmpdir):
    """ Test operations on an empty git repository (commit/tag noop) """
    gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    gitrepo.fetch_and_reset()
    gitrepo.describe()
    gitrepo.commit('Try to commit without changes')
    gitrepo.tag('tag')
    assert not gitrepo.diff()
    assert not gitrepo.describe()
    assert not gitrepo.get_hexsha()
def test_gitrepo_local_commitsquash(tmpdir):
    """ Test squash commiting to a git repository """
    gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    testfile = os.path.join(gitrepo.path, 'testfile')
    create_file(testfile)
    gitrepo.commit('Commit testfile', squash=True)
    create_file(testfile, 'modified content')
    gitrepo.commit('Commit modified testfile', squash=True)
    assert '/dev/null\n+++ b/{}\n'.format(
        os.path.basename(testfile)) in gitrepo.diff()
def test_libretrosuper_fetchreset(mocker):
    """ Test fetching libretro-super repository """
    gitrepomock = mocker.patch(
        'kodi_game_scripting.libretro_super.GitRepo', autospec=True)
    LibretroSuper('dir').fetch_and_reset()
    gitrepomock.assert_called_once_with(
        GitHubRepo('libretro-super',
                   'https://github.com/libretro/libretro-super.git', ''),
        'dir')
    gitrepomock.return_value.fetch_and_reset.assert_called_once_with()
def test_gitrepo_local_commitdirectory(tmpdir):
    """ Test commiting limited to a directory """
    gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    testfile = os.path.join(gitrepo.path, 'add', 'testfile')
    testfile_ignored = os.path.join(gitrepo.path, 'ignored')
    create_file(testfile)
    create_file(testfile_ignored)
    gitrepo.commit('Commit directory `add`', directory='add')
    gitrepo.fetch_and_reset()
    assert os.path.isfile(testfile)
    assert not os.path.isfile(testfile_ignored)
def test_gitrepo_remote_commitsquash(tmpdir, gitrepo_remote):
    """ Test squash commiting """
    url = 'file://{}'.format(gitrepo_remote.path)
    gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir))
    testfile = os.path.join(gitrepo.path, 'testfile')
    gitrepo.fetch_and_reset()
    create_file(testfile)
    gitrepo.commit('Commit testfile', squash=True)
    create_file(testfile, 'modified content')
    gitrepo.commit('Commit modified testfile', squash=True)
    assert '/dev/null\n+++ b/{}\n'.format(
        os.path.basename(testfile)) in gitrepo.diff()
def test_gitrepo_remote(tmpdir, gitrepo_remote):
    """ Test operations on a git repository with a remote """
    url = 'file://{}'.format(gitrepo_remote.path)
    gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir))
    gitrepo.fetch_and_reset()
    assert not gitrepo.diff()
    assert gitrepo.describe()
    assert gitrepo.get_hexsha()
    testfile = os.path.join(str(tmpdir), 'local-repo', 'testfile')
    create_file(testfile)
    gitrepo.commit('Commit testfile')
    assert gitrepo.diff()
def test_gitrepo_remote_tag(tmpdir, gitrepo_remote):
    """ Test tags in git repository """
    url = 'file://{}'.format(gitrepo_remote.path)
    gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir))
    gitrepo.fetch_and_reset()
    assert 'remote-tag' not in gitrepo.describe()
    gitrepo_remote.tag('remote-tag')
    gitrepo.fetch_and_reset()
    assert 'remote-tag' in gitrepo.describe()
    gitrepo.tag('local-tag')
    gitrepo.fetch_and_reset()
    assert 'local-tag' not in gitrepo.describe()
def test_gitrepo_local(tmpdir):
    """ Test operations on a local git repository """
    gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    testfile = os.path.join(gitrepo.path, 'testfile')
    gitrepo.fetch_and_reset()
    create_file(testfile)
    gitrepo.commit('Commit testfile')
    gitrepo.tag('tag')
    assert gitrepo.diff()
    assert gitrepo.describe()
    assert gitrepo.get_hexsha()
    gitrepo.fetch_and_reset()
    assert os.path.isfile(testfile)
def test_gitrepo_remote_push(tmpdir, gitrepo_remote):
    """ Tests pushing changes to remote repository """
    url = 'file://{}'.format(gitrepo_remote.path)
    gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir))
    testfile = os.path.join(gitrepo.path, 'testfile')
    gitrepo.fetch_and_reset()
    create_file(testfile)
    gitrepo.commit('Commit testfile')
    gitrepo.push('master')
    gitrepo.tag('tag')
    gitrepo.push('master', True)
    gitrepo.push('somebranch', True)
    create_file(testfile, 'modified content')
    with pytest.raises(ValueError):
        gitrepo.push('master')
def test_gitrepo_remote_rebase(tmpdir, gitrepo_remote):
    """ Test rebasing changes instead of resetting """
    url = 'file://{}'.format(gitrepo_remote.path)
    gitrepo = GitRepo(GitHubRepo('local-repo', url, url), str(tmpdir))
    testfile = os.path.join(gitrepo.path, 'testfile')
    gitrepo.fetch_and_reset()
    create_file(testfile)
    gitrepo.commit('Commit testfile')
    assert gitrepo.diff()
    gitrepo.fetch_and_reset(reset=False)
    assert gitrepo.diff()
    assert os.path.isfile(testfile)
    gitrepo.fetch_and_reset(reset=True)
    assert not gitrepo.diff()
    assert not os.path.isfile(testfile)
def test_gitrepo_local_commitforce(tmpdir):
    """ Test force committing to a git repository """
    gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    gitignore = os.path.join(gitrepo.path, '.gitignore')
    testfile = os.path.join(gitrepo.path, 'testfile')
    create_file(gitignore, os.path.basename(testfile))
    gitrepo.commit('Commit gitignore')
    create_file(testfile)
    gitrepo.commit('Try to commit ignored file')
    gitrepo.fetch_and_reset()
    assert not os.path.isfile(testfile)
    create_file(testfile)
    gitrepo.commit('Force commit ignored file', force=True)
    gitrepo.fetch_and_reset()
    assert os.path.isfile(testfile)
    return mocker.patch(
        'kodi_game_scripting.process_game_addons'
        '.LibretroWrapper',
        autospec=True)


@pytest.fixture(autouse=True)
def templateprocessormock(mocker):
    """ Setup mocked TemplateProcessor """
    return mocker.patch(
        'kodi_game_scripting.process_game_addons'
        '.TemplateProcessor',
        autospec=True)


GITHUBREPO = GitHubRepo('name', 'clone_url', 'ssh_url')


def test_kodiaddondescriptions_clean(mocker):
    """ Test cleaning addon descriptions """
    game1 = '{}game1'.format(config.GITHUB_ADDON_PREFIX)
    game2 = '{}game2'.format(config.GITHUB_ADDON_PREFIX)
    kodi_directory = os.path.join('path', 'repo')
    mocker.patch('os.walk',
                 return_value=iter([
                     ('dir', (game1, game2, 'other'), ('file1', 'file2')),
                 ]),
                 autospec=True)
    rmmock = mocker.patch('shutil.rmtree', autospec=True)
    KodiAddonDescriptions(kodi_directory).clean()
    rmmock.assert_has_calls([
Exemplo n.º 19
0
def test_gitrepo_initnocloneurl(gitmock):
    """ Test initializing a new repository without clone url """
    with mock.patch('kodi_game_scripting.git_access.GitRepo.is_git_repo',
                    return_value=False):
        GitRepo(GitHubRepo('empty', '', ''), 'tmpdir')
    gitmock.init.return_value.remotes.origin.set_url.assert_not_called()
def test_gitrepo_isgitrepo(tmpdir):
    """ Test if a directory is a git repository """
    assert not GitRepo.is_git_repo(os.path.join(str(tmpdir), 'local-repo'))
    GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    assert GitRepo.is_git_repo(os.path.join(str(tmpdir), 'local-repo'))
def test_gitrepo_local_existing(tmpdir):
    """ Test initializing an existing repository """
    gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    gitrepo.fetch_and_reset()
    gitrepo = GitRepo(GitHubRepo('local-repo', '', ''), str(tmpdir))
    gitrepo.fetch_and_reset()