/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
from __future__ import absolute_import
22
23
import os
24
25
from ..wrapper import (
7381.1.1 by Jelmer Vernooij
Add quilt_delete.
26
    quilt_delete,
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
27
    quilt_pop_all,
28
    quilt_applied,
29
    quilt_unapplied,
30
    quilt_push_all,
31
    quilt_series,
32
    )
33
34
from ....tests import TestCaseWithTransport
35
from ....tests.features import ExecutableFeature
36
37
quilt_feature = ExecutableFeature('quilt')
38
39
TRIVIAL_PATCH = """--- /dev/null	2012-01-02 01:09:10.986490031 +0100
40
+++ base/a	2012-01-02 20:03:59.710666215 +0100
41
@@ -0,0 +1 @@
42
+a
43
"""
44
45
class QuiltTests(TestCaseWithTransport):
46
47
    _test_needs_features = [quilt_feature]
48
49
    def make_empty_quilt_dir(self, path):
50
        source = self.make_branch_and_tree(path)
51
        self.build_tree(
52
            [os.path.join(path, n) for n in ['patches/']])
53
        self.build_tree_contents([
54
            (os.path.join(path, "patches/series"), "\n")])
55
        source.add(["patches", "patches/series"])
56
        return source
57
58
    def test_series_all_empty(self):
59
        source = self.make_empty_quilt_dir("source")
60
        self.assertEquals([], quilt_series(source, 'patches/series'))
61
62
    def test_series_all(self):
63
        source = self.make_empty_quilt_dir("source")
64
        self.build_tree_contents([
65
            ("source/patches/series", "patch1.diff\n"),
66
            ("source/patches/patch1.diff", TRIVIAL_PATCH)])
67
        source.smart_add(["source"])
68
        self.assertEquals(
69
            ["patch1.diff"], quilt_series(source, 'patches/series'))
70
71
    def test_push_all_empty(self):
72
        self.make_empty_quilt_dir("source")
73
        quilt_push_all("source", quiet=True)
74
7381.1.1 by Jelmer Vernooij
Add quilt_delete.
75
    def test_pop_all_empty(self):
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
76
        self.make_empty_quilt_dir("source")
77
        quilt_pop_all("source", quiet=True)
78
79
    def test_applied_empty(self):
80
        source = self.make_empty_quilt_dir("source")
81
        self.build_tree_contents([
82
            ("source/patches/series", "patch1.diff\n"),
83
            ("source/patches/patch1.diff", "foob ar")])
84
        self.assertEquals([], quilt_applied(source))
85
86
    def test_unapplied(self):
87
        self.make_empty_quilt_dir("source")
88
        self.build_tree_contents([
89
            ("source/patches/series", "patch1.diff\n"),
90
            ("source/patches/patch1.diff", "foob ar")])
91
        self.assertEquals(["patch1.diff"], quilt_unapplied("source"))
92
7413.3.1 by Jelmer Vernooij
Don't strip directory name when determining applied patches.
93
    def test_unapplied_dir(self):
94
        self.make_empty_quilt_dir("source")
95
        self.build_tree_contents([
96
            ("source/patches/series", "debian/patch1.diff\n"),
97
            ("source/patches/debian/", ),
98
            ("source/patches/debian/patch1.diff", "foob ar")])
99
        self.assertEquals(["debian/patch1.diff"], quilt_unapplied("source"))
100
7321.2.1 by Jelmer Vernooij
Bundle the quilt plugin.
101
    def test_unapplied_multi(self):
102
        self.make_empty_quilt_dir("source")
103
        self.build_tree_contents([
104
            ("source/patches/series", "patch1.diff\npatch2.diff"),
105
            ("source/patches/patch1.diff", "foob ar"),
106
            ("source/patches/patch2.diff", "bazb ar")])
107
        self.assertEquals(["patch1.diff", "patch2.diff"],
108
                          quilt_unapplied("source", "patches"))
7381.1.1 by Jelmer Vernooij
Add quilt_delete.
109
110
    def test_delete(self):
111
        source = self.make_empty_quilt_dir("source")
112
        self.build_tree_contents([
113
            ("source/patches/series", "patch1.diff\npatch2.diff"),
114
            ("source/patches/patch1.diff", "foob ar"),
115
            ("source/patches/patch2.diff", "bazb ar")])
116
        quilt_delete("source", "patch1.diff", "patches", remove=False)
117
        self.assertEqual(
118
            ['patch2.diff'],
119
            quilt_series(source, 'patches/series'))
120
        quilt_delete("source", "patch2.diff", "patches", remove=True)
121
        self.assertTrue(os.path.exists('source/patches/patch1.diff'))
122
        self.assertFalse(os.path.exists('source/patches/patch2.diff'))
123
        self.assertEqual([], quilt_series(source, 'patches/series'))