03_test_dch_guess_version.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # vim: set fileencoding=utf-8 :
  2. """Test L{Changelog}'s guess_version_from_upstream"""
  3. from . import context
  4. from . import testutils
  5. from gbp.scripts import dch
  6. class TestGuessVersionFromUpstream(testutils.DebianGitTestRepo):
  7. """Test guess_version_from_upstream"""
  8. def test_guess_no_epoch(self):
  9. """Guess the new version from the upstream tag"""
  10. cp = testutils.MockedChangeLog('1.0-1')
  11. tagformat = 'upstream/%(version)s'
  12. uversion = '1.1'
  13. upstream_branch = 'upstream'
  14. self.add_file('doesnot', 'matter')
  15. self.repo.create_branch('upstream')
  16. tag = self.repo.version_to_tag(tagformat, uversion)
  17. self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
  18. sign=False)
  19. self.repo.set_branch("master")
  20. guessed = dch.guess_version_from_upstream(self.repo,
  21. tagformat,
  22. upstream_branch,
  23. cp)
  24. self.assertEqual('1.1-1', guessed)
  25. def test_guess_epoch(self):
  26. """Check if we picked up the epoch correctly (#652366)"""
  27. cp = testutils.MockedChangeLog('1:1.0-1')
  28. tagformat = 'upstream/%(version)s'
  29. uversion = '1.1'
  30. upstream_branch = 'upstream'
  31. self.add_file('doesnot', 'matter')
  32. self.repo.create_branch('upstream')
  33. tag = self.repo.version_to_tag(tagformat, uversion)
  34. self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
  35. sign=False)
  36. self.repo.set_branch("master")
  37. guessed = dch.guess_version_from_upstream(self.repo,
  38. tagformat,
  39. upstream_branch,
  40. cp)
  41. self.assertEqual('1:1.1-1', guessed)
  42. def test_guess_upstream_tag_clash_with_non_upstream_tag(self):
  43. """Guess with clashing upstream- and non-upstream-tag"""
  44. cp = testutils.MockedChangeLog('0.9-1')
  45. tagformat = 'v%(version)s'
  46. uversion = '1.0'
  47. upstream_branch = 'upstream'
  48. self.add_file('doesnot', 'matter')
  49. self.repo.create_branch('upstream')
  50. tag = self.repo.version_to_tag(tagformat, uversion)
  51. self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
  52. sign=False)
  53. self.repo.set_branch("master")
  54. self.add_file("clash", "bar")
  55. self.repo.create_tag("vyatta/something", msg="some non-upstream tag but not package release tag either")
  56. self.add_file("clash2", "bar")
  57. guessed = dch.guess_version_from_upstream(self.repo,
  58. tagformat,
  59. upstream_branch,
  60. cp)
  61. self.assertEqual('1.0-1', guessed)
  62. def test_guess_upstream_tag_zero_release(self):
  63. """Guess with existing -0... releases"""
  64. cp = testutils.MockedChangeLog('0.9-0vyatta2')
  65. tagformat = 'upstream/%(version)s'
  66. uversion = '0.9'
  67. upstream_branch = 'upstream'
  68. self.add_file('doesnot', 'matter')
  69. self.repo.create_branch('upstream')
  70. tag = self.repo.version_to_tag(tagformat, uversion)
  71. self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
  72. sign=False)
  73. self.repo.set_branch('master')
  74. self.add_file('doesnot2', 'matter')
  75. guessed = dch.guess_version_from_upstream(self.repo,
  76. tagformat,
  77. upstream_branch,
  78. cp)
  79. self.assertEqual(None, guessed)