test_PristineTar.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # vim: set fileencoding=utf-8 :
  2. """
  3. Test pristine-tar related methods in
  4. - L{gbp.deb.DebianPristineTar}
  5. and
  6. - L{gbp.deb.git.DebianGitRepository}
  7. This testcase creates this reposity:
  8. - A repository at L{repo_dir} called I{repo}
  9. """
  10. from . import context
  11. import os
  12. repo_dir = context.new_tmpdir(__name__).join('repo')
  13. test_data = os.path.join(context.projectdir, "tests/test_PristineTar_data")
  14. def test_create():
  15. """
  16. Create a repository
  17. Methods tested:
  18. - L{gbp.deb.git.DebianGitRepository.create}
  19. >>> import os, gbp.deb.git
  20. >>> repo = gbp.deb.git.DebianGitRepository.create(repo_dir)
  21. """
  22. def test_empty_repo():
  23. """
  24. Empty repos have no branch pristine-tar branch
  25. Methods tested:
  26. - L{gbp.deb.git.DebianGitRepository.has_pristine_tar_branch}
  27. - L{gbp.deb.pristinetar.DebianPristineTar.has_commit}
  28. >>> import gbp.deb.git
  29. >>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
  30. >>> repo.has_pristine_tar_branch()
  31. False
  32. >>> repo.pristine_tar.has_commit('upstream', '1.0', 'gzip')
  33. False
  34. """
  35. def test_commit_dir():
  36. """
  37. Empty repos have no branch pristine-tar branch
  38. Methods tested:
  39. - L{gbp.git.repository.GitRepository.commit_dir}
  40. - L{gbp.git.repository.GitRepository.create_branch}
  41. >>> import gbp.deb.git
  42. >>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
  43. >>> commit = repo.commit_dir(test_data, msg="initial commit", branch=None)
  44. >>> repo.create_branch('upstream')
  45. """
  46. def test_create_tarball():
  47. """
  48. Create a tarball from a git tree
  49. Methods tested:
  50. - L{gbp.deb.git.DebianGitRepository.archive}
  51. >>> import gbp.deb.git
  52. >>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
  53. >>> repo.archive('tar', 'upstream/', '../upstream_1.0.orig.tar', 'upstream')
  54. >>> gbp.command_wrappers.Command('gzip', [ '-n', '%s/../upstream_1.0.orig.tar' % repo_dir])()
  55. """
  56. def test_pristine_tar_commit():
  57. """
  58. Commit the delta to the pristine-tar branch
  59. Methods tested:
  60. - L{gbp.deb.pristinetar.DebianPristineTar.commit}
  61. >>> import gbp.deb.git
  62. >>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
  63. >>> repo.pristine_tar.commit('../upstream_1.0.orig.tar.gz', 'upstream')
  64. """
  65. def test_pristine_has_commit():
  66. """
  67. Find delta on the pristine tar branch
  68. Methods tested:
  69. - L{gbp.deb.pristinetar.DebianPristineTar.has_commit}
  70. - L{gbp.pkg.pristinetar.PristineTar.get_commit}
  71. >>> import gbp.deb.git
  72. >>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
  73. >>> repo.pristine_tar.has_commit('upstream', '1.0', 'bzip2')
  74. False
  75. >>> repo.pristine_tar.has_commit('upstream', '1.0', 'gzip')
  76. True
  77. >>> repo.pristine_tar.has_commit('upstream', '1.0')
  78. True
  79. >>> branch = repo.rev_parse('pristine-tar')
  80. >>> commit = repo.pristine_tar.get_commit('upstream_1.0.orig.tar.gz')
  81. >>> branch == commit
  82. True
  83. """
  84. def test_pristine_tar_checkout():
  85. """
  86. Checkout a tarball using pristine-tar
  87. Methods tested:
  88. - L{gbp.deb.pristinetar.DebianPristineTar.checkout}
  89. >>> import gbp.deb.git
  90. >>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
  91. >>> repo.pristine_tar.checkout('upstream', '1.0', 'gzip', '..')
  92. """
  93. def test_pristine_tar_checkout_nonexistent():
  94. """
  95. Checkout a tarball that does not exist using pristine-tar
  96. Methods tested:
  97. - L{gbp.deb.pristinetar.DebianPristineTar.checkout}
  98. >>> import gbp.deb.git
  99. >>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
  100. >>> repo.pristine_tar.checkout('upstream', '1.1', 'gzip', '..')
  101. Traceback (most recent call last):
  102. ...
  103. CommandExecFailed: Pristine-tar couldn't checkout "upstream_1.1.orig.tar.gz": fatal: Path 'upstream_1.1.orig.tar.gz.delta' does not exist in 'refs/heads/pristine-tar'
  104. pristine-tar: git show refs/heads/pristine-tar:upstream_1.1.orig.tar.gz.delta failed
  105. """
  106. def test_teardown():
  107. """
  108. Perform the teardown
  109. >>> context.teardown()
  110. """
  111. # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: