File: test_revspec.py

package info (click to toggle)
bzr-builddeb 2.8.11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,172 kB
  • sloc: python: 12,741; makefile: 41; sh: 3
file content (122 lines) | stat: -rw-r--r-- 4,495 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#    test_revspec.py -- Test the revision specs
#    Copyright (C) 2008 Canonical Ltd.
#
#    This file is part of bzr-builddeb.
#
#    bzr-builddeb is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    bzr-builddeb is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with bzr-builddeb; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

import os

from bzrlib.errors import InvalidRevisionSpec
from bzrlib.revisionspec import RevisionSpec

from bzrlib.tests.test_revisionspec import TestRevisionSpec

from bzrlib.plugins.builddeb.tests import Version, Changelog
from bzrlib.plugins.builddeb.errors import (
    UnknownVersion,
    VersionNotSpecified,
    )
from bzrlib.plugins.builddeb.revspec import (
    RevisionSpec_package,
    RevisionSpec_upstream,
    )


class TestRevisionSpec_package(TestRevisionSpec):

    def test_from_string_package(self):
        spec = RevisionSpec.from_string('package:0.1-1')
        self.assertIsInstance(spec, RevisionSpec_package)
        self.assertEqual(spec.spec, '0.1-1')

    def test_simple_package(self):
        self.tree.branch.tags.set_tag('0.1-1', 'r1')
        self.assertInHistoryIs(1, 'r1', 'package:0.1-1')

    def test_unkown_version(self):
        self.assertRaises(UnknownVersion,
                self.get_in_history, 'package:0.1-1')

    def test_missing_version(self):
        self.assertRaises(VersionNotSpecified,
                self.get_in_history, 'package:')


class TestRevisionSpec_upstream(TestRevisionSpec):

    package_name = 'test'
    package_version = Version('0.1-1')
    upstream_version = property(lambda self: \
                                self.package_version.upstream_version)

    def make_changelog(self, version=None):
        if version is None:
            version = self.package_version
        c = Changelog()
        c.new_block()
        c.version = Version(version)
        c.package = self.package_name
        c.distributions = 'unstable'
        c.urgency = 'low'
        c.author = 'James Westby <jw+debian@jameswestby.net>'
        c.date = 'Thu,  3 Aug 2006 19:16:22 +0100'
        c.add_change('')
        c.add_change('  *  test build')
        c.add_change('')
        return c

    def write_changelog(self, changelog, filename):
        f = open(filename, 'w')
        changelog.write_to_open_file(f)
        f.close()

    def add_changelog(self, tree, version):
        cl = self.make_changelog("1.2-1")
        tree.mkdir('debian')
        self.write_changelog(cl, os.path.join(tree.basedir, 'debian/changelog'))
        tree.add(['debian', 'debian/changelog'])

    def test_from_string_package(self):
        self.make_branch_and_tree('.')
        spec = RevisionSpec.from_string('upstream:')
        self.assertIsInstance(spec, RevisionSpec_upstream)
        self.assertEqual(spec.spec, '')

    def test_no_changelog(self):
        t = self.make_branch_and_tree('.')
        spec = RevisionSpec.from_string('upstream:')
        self.assertRaises(InvalidRevisionSpec, spec.as_revision_id, t.branch)

    def test_version_specified(self):
        t = self.make_branch_and_tree('.')
        upstream_revid = t.commit('The upstream revision')
        t.branch.tags.set_tag("upstream-1.2", upstream_revid)
        t.commit('Mention upstream.')
        self.add_changelog(t, "1.2-1")
        spec = RevisionSpec.from_string('upstream:1.2')
        self.assertEquals(upstream_revid, spec.as_revision_id(t.branch))
        spec = RevisionSpec.from_string('upstream:1.2-1')
        self.assertEquals(upstream_revid, spec.as_revision_id(t.branch))

    def test_version_from_changelog(self):
        t = self.make_branch_and_tree('.')
        upstream_revid = t.commit('The upstream revision')
        t.branch.tags.set_tag("upstream-1.2", upstream_revid)
        t.commit('Mention upstream.')
        self.add_changelog(t, "1.2-1")
        spec = RevisionSpec.from_string('upstream:')
        self.assertEquals(upstream_revid, spec.as_revision_id(t.branch))