aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/03_test_dch_guess_version.py
blob: 97a485087c57a188f97d88ec380e364a24a57a09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# vim: set fileencoding=utf-8 :

"""Test L{Changelog}'s guess_version_from_upstream"""

from . import context

import testutils
import unittest

from gbp.scripts import dch
from gbp.deb.changelog import ChangeLog


class MockedChangeLog(ChangeLog):
    contents = """foo (%s) experimental; urgency=low

  * a important change

 -- Debian Maintainer <maint@debian.org>  Sat, 01 Jan 2012 00:00:00 +0100"""

    def __init__(self, version):
        ChangeLog.__init__(self, contents=self.contents % version)


class TestGuessVersionFromUpstream(testutils.DebianGitTestRepo):
    """Test guess_version_from_upstream"""

    def test_guess_no_epoch(self):
        """Guess the new version from the upstream tag"""
        cp = MockedChangeLog('1.0-1')
        tagformat = 'upstream/%(version)s'
        uversion = '1.1'

        self.add_file('doesnot', 'matter')
        tag = self.repo.version_to_tag(tagformat, uversion)
        self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
                             sign=False)

        guessed = dch.guess_version_from_upstream(self.repo,
                                                  tagformat,
                                                  cp)
        self.assertEqual('1.1-1', guessed)

    def test_guess_epoch(self):
        """Check if we picked up the epoch correctly (#652366)"""
        cp = MockedChangeLog('1:1.0-1')

        tagformat = 'upstream/%(version)s'
        uversion = '1.1'

        self.add_file('doesnot', 'matter')
        tag = self.repo.version_to_tag(tagformat, uversion)
        self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
                             sign=False)

        guessed = dch.guess_version_from_upstream(self.repo,
                                                  tagformat,
                                                  cp)

        self.assertEqual('1:1.1-1', guessed)