Exemplo n.º 1
0
def test_substitute_keywords(project_repo):
    test_text = """\
        First line
        version:
        date:
        author:
        Last line"""

    commit_ref = project_repo.head()
    short_ref = commit_ref[:7].decode(encoding='ascii')
    commit = project_repo.get_object(commit_ref)
    commit_time = strftime('%Y-%m-%d %H:%M:%S', gmtime(commit.commit_time))
    timezone = format_timezone(commit.commit_timezone).decode(encoding='ascii')
    commit_timestamp = commit_time + ' ' + timezone
    author = commit.author.decode(encoding='ascii')

    result = git.substitute_keywords(test_text, project_repo, 'master')
    expected_result = """\
        First line
        version: %s
        date: %s
        author: %s
        Last line""" % (short_ref, commit_timestamp, author)
    assert result == expected_result

    result = git.substitute_keywords(test_text, project_repo, 'test-tag')
    expected_result = """\
        First line
        version: %s
        date: %s
        author: %s
        Last line""" % (short_ref, commit_timestamp, author)
    assert result == expected_result

    result = git.substitute_keywords(test_text, project_repo, 'test-garbage')
    expected_result = ''
    assert result == expected_result
Exemplo n.º 2
0
def _fetch_script(repo, script_path, commit_ref, target_folder):
    script = Path(repo.path, script_path)
    target_script = Path(target_folder, script.name)

    git.checkout(repo, commit_ref)

    with script.open('r') as f:
        original_text = f.read()
        f.close()

    new_text = git.substitute_keywords(original_text, repo, commit_ref)

    with target_script.open('w') as f:
        f.write(new_text)
        f.close()

    return target_script