/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_matchers.py

  • Committer: Jelmer Vernooij
  • Date: 2018-07-08 10:56:06 UTC
  • mto: This revision was merged to the branch mainline in revision 7030.
  • Revision ID: jelmer@jelmer.uk-20180708105606-d53hkks89qq88twu
Use separate .as_bytes method rather than __bytes__.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
 
1
# Copyright (C) 2010, 2011, 2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Tests of bzrlib test matchers."""
 
17
"""Tests of breezy test matchers."""
18
18
 
19
19
from testtools.matchers import *
20
20
 
21
 
from bzrlib.tests import TestCase
22
 
from bzrlib.tests.matchers import *
 
21
from ..bzr.smart.client import CallHookParams
 
22
 
 
23
from . import (
 
24
    CapturedCall,
 
25
    TestCase,
 
26
    TestCaseWithTransport,
 
27
    )
 
28
from .matchers import *
23
29
 
24
30
 
25
31
class StubTree(object):
62
68
        self.assertNotEqual(None, mismatch)
63
69
        self.assertThat(mismatch.describe(), Equals("I am da tree is locked"))
64
70
 
 
71
 
 
72
class TestMatchesAncestry(TestCaseWithTransport):
 
73
 
 
74
    def test__str__(self):
 
75
        matcher = MatchesAncestry("A repository", b"arevid")
 
76
        self.assertEqual(
 
77
            "MatchesAncestry(repository='A repository', "
 
78
            "revision_id=%r)" % (b'arevid', ),
 
79
            str(matcher))
 
80
 
 
81
    def test_match(self):
 
82
        b = self.make_branch_builder('.')
 
83
        b.start_series()
 
84
        revid1 = b.build_commit()
 
85
        revid2 = b.build_commit()
 
86
        b.finish_series()
 
87
        branch = b.get_branch()
 
88
        m = MatchesAncestry(branch.repository, revid2)
 
89
        self.assertThat([revid2, revid1], m)
 
90
        self.assertThat([revid1, revid2], m)
 
91
        m = MatchesAncestry(branch.repository, revid1)
 
92
        self.assertThat([revid1], m)
 
93
        m = MatchesAncestry(branch.repository, b"unknown")
 
94
        self.assertThat([b"unknown"], m)
 
95
 
 
96
    def test_mismatch(self):
 
97
        b = self.make_branch_builder('.')
 
98
        b.start_series()
 
99
        revid1 = b.build_commit()
 
100
        revid2 = b.build_commit()
 
101
        b.finish_series()
 
102
        branch = b.get_branch()
 
103
        m = MatchesAncestry(branch.repository, revid1)
 
104
        mismatch = m.match([])
 
105
        self.assertIsNot(None, mismatch)
 
106
        self.assertEqual(
 
107
            "mismatched ancestry for revision %r was [%r], expected []" % (
 
108
                revid1, revid1),
 
109
            mismatch.describe())
 
110
 
 
111
 
 
112
class TestHasLayout(TestCaseWithTransport):
 
113
 
 
114
    def test__str__(self):
 
115
        matcher = HasLayout([(b"a", b"a-id")])
 
116
        self.assertEqual("HasLayout(%r)" % ([(b'a', b'a-id')], ), str(matcher))
 
117
 
 
118
    def test_match(self):
 
119
        t = self.make_branch_and_tree('.')
 
120
        self.build_tree(['a', 'b/', 'b/c'])
 
121
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
 
122
        self.assertThat(t, HasLayout(['', 'a', 'b/', 'b/c']))
 
123
        self.assertThat(t, HasLayout(
 
124
            [('', t.get_root_id()),
 
125
             ('a', b'a-id'),
 
126
             ('b/', b'b-id'),
 
127
             ('b/c', b'c-id')]))
 
128
 
 
129
    def test_mismatch(self):
 
130
        t = self.make_branch_and_tree('.')
 
131
        self.build_tree(['a', 'b/', 'b/c'])
 
132
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
 
133
        mismatch = HasLayout(['a']).match(t)
 
134
        self.assertIsNot(None, mismatch)
 
135
        self.assertEqual(
 
136
            set(("[u'', u'a', u'b/', u'b/c']", "['a']")),
 
137
            set(mismatch.describe().split(" != ")))
 
138
 
 
139
    def test_no_dirs(self):
 
140
        # Some tree/repository formats do not support versioned directories
 
141
        t = self.make_branch_and_tree('.')
 
142
        t.has_versioned_directories = lambda: False
 
