/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
1
#    Copyright (C) 2011 Canonical Ltd
7321.2.3 by Jelmer Vernooij
Fix flake8 errors.
2
#    Copyright (C) 2019 Jelmer Vernooij <jelmer@jelmer.uk>
3
#
4
#    Breezy is free software; you can redistribute it and/or modify
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
5
#    it under the terms of the GNU General Public License as published by
6
#    the Free Software Foundation; either version 2 of the License, or
7
#    (at your option) any later version.
8
#
7321.2.3 by Jelmer Vernooij
Fix flake8 errors.
9
#    Breezy is distributed in the hope that it will be useful,
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#    GNU General Public License for more details.
13
#
14
#    You should have received a copy of the GNU General Public License
7321.2.3 by Jelmer Vernooij
Fix flake8 errors.
15
#    along with Breezy; if not, write to the Free Software
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
16
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
#
18
19
"""Tests for the quilt code."""
20
21
import os
22
23
from ..wrapper import (
7381.1.1 by Jelmer Vernooij
Add quilt_delete.
24
    quilt_delete,
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
25
    quilt_pop_all,
26
    quilt_applied,
27
    quilt_unapplied,
28
    quilt_push_all,
29
    quilt_series,
30
    )
31
32
from ....tests import TestCaseWithTransport
33
from ....tests.features import ExecutableFeature
34
35
quilt_feature = ExecutableFeature('quilt')
36
37
TRIVIAL_PATCH = """--- /dev/null	2012-01-02 01:09:10.986490031 +0100
38
+++ base/a	2012-01-02 20:03:59.710666215 +0100
39
@@ -0,0 +1 @@
40
+a
41
"""
42
43
class QuiltTests(TestCaseWithTransport):
44
45
    _test_needs_features = [quilt_feature]
46
47
    def make_empty_quilt_dir(self, path):
48
        source = self.make_branch_and_tree(path)
49
        self.build_tree(
50
            [os.path.join(path, n) for n in ['patches/']])
51
        self.build_tree_contents([
52
            (os.path.join(path, "patches/series"), "\n")])
53
        source.add(["patches", "patches/series"])
54
        return source
55
56
    def test_series_all_empty(self):
57
        source = self.make_empty_quilt_dir("source")
58
        self.assertEquals([], quilt_series(source, 'patches/series'))
59
60
    def test_series_all(self):
61
        source = self.make_empty_quilt_dir("source")
62
        self.build_tree_contents([
63
            ("source/patches/series", "patch1.diff\n"),
64
            ("source/patches/patch1.diff", TRIVIAL_PATCH)])
65
        source.smart_add(["source"])
66
        self.assertEquals(
67
            ["patch1.diff"], quilt_series(source, 'patches/series'))
68
69
    def test_push_all_empty(self):
70
        self.make_empty_quilt_dir("source")
71
        quilt_push_all("source", quiet=True)
72
7381.1.1 by Jelmer Vernooij
Add quilt_delete.
73
    def test_pop_all_empty(self):
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
74
        self.make_empty_quilt_dir("source")
75
        quilt_pop_all("source", quiet=True)
76
77
    def test_applied_empty(self):
78
        source = self.make_empty_quilt_dir("source")
79
        self.build_tree_contents([
80
            ("source/patches/series", "patch1.diff\n"),
81
            ("source/patches/patch1.diff", "foob ar")])
82
        self.assertEquals([], quilt_applied(source))
83
84
    def test_unapplied(self):
85
        self.make_empty_quilt_dir("source")
86
        self.build_tree_contents([
87
            ("source/patches/series", "patch1.diff\n"),
88
            ("source/patches/patch1.diff", "foob ar")])
89
        self.assertEquals(["patch1.diff"], quilt_unapplied("source"))
90
7413.3.1 by Jelmer Vernooij
Don't strip directory name when determining applied patches.
91
    def test_unapplied_dir(self):
92
        self.make_empty_quilt_dir("source")
93
        self.build_tree_contents([
94
            ("source/patches/series", "debian/patch1.diff\n"),
95
            ("source/patches/debian/", ),
96
            ("source/patches/debian/patch1.diff", "foob ar")])
97
        self.assertEquals(["debian/patch1.diff"], quilt_unapplied("source"))
98
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
99
    def test_unapplied_multi(self):
100
        self.make_empty_quilt_dir("source")
101
        self.build_tree_contents([
102
            ("source/patches/series", "patch1.diff\npatch2.diff"),
103
            ("source/patches/patch1.diff", "foob ar"),
104
            ("source/patches/patch2.diff", "bazb ar")])
105
        self.assertEquals(["patch1.diff", "patch2.diff"],
106
                          quilt_unapplied("source", "patches"))
7381.1.1 by Jelmer Vernooij
Add quilt_delete.
107
108
    def test_delete(self):
109
        source = self.make_empty_quilt_dir("source")
110
        self.build_tree_contents([
111
            ("source/patches/series", "patch1.diff\npatch2.diff"),
112
            ("source/patches/patch1.diff", "foob ar"),
113
            ("source/patches/patch2.diff", "bazb ar")])
114
        quilt_delete("source", "patch1.diff", "patches", remove=False)
115
        self.assertEqual(
116
            ['patch2.diff'],
117
            quilt_series(source, 'patches/series'))
118
        quilt_delete("source", "patch2.diff", "patches", remove=True)
119
        self.assertTrue(os.path.exists('source/patches/patch1.diff'))
120
        self.assertFalse(os.path.exists('source/patches/patch2.diff'))
121
        self.assertEqual([], quilt_series(source, 'patches/series'))