~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_matchers.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
18
18
 
19
19
from testtools.matchers import *
20
20
 
 
21
from bzrlib.smart.client import CallHookParams
 
22
 
21
23
from bzrlib.tests import (
 
24
    CapturedCall,
22
25
    TestCase,
23
26
    TestCaseWithTransport,
24
27
    )
100
103
        m = MatchesAncestry(branch.repository, revid1)
101
104
        mismatch = m.match([])
102
105
        self.assertIsNot(None, mismatch)
103
 
        self.assertEquals(
 
106
        self.assertEqual(
104
107
            "mismatched ancestry for revision '%s' was ['%s'], expected []" % (
105
108
                revid1, revid1),
106
109
            mismatch.describe())
129
132
        t.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
130
133
        mismatch = HasLayout(['a']).match(t)
131
134
        self.assertIsNot(None, mismatch)
132
 
        self.assertEquals(
 
135
        self.assertEqual(
133
136
            "['a'] != [u'', u'a', u'b/', u'b/c']",
134
137
            mismatch.describe())
135
138
 
143
146
        self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c', 'd/']).match(t))
144
147
        mismatch = HasLayout([u'', u'a', u'd/']).match(t)
145
148
        self.assertIsNot(None, mismatch)
146
 
        self.assertEquals(
 
149
        self.assertEqual(
147
150
            "[u'', u'a'] != [u'', u'a', u'b/', u'b/c']",
148
151
            mismatch.describe())
 
152
 
 
153
 
 
154
class TestContainsNoVfsCalls(TestCase):
 
155
 
 
156
    def _make_call(self, method, args):
 
157
        return CapturedCall(CallHookParams(method, args, None, None, None), 0)
 
158
 
 
159
    def test__str__(self):
 
160
        self.assertEqual("ContainsNoVfsCalls()", str(ContainsNoVfsCalls()))
 
161
 
 
162
    def test_empty(self):
 
163
        self.assertIs(None, ContainsNoVfsCalls().match([]))
 
164
 
 
165
    def test_no_vfs_calls(self):
 
166
        calls = [self._make_call("Branch.get_config_file", [])]
 
167
        self.assertIs(None, ContainsNoVfsCalls().match(calls))
 
168
 
 
169
    def test_ignores_unknown(self):
 
170
        calls = [self._make_call("unknown", [])]
 
171
        self.assertIs(None, ContainsNoVfsCalls().match(calls))
 
172
 
 
173
    def test_match(self):
 
174
        calls = [self._make_call("append", ["file"]),
 
175
                 self._make_call("Branch.get_config_file", [])]
 
176
        mismatch = ContainsNoVfsCalls().match(calls)
 
177
        self.assertIsNot(None, mismatch)
 
178
        self.assertEqual([calls[0].call], mismatch.vfs_calls)
 
179
        self.assertEqual("no VFS calls expected, got: append('file')""",
 
180
                mismatch.describe())
 
181
 
 
182
 
 
183
class TestRevisionHistoryMatches(TestCaseWithTransport):
 
184
 
 
185
    def test_empty(self):
 
186
        tree = self.make_branch_and_tree('.')
 
187
        matcher = RevisionHistoryMatches([])
 
188
        self.assertIs(None, matcher.match(tree.branch))
 
189
 
 
190
    def test_matches(self):
 
191
        tree = self.make_branch_and_tree('.')
 
192
        tree.commit('msg1', rev_id='a')
 
193
        tree.commit('msg2', rev_id='b')
 
194
        matcher = RevisionHistoryMatches(['a', 'b'])
 
195
        self.assertIs(None, matcher.match(tree.branch))
 
196
 
 
197
    def test_mismatch(self):
 
198
        tree = self.make_branch_and_tree('.')
 
199
        tree.commit('msg1', rev_id='a')
 
200
        tree.commit('msg2', rev_id='b')
 
201
        matcher = RevisionHistoryMatches(['a', 'b', 'c'])
 
202
        self.assertEqual(
 
203
            "['a', 'b', 'c'] != ['a', 'b']",
 
204
            matcher.match(tree.branch).describe())