07_test_fastimport.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # vim: set fileencoding=utf-8 :
  2. """Test L{FastImport} class"""
  3. from . import context
  4. import os
  5. import gbp.log
  6. import gbp.git
  7. repo = None
  8. fastimport = None
  9. tf_name = 'testfile'
  10. tl_name = 'a_testlink'
  11. def setup():
  12. global repo
  13. tmpdir = context.new_tmpdir(__name__)
  14. repo = gbp.git.GitRepository.create(tmpdir.join('test_repo'))
  15. def teardown():
  16. context.teardown()
  17. def test_init_fastimport():
  18. """Create a fastimport object"""
  19. global fastimport
  20. fastimport = gbp.git.FastImport(repo)
  21. assert fastimport, "Failed to init FastImport"
  22. def test_add_file():
  23. """Add a file via fastimport"""
  24. author = repo.get_author_info()
  25. fastimport.start_commit('master', author, "a commit")
  26. fastimport.deleteall()
  27. testfile = os.path.join(repo.path, '.git', 'description')
  28. fastimport.add_file('./testfile',
  29. open(testfile),
  30. os.path.getsize(testfile))
  31. def test_add_symlink():
  32. """Add a symbolic link via fastimport"""
  33. author = repo.get_author_info()
  34. fastimport.start_commit('master', author, "a 2nd commit")
  35. fastimport.add_symlink(tl_name, tf_name)
  36. def test_close():
  37. fastimport.close()
  38. def test_result():
  39. repo.force_head('master', hard=True)
  40. testfile = os.path.join(repo.path, tf_name)
  41. testlink = os.path.join(repo.path, tl_name)
  42. assert os.path.exists(testfile), "%s doesn't exist" % testfile
  43. assert os.path.lexists(testlink), "%s doesn't exist" % testlink
  44. assert os.readlink(testlink) == tf_name