/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: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from testtools.matchers import *
20
20
 
 
21
from ..smart.client import CallHookParams
 
22
 
21
23
from . import (
22
24
    CapturedCall,
23
25
    TestCase,
57
59
    def test_match(self):
58
60
        stub_tree = StubTree(False)
59
61
        matcher = ReturnsUnlockable(stub_tree)
60
 
        self.assertThat(matcher.match(lambda: FakeUnlockable()), Equals(None))
 
62
        self.assertThat(matcher.match(lambda:FakeUnlockable()), Equals(None))
61
63
 
62
64
    def test_mismatch(self):
63
65
        stub_tree = StubTree(True)
64
66
        matcher = ReturnsUnlockable(stub_tree)
65
 
        mismatch = matcher.match(lambda: FakeUnlockable())
 
67
        mismatch = matcher.match(lambda:FakeUnlockable())
66
68
        self.assertNotEqual(None, mismatch)
67
69
        self.assertThat(mismatch.describe(), Equals("I am da tree is locked"))
68
70
 
70
72
class TestMatchesAncestry(TestCaseWithTransport):
71
73
 
72
74
    def test__str__(self):
73
 
        matcher = MatchesAncestry("A repository", b"arevid")
 
75
        matcher = MatchesAncestry("A repository", "arevid")
74
76
        self.assertEqual(
75
77
            "MatchesAncestry(repository='A repository', "
76
 
            "revision_id=%r)" % (b'arevid', ),
 
78
            "revision_id='arevid')",
77
79
            str(matcher))
78
80
 
79
81
    def test_match(self):
88
90
        self.assertThat([revid1, revid2], m)
89
91
        m = MatchesAncestry(branch.repository, revid1)
90
92
        self.assertThat([revid1], m)
91
 
        m = MatchesAncestry(branch.repository, b"unknown")
92
 
        self.assertThat([b"unknown"], m)
 
93
        m = MatchesAncestry(branch.repository, "unknown")
 
94
        self.assertThat(["unknown"], m)
93
95
 
94
96
    def test_mismatch(self):
95
97
        b = self.make_branch_builder('.')
102
104
        mismatch = m.match([])
103
105
        self.assertIsNot(None, mismatch)
104
106
        self.assertEqual(
105
 
            "mismatched ancestry for revision %r was [%r], expected []" % (
 
107
            "mismatched ancestry for revision '%s' was ['%s'], expected []" % (
106
108
                revid1, revid1),
107
109
            mismatch.describe())
108
110
 
110
112
class TestHasLayout(TestCaseWithTransport):
111
113
 
112
114
    def test__str__(self):
113
 
        matcher = HasLayout([(b"a", b"a-id")])
114
 
        self.assertEqual("HasLayout(%r)" % ([(b'a', b'a-id')], ), str(matcher))
 
115
        matcher = HasLayout([("a", "a-id")])
 
116
        self.assertEqual("HasLayout([('a', 'a-id')])", str(matcher))
115
117
 
116
118
    def test_match(self):
117
119
        t = self.make_branch_and_tree('.')
118
120
        self.build_tree(['a', 'b/', 'b/c'])
119
 
        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'])
120
122
        self.assertThat(t, HasLayout(['', 'a', 'b/', 'b/c']))
121
123
        self.assertThat(t, HasLayout(
122
 
            [('', t.path2id('')),
123
 
             ('a', b'a-id'),
124
 
             ('b/', b'b-id'),
125
 
             ('b/c', b'c-id')]))
 
124
            [('', t.get_root_id()),
 
125
             ('a', 'a-id'),
 
126
             ('b/', 'b-id'),
 
127
             ('b/c', 'c-id')]))
126
128
 
127
129
    def test_mismatch(self):
128
130
        t = self.make_branch_and_tree('.')
129
131
        self.build_tree(['a', 'b/', 'b/c'])
130
 
        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'])
131
133
        mismatch = HasLayout(['a']).match(t)
132
134
        self.assertIsNot(None, mismatch)
