07_test_fastimport.py 1.5 KB
Newer Older
1 2
# vim: set fileencoding=utf-8 :

3 4
"""Test L{FastImport} class"""

5 6
from . import context

7 8 9 10 11 12 13 14 15 16
import os

import gbp.log
import gbp.git

repo = None
fastimport = None
tf_name = 'testfile'
tl_name = 'a_testlink'

17

18
def setup():
19
    global repo
20

21 22
    tmpdir = context.new_tmpdir(__name__)
    repo = gbp.git.GitRepository.create(tmpdir.join('test_repo'))
23

24

25
def teardown():
26
    context.teardown()
27

28

29 30 31 32 33 34
def test_init_fastimport():
    """Create a fastimport object"""
    global fastimport
    fastimport = gbp.git.FastImport(repo)
    assert fastimport, "Failed to init FastImport"

35

36 37 38 39 40 41
def test_add_file():
    """Add a file via fastimport"""
    author = repo.get_author_info()
    fastimport.start_commit('master', author, "a commit")
    fastimport.deleteall()
    testfile = os.path.join(repo.path, '.git', 'description')
42 43
    fastimport.add_file(b'./testfile',
                        open(testfile, 'rb'),
44 45
                        os.path.getsize(testfile))

46

47 48 49 50 51 52
def test_add_symlink():
    """Add a symbolic link via fastimport"""
    author = repo.get_author_info()
    fastimport.start_commit('master', author, "a 2nd commit")
    fastimport.add_symlink(tl_name, tf_name)

53

54 55 56
def test_close():
    fastimport.close()

57

58 59 60 61 62 63 64 65 66
def test_result():
    repo.force_head('master', hard=True)

    testfile = os.path.join(repo.path, tf_name)
    testlink = os.path.join(repo.path, tl_name)

    assert os.path.exists(testfile), "%s doesn't exist" % testfile
    assert os.path.lexists(testlink), "%s doesn't exist" % testlink
    assert os.readlink(testlink) == tf_name