17_test_dch_guess_documented_commit.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 TestGuessDocumentedCommit(testutils.DebianGitTestRepo):
  7. def setUp(self):
  8. self.version = '1.0-1'
  9. self.tagformat = 'debian/%(version)s'
  10. testutils.DebianGitTestRepo.setUp(self)
  11. def test_01_from_snapshot_banner(self):
  12. """
  13. Guess the commit to start from from the snapshot banner
  14. """
  15. cp = testutils.MockedChangeLog(self.version,
  16. "*** SNAPSHOT build @12345 ***")
  17. guessed_commit = dch.guess_documented_commit(cp, None, None)
  18. self.assertEqual(guessed_commit, '12345')
  19. def test_02_from_tag(self):
  20. """
  21. Guess the commit to start from from the tag matching
  22. the topmost version in the changelog
  23. """
  24. cp = testutils.MockedChangeLog(self.version)
  25. self.add_file('doesnot', 'matter')
  26. tag = self.repo.version_to_tag(self.tagformat,
  27. self.version)
  28. self.repo.create_tag(name=tag,
  29. msg="Debian release %s" % self.version,
  30. sign=False)
  31. commit = self.repo.rev_parse('%s^0' % tag)
  32. guessed_commit = dch.guess_documented_commit(cp,
  33. self.repo,
  34. self.tagformat)
  35. self.assertEqual(guessed_commit, commit)
  36. def test_03_from_changelog_commit(self):
  37. """
  38. Guess the commit to start from from the commit that
  39. last touched the changelog
  40. """
  41. cp = testutils.MockedChangeLog(self.version)
  42. self.add_file('debian/changelog', 'foo')
  43. commit = self.repo.head
  44. self.add_file('doesnot', 'matter')
  45. guessed_commit = dch.guess_documented_commit(cp,
  46. self.repo,
  47. self.tagformat)
  48. self.assertEqual(guessed_commit, commit)
  49. def test_04_not_touched(self):
  50. """
  51. None of the above matched so we want to start from
  52. the beginning of history
  53. """
  54. cp = testutils.MockedChangeLog(self.version)
  55. self.add_file('doesnot', 'matter')
  56. self.add_file('doesnot', 'mattereither')
  57. guessed_commit = dch.guess_documented_commit(cp,
  58. self.repo,
  59. self.tagformat)
  60. self.assertIsNone(guessed_commit)