133
135
        self.assertEqual(
134
 
            set(("['', 'a', 'b/', 'b/c']", "['a']")),
 
136
            set(("[u'', u'a', u'b/', u'b/c']", "['a']")),
135
137
            set(mismatch.describe().split(" != ")))
136
138
 
137
139
    def test_no_dirs(self):
139
141
        t = self.make_branch_and_tree('.')
140
142
        t.has_versioned_directories = lambda: False
141
143
        self.build_tree(['a', 'b/', 'b/c'])
142
 
        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'])
143
145
        self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c']).match(t))
144
146
        self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c', 'd/']).match(t))
145
147
        mismatch = HasLayout([u'', u'a', u'd/']).match(t)
146
148
        self.assertIsNot(None, mismatch)
147
149
        self.assertEqual(
148
 
            set(("['', 'a', 'b/', 'b/c']", "['', 'a']")),
 
150
            set(("[u'', u'a', u'b/', u'b/c']", "[u'', u'a']")),
149
151
            set(mismatch.describe().split(" != ")))
150
152
 
151
153
 
152
 
class TestHasPathRelations(TestCaseWithTransport):
 
154
class TestContainsNoVfsCalls(TestCase):
 
155
 
 
156
    def _make_call(self, method, args):
 
157
        return CapturedCall(CallHookParams(method, args, None, None, None), 0)
153
158
 
154
159
    def test__str__(self):
155
 
        t = self.make_branch_and_tree('.')
156
 
        matcher = HasPathRelations(t, [("a", "b")])
157
 
        self.assertEqual("HasPathRelations(%r, %r)" %
158
 
                         (t, [('a', 'b')]), str(matcher))
 
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))
159
172
 
160
173
    def test_match(self):
161
 
        t = self.make_branch_and_tree('.')
162
 
        self.build_tree(['a', 'b/', 'b/c'])
163
 
        t.add(['a', 'b', 'b/c'])
164
 
        self.assertThat(t, HasPathRelations(t,
165
 
                                            [('', ''),
166
 
                                             ('a', 'a'),
167
 
                                                ('b/', 'b/'),
168
 
                                                ('b/c', 'b/c')]))
169
 
 
170
 
    def test_mismatch(self):
171
 
        t = self.make_branch_and_tree('.')
172
 
        self.build_tree(['a', 'b/', 'b/c'])
173
 
        t.add(['a', 'b', 'b/c'])
174
 
        mismatch = HasPathRelations(t, [('a', 'a')]).match(t)
 
174
        calls = [self._make_call("append", ["file"]),
 
175
                 self._make_call("Branch.get_config_file", [])]
 
176
        mismatch = ContainsNoVfsCalls().match(calls)
175
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())
176
181
 
177
182
 
178
183
class TestRevisionHistoryMatches(TestCaseWithTransport):
184
189
 
185
190
    def test_matches(self):
186
191
        tree = self.make_branch_and_tree('.')
187
 
        tree.commit('msg1', rev_id=b'a')
188
 
        tree.commit('msg2', rev_id=b'b')
189
 
        matcher = RevisionHistoryMatches([b'a', b'b'])
 
192
        tree.commit('msg1', rev_id='a')
 
193
        tree.commit('msg2', rev_id='b')
 
194
        matcher = RevisionHistoryMatches(['a', 'b'])
190
195
        self.assertIs(None, matcher.match(tree.branch))
191
196
 
192
197
    def test_mismatch(self):
193
198
        tree = self.make_branch_and_tree('.')
194
 
        tree.commit('msg1', rev_id=b'a')
195
 
        tree.commit('msg2', rev_id=b'b')
196
 
        matcher = RevisionHistoryMatches([b'a', b'b', b'c'])
 
199
        tree.commit('msg1', rev_id='a')
 
200
        tree.commit('msg2', rev_id='b')
 
201
        matcher = RevisionHistoryMatches(['a', 'b', 'c'])
197
202
        self.assertEqual(
198
 
            set(("[b'a', b'b']", "[b'a', b'b', b'c']")),
 
203
            set(("['a', 'b']", "['a', 'b', 'c']")),
199
204
            set(matcher.match(tree.branch).describe().split(" != ")))