/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 bzrlib/tests/test_matchers.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010, 2011, 2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2010 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 breezy test matchers."""
 
17
"""Tests of bzrlib test matchers."""
18
18
 
19
19
from testtools.matchers import *
20
20
 
21
 
from ..bzr.smart.client import CallHookParams
 
21
from bzrlib.smart.client import CallHookParams
22
22
 
23
 
from . import (
 
23
from bzrlib.tests import (
24
24
    CapturedCall,
25
25
    TestCase,
26
26
    TestCaseWithTransport,
27
27
    )
28
 
from .matchers import *
 
28
from bzrlib.tests.matchers import *
29
29
 
30
30
 
31
31
class StubTree(object):
103
103
        m = MatchesAncestry(branch.repository, revid1)
104
104
        mismatch = m.match([])
105
105
        self.assertIsNot(None, mismatch)
106
 
        self.assertEqual(
 
106
        self.assertEquals(
107
107
            "mismatched ancestry for revision '%s' was ['%s'], expected []" % (
108
108
                revid1, revid1),
109
109
            mismatch.describe())
118
118
    def test_match(self):
119
119
        t = self.make_branch_and_tree('.')
120
120
        self.build_tree(['a', 'b/', 'b/c'])
121
 
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
 
121
        t.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
122
122
        self.assertThat(t, HasLayout(['', 'a', 'b/', 'b/c']))
123
123
        self.assertThat(t, HasLayout(
124
124
            [('', t.get_root_id()),
125
 
             ('a', b'a-id'),
126
 
             ('b/', b'b-id'),
127
 
             ('b/c', b'c-id')]))
 
125
             ('a', 'a-id'),
 
126
             ('b/', 'b-id'),
 
127
             ('b/c', 'c-id')]))
128
128
 
129
129
    def test_mismatch(self):
130
130
        t = self.make_branch_and_tree('.')
131
131
        self.build_tree(['a', 'b/', 'b/c'])
132
 
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
 
132
        t.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
133
133
        mismatch = HasLayout(['a']).match(t)
134
134
        self.assertIsNot(None, mismatch)
135
 
        self.assertEqual(
136
 
            set(("[u'', u'a', u'b/', u'b/c']", "['a']")),
137
 
            set(mismatch.describe().split(" != ")))
 
135
        self.assertEquals(
 
136
            "['a'] != [u'', u'a', u'b/', u'b/c']",
 
137
            mismatch.describe())
138
138
 
139
139
    def test_no_dirs(self):
140
140
        # Some tree/repository formats do not support versioned directories
141
141
        t = self.make_branch_and_tree('.')
142
142
        t.has_versioned_directories = lambda: False
143
143
        self.build_tree(['a', 'b/', 'b/c'])
144
 
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
 
144
        t.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
145
145
        self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c']).match(t))
146
146
        self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c', 'd/']).match(t))
147
147
        mismatch = HasLayout([u'', u'a', u'd/']).match(t)
148
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, [('a', 'b')])" % t, 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)
 
149
        self.assertEquals(
 
150
            "[u'', u'a'] != [u'', u'a', u'b/', u'b/c']",
 
151
            mismatch.describe())
177
152
 
178
153
 
179
154
class TestContainsNoVfsCalls(TestCase):
200
175
                 self._make_call("Branch.get_config_file", [])]
201
176
        mismatch = ContainsNoVfsCalls().match(calls)
202
177
        self.assertIsNot(None, mismatch)
203
 
        self.assertEqual([calls[0].call], mismatch.vfs_calls)
204
 
        self.assertEqual("no VFS calls expected, got: append('file')""",
 
178
        self.assertEquals([calls[0].call], mismatch.vfs_calls)
 
179
        self.assertEquals("no VFS calls expected, got: append('file')""",
205
180
                mismatch.describe())
206
181
 
207
182
 
214
189
 
215
190
    def test_matches(self):
216
191
        tree = self.make_branch_and_tree('.')
217
 
        tree.commit('msg1', rev_id=b'a')
218
 
        tree.commit('msg2', rev_id=b'b')
 
192
        tree.commit('msg1', rev_id='a')
 
193
        tree.commit('msg2', rev_id='b')
219
194
        matcher = RevisionHistoryMatches(['a', 'b'])
220
195
        self.assertIs(None, matcher.match(tree.branch))
221
196
 
222
197
    def test_mismatch(self):
223
198
        tree = self.make_branch_and_tree('.')
224
 
        tree.commit('msg1', rev_id=b'a')
225
 
        tree.commit('msg2', rev_id=b'b')
 
199
        tree.commit('msg1', rev_id='a')
 
200
        tree.commit('msg2', rev_id='b')
226
201
        matcher = RevisionHistoryMatches(['a', 'b', 'c'])
227
 
        self.assertEqual(
228
 
            set(("['a', 'b']", "['a', 'b', 'c']")),
229
 
            set(matcher.match(tree.branch).describe().split(" != ")))
 
202
        self.assertEquals(
 
203
            "['a', 'b', 'c'] != ['a', 'b']",
 
204
            matcher.match(tree.branch).describe())