aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/15_test_DebianSource.py
blob: 809feaac7670e038c7e701458da484aa069b90e9 (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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# vim: set fileencoding=utf-8 :
# (C) 2013 Guido Günther <agx@sigxcpu.org>
#    This program 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.
#
#    This program 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 this program; if not, please see
#    <http://www.gnu.org/licenses/>
"""Test L{gbp.pq}"""

from . import context
from . import testutils

import os

from gbp.deb.source import DebianSource, DebianSourceError
from gbp.deb.format import DebianSourceFormat
from gbp.git.vfs import GitVfs


class TestDebianSource(testutils.DebianGitTestRepo):
    """Test L{gbp.deb.source}'s """

    def setUp(self):
        testutils.DebianGitTestRepo.setUp(self)
        context.chdir(self.repo.path)

    def test_is_native_file_3_file(self):
        """Test native package of format 3"""
        source = DebianSource('.')
        os.makedirs('debian/source')
        with self.assertRaises(DebianSourceError):
            source.is_native()

        dsf = DebianSourceFormat.from_content("3.0", "native")
        self.assertEqual(dsf.type, 'native')
        self.assertTrue(source.is_native())

        dsf = DebianSourceFormat.from_content("3.0", "quilt")
        self.assertEqual(dsf.type, 'quilt')
        self.assertFalse(source.is_native())

    def test_is_native_fallback_file(self):
        """Test native package without a debian/source/format file"""
        source = DebianSource('.')
        os.makedirs('debian/')
        with self.assertRaises(DebianSourceError):
            source.is_native()

        with open('debian/changelog', 'w') as f:
            f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <agx@sigxcpu.org>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        source = DebianSource('.')
        self.assertTrue(source.is_native())

    def _commit_format(self, version, format):
        # Commit a format file to disk
        if not os.path.exists('debian/source'):
            os.makedirs('debian/source')
        dsf = DebianSourceFormat.from_content(version, format)
        self.assertEqual(dsf.type, format)
        self.repo.add_files('.')
        self.repo.commit_all('foo')
        os.unlink('debian/source/format')
        self.assertFalse(os.path.exists('debian/source/format'))

    def test_is_native_file_3_git(self):
        """Test native package of format 3 from git"""
        self._commit_format('3.0', 'native')
        source = DebianSource(GitVfs(self.repo))
        self.assertTrue(source.is_native())

        self._commit_format('3.0', 'quilt')
        source = DebianSource(GitVfs(self.repo))
        self.assertFalse(source.is_native())

    def test_is_releasable(self):
        os.makedirs('debian/')
        with open('debian/changelog', 'w') as f:
            f.write("""git-buildpackage (0.2.3) unstable; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <agx@sigxcpu.org>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        source = DebianSource('.')
        self.assertEquals(source.changelog.distribution, "unstable")
        self.assertTrue(source.is_releasable())

    def test_is_not_releasable(self):
        os.makedirs('debian/')
        with open('debian/changelog', 'w') as f:
            f.write("""git-buildpackage (0.2.3) UNRELEASED; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <agx@sigxcpu.org>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        source = DebianSource('.')
        self.assertEquals(source.changelog.distribution, "UNRELEASED")
        self.assertFalse(source.is_releasable())

    def test_control(self):
        os.makedirs('debian/')
        with open('debian/control', 'w') as f:
            f.write("Source: foo")
        source = DebianSource('.')
        self.assertIsNotNone(source.control)
        self.assertEquals(source.control.name, "foo")

    def test_cur_dir_not_toplevel(self):
        """
        Check if we can parse files if workdir != debian toplevel dir
        """
        os.makedirs('debian/')
        with open('debian/changelog', 'w') as f:
            f.write("""foo (0.2.3) unstable; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <agx@sigxcpu.org>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        with open('debian/control', 'w') as f:
            f.write("Source: foo")
        os.chdir('debian/')
        source = DebianSource('..')
        self.assertEquals(source.changelog.name, "foo")
        self.assertEquals(source.control.name, "foo")

        source = DebianSource(os.path.abspath('..'))
        self.assertEquals(source.changelog.name, "foo")
        self.assertEquals(source.control.name, "foo")