143
        self.build_tree(['a', 'b/', 'b/c'])
 
144
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
 
145
        self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c']).match(t))
 
146
        self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c', 'd/']).match(t))
 
147
        mismatch = HasLayout([u'', u'a', u'd/']).match(t)
 
148
        self.assertIsNot(None, mismatch)
 
149
        self.assertEqual(
 
150
            set(("[u'', u'a', u'b/', u'b/c']", "[u'', u'a']")),
 
151
            set(mismatch.describe().split(" != ")))
 
152
 
 
153
 
 
154
class TestHasPathRelations(TestCaseWithTransport):
 
155
 
 
156
    def test__str__(self):
 
157
        t = self.make_branch_and_tree('.')
 
158
        matcher = HasPathRelations(t, [("a", "b")])
 
159
        self.assertEqual("HasPathRelations(%r, %r)" % (t, [('a', 'b')]), str(matcher))
 
160
 
 
161
    def test_match(self):
 
162
        t = self.make_branch_and_tree('.')
 
163
        self.build_tree(['a', 'b/', 'b/c'])
 
164
        t.add(['a', 'b', 'b/c'])
 
165
        self.assertThat(t, HasPathRelations(t,
 
166
            [('', ''),
 
167
             ('a', 'a'),
 
168
             ('b/', 'b/'),
 
169
             ('b/c', 'b/c')]))
 
170
 
 
171
    def test_mismatch(self):
 
172
        t = self.make_branch_and_tree('.')
 
173
        self.build_tree(['a', 'b/', 'b/c'])
 
174
        t.add(['a', 'b', 'b/c'])
 
175
        mismatch = HasPathRelations(t, [('a', 'a')]).match(t)
 
176
        self.assertIsNot(None, mismatch)
 
177
 
 
178
 
 
179
class TestContainsNoVfsCalls(TestCase):
 
180
 
 
181
    def _make_call(self, method, args):
 
182
        return CapturedCall(CallHookParams(method, args, None, None, None), 0)
 
183
 
 
184
    def test__str__(self):
 
185
        self.assertEqual("ContainsNoVfsCalls()", str(ContainsNoVfsCalls()))
 
186
 
 
187
    def test_empty(self):
 
188
        self.assertIs(None, ContainsNoVfsCalls().match([]))
 
189
 
 
190
    def test_no_vfs_calls(self):
 
191
        calls = [self._make_call("Branch.get_config_file", [])]
 
192
        self.assertIs(None, ContainsNoVfsCalls().match(calls))
 
193
 
 
194
    def test_ignores_unknown(self):
 
195
        calls = [self._make_call("unknown", [])]
 
196
        self.assertIs(None, ContainsNoVfsCalls().match(calls))
 
197
 
 
198
    def test_match(self):
 
199
        calls = [self._make_call("append", ["file"]),
 
200
                 self._make_call("Branch.get_config_file", [])]
 
201
        mismatch = ContainsNoVfsCalls().match(calls)
 
202
        self.assertIsNot(None, mismatch)
 
203
        self.assertEqual([calls[0].call], mismatch.vfs_calls)
 
204
        self.assertEqual("no VFS calls expected, got: append('file')""",
 
205
                mismatch.describe())
 
206
 
 
207
 
 
208
class TestRevisionHistoryMatches(TestCaseWithTransport):
 
209
 
 
210
    def test_empty(self):
 
211
        tree = self.make_branch_and_tree('.')
 
212
        matcher = RevisionHistoryMatches([])
 
213
        self.assertIs(None, matcher.match(tree.branch))
 
214
 
 
215
    def test_matches(self):
 
216
        tree = self.make_branch_and_tree('.')
 
217
        tree.commit('msg1', rev_id=b'a')
 
218
        tree.commit('msg2', rev_id=b'b')
 
219
        matcher = RevisionHistoryMatches(['a', 'b'])
 
220
        self.assertIs(None, matcher.match(tree.branch))
 
221
 
 
222
    def test_mismatch(self):
 
223
        tree = self.make_branch_and_tree('.')
 
224
        tree.commit('msg1', rev_id=b'a')
 
225
        tree.commit('msg2', rev_id=b'b')
 
226
        matcher = RevisionHistoryMatches(['a', 'b', 'c'])
 
227
        self.assertEqual(
 
228
            set(("['a', 'b']", "['a', 'b', 'c']")),
 
229
            set(matcher.match(tree.branch).describe().split(" != ")))