test_import_dsc.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # vim: set fileencoding=utf-8 :
  2. #
  3. # (C) 2013,2014,2015 Guido Günther <agx@sigxcpu.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, please see
  17. # <http://www.gnu.org/licenses/>
  18. import os
  19. from tests.component import (ComponentTestBase,
  20. ComponentTestGitRepository)
  21. from tests.component.deb import DEB_TEST_DATA_DIR
  22. from nose.tools import ok_
  23. from gbp.scripts.import_dsc import main as import_dsc
  24. class TestImportDsc(ComponentTestBase):
  25. """Test importing of debian source packages"""
  26. def test_debian_import(self):
  27. """Test that importing of debian native packages works"""
  28. def _dsc(version):
  29. return os.path.join(DEB_TEST_DATA_DIR,
  30. 'dsc-native',
  31. 'git-buildpackage_%s.dsc' % version)
  32. dsc = _dsc('0.4.14')
  33. assert import_dsc(['arg0', dsc]) == 0
  34. repo = ComponentTestGitRepository('git-buildpackage')
  35. self._check_repo_state(repo, 'master', ['master'])
  36. assert len(repo.get_commits()) == 1
  37. os.chdir('git-buildpackage')
  38. dsc = _dsc('0.4.15')
  39. assert import_dsc(['arg0', dsc]) == 0
  40. self._check_repo_state(repo, 'master', ['master'])
  41. assert len(repo.get_commits()) == 2
  42. dsc = _dsc('0.4.16')
  43. assert import_dsc(['arg0', dsc]) == 0
  44. self._check_repo_state(repo, 'master', ['master'])
  45. assert len(repo.get_commits()) == 3
  46. def test_create_branches(self):
  47. """Test if creating missing branches works"""
  48. def _dsc(version):
  49. return os.path.join(DEB_TEST_DATA_DIR,
  50. 'dsc-3.0',
  51. 'hello-debhelper_%s.dsc' % version)
  52. dsc = _dsc('2.6-2')
  53. assert import_dsc(['arg0',
  54. '--verbose',
  55. '--pristine-tar',
  56. '--debian-branch=master',
  57. '--upstream-branch=upstream',
  58. dsc]) == 0
  59. repo = ComponentTestGitRepository('hello-debhelper')
  60. os.chdir('hello-debhelper')
  61. assert len(repo.get_commits()) == 2
  62. self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream'])
  63. dsc = _dsc('2.8-1')
  64. assert import_dsc(['arg0',
  65. '--verbose',
  66. '--pristine-tar',
  67. '--debian-branch=foo',
  68. '--upstream-branch=bar',
  69. '--create-missing-branches',
  70. dsc]) == 0
  71. self._check_repo_state(repo, 'master', ['bar', 'foo', 'master', 'pristine-tar', 'upstream'])
  72. commits, expected = len(repo.get_commits()), 2
  73. ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
  74. def test_import_multiple(self):
  75. """Test if importing a multiple tarball package works"""
  76. def _dsc(version):
  77. return os.path.join(DEB_TEST_DATA_DIR,
  78. 'dsc-3.0-additional-tarballs',
  79. 'hello-debhelper_%s.dsc' % version)
  80. dsc = _dsc('2.8-1')
  81. assert import_dsc(['arg0',
  82. '--verbose',
  83. '--pristine-tar',
  84. '--debian-branch=master',
  85. '--upstream-branch=upstream',
  86. dsc]) == 1
  87. self._check_log(0, "gbp:error: Cannot import package with additional tarballs but found 'hello-debhelper_2.8.orig-foo.tar.gz")
  88. def test_existing_dir(self):
  89. """
  90. Importing outside of git repository with existing target
  91. dir must fail
  92. """
  93. def _dsc(version):
  94. return os.path.join(DEB_TEST_DATA_DIR,
  95. 'dsc-3.0',
  96. 'hello-debhelper_%s.dsc' % version)
  97. # Create directory we should stumble upon
  98. os.makedirs('hello-debhelper')
  99. dsc = _dsc('2.8-1')
  100. assert import_dsc(['arg0',
  101. '--verbose',
  102. '--pristine-tar',
  103. '--debian-branch=master',
  104. '--upstream-branch=upstream',
  105. dsc]) == 1
  106. self._check_log(0, "gbp:error: Directory 'hello-debhelper' already exists. If you want to import into it, "
  107. "please change into this directory otherwise move it away first")