From 938e4cd25d47a0b9230a14e55724a5c3912e2359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 21 Aug 2013 19:21:41 +0200 Subject: dch: make automatic adding of new sections more robust This code that determined if we found a snapshot header was obuscated by the code that determines the commits to add. Split those and better document their purpose. Also always return the commit to start from so we don't need to repeat the logic in the uper levels. --- tests/17_test_dch_guess_documented_commit.py | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/17_test_dch_guess_documented_commit.py (limited to 'tests') diff --git a/tests/17_test_dch_guess_documented_commit.py b/tests/17_test_dch_guess_documented_commit.py new file mode 100644 index 00000000..89eba2d3 --- /dev/null +++ b/tests/17_test_dch_guess_documented_commit.py @@ -0,0 +1,73 @@ +# vim: set fileencoding=utf-8 : + +"""Test L{Changelog}'s guess_version_from_upstream""" + +from . import context + +import testutils + +from gbp.scripts import dch + +class TestGuessDocumentedCommit(testutils.DebianGitTestRepo): + def setUp(self): + self.version = '1.0-1' + self.tagformat = 'debian/%(version)s' + + testutils.DebianGitTestRepo.setUp(self) + + def test_01_from_snapshot_banner(self): + """ + Guess the commit to start from from the snapshot banner + """ + cp = testutils.MockedChangeLog(self.version, + "*** SNAPSHOT build @12345 ***") + guessed_commit = dch.guess_documented_commit(cp, None, None) + self.assertEqual(guessed_commit, '12345') + + def test_02_from_tag(self): + """ + Guess the commit to start from from the tag matching + the topmost version in the changelog + """ + cp = testutils.MockedChangeLog(self.version) + + self.add_file('doesnot', 'matter') + tag = self.repo.version_to_tag(self.tagformat, + self.version) + self.repo.create_tag(name=tag, + msg="Debian release %s" % self.version, + sign=False) + commit = self.repo.rev_parse('%s^0' % tag) + guessed_commit = dch.guess_documented_commit(cp, + self.repo, + self.tagformat) + self.assertEqual(guessed_commit, commit) + + def test_03_from_changelog_commit(self): + """ + Guess the commit to start from from the commit that + last touched the changelog + """ + cp = testutils.MockedChangeLog(self.version) + + self.add_file('debian/changelog', 'foo') + commit = self.repo.head + self.add_file('doesnot', 'matter') + guessed_commit = dch.guess_documented_commit(cp, + self.repo, + self.tagformat) + self.assertEqual(guessed_commit, commit) + + def test_04_not_touched(self): + """ + None of the above matched so we want to start from + the beginning of history + """ + cp = testutils.MockedChangeLog(self.version) + + self.add_file('doesnot', 'matter') + self.add_file('doesnot', 'mattereither') + guessed_commit = dch.guess_documented_commit(cp, + self.repo, + self.tagformat) + self.assertIsNone(guessed_commit) -- cgit v1.2.3