/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: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    def test_match(self):
60
60
        stub_tree = StubTree(False)
61
61
        matcher = ReturnsUnlockable(stub_tree)
62
 
        self.assertThat(matcher.match(lambda:FakeUnlockable()), Equals(None))
 
62
        self.assertThat(matcher.match(lambda: FakeUnlockable()), Equals(None))
63
63
 
64
64
    def test_mismatch(self):
65
65
        stub_tree = StubTree(True)
66
66
        matcher = ReturnsUnlockable(stub_tree)
67
 
        mismatch = matcher.match(lambda:FakeUnlockable())
 
67
        mismatch = matcher.match(lambda: FakeUnlockable())
68
68
        self.assertNotEqual(None, mismatch)
69
69
        self.assertThat(mismatch.describe(), Equals("I am da tree is locked"))
70
70
 
72
72
class TestMatchesAncestry(TestCaseWithTransport):
73
73
 
74
74
    def test__str__(self):
75
 
        matcher = MatchesAncestry("A repository", "arevid")
 
75
        matcher = MatchesAncestry("A repository", b"arevid")
76
76
        self.assertEqual(
77
77
            "MatchesAncestry(repository='A repository', "
78
 
            "revision_id='arevid')",
 
78
            "revision_id=%r)" % (b'arevid', ),
79
79
            str(matcher))
80
80
 
81
81
    def test_match(self):
90
90
        self.assertThat([revid1, revid2], m)
91
91
        m = MatchesAncestry(branch.repository, revid1)
92
92
        self.assertThat([revid1], m)
93
 
        m = MatchesAncestry(branch.repository, "unknown")
94
 
        self.assertThat(["unknown"], m)
 
93
        m = MatchesAncestry(branch.repository, b"unknown")
 
94
        self.assertThat([b"unknown"], m)
95
95
 
96
96
    def test_mismatch(self):
97
97
        b = self.make_branch_builder('.')
104
104
        mismatch = m.match([])
105
105
        self.assertIsNot(None, mismatch)
106
106
        self.assertEqual(
107
 
            "mismatched ancestry for revision '%s' was ['%s'], expected []" % (
 
107
            "mismatched ancestry for revision %r was [%r], expected []" % (
108
108
                revid1, revid1),
109
109
            mismatch.describe())
110
110
 
112
112
class TestHasLayout(TestCaseWithTransport):
113
113
 
114
114
    def test__str__(self):
115
 
        matcher = HasLayout([("a", "a-id")])
116
 
        self.assertEqual("HasLayout([('a', 'a-id')])", str(matcher))
 
115
        matcher = HasLayout([(b"a", b"a-id")])
 
116
        self.assertEqual("HasLayout(%r)" % ([(b'a', b'a-id')], ), str(matcher))
117
117
 
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'], ['a-id', 'b-id', 'c-id'])
 
121
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
122
122
        self.assertThat(t, HasLayout(['', 'a', 'b/', 'b/c']))
123
123
        self.assertThat(t, HasLayout(
124
 
            [('', t.get_root_id()),
125
 
             ('a', 'a-id'),
126
 
             ('b/', 'b-id'),
127
 
             ('b/c', 'c-id')]))
 
124
            [('', t.path2id('')),
 
125
             ('a', b'a-id'),
 
126
             ('b/', b'b-id'),
 
127
             ('b/c', b'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'], ['a-id', 'b-id', 'c-id'])
 
132
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
133
133
        mismatch = HasLayout(['a']).match(t)
134
134
        self.assertIsNot(None, mismatch)
135
135
        self.assertEqual(
136
 
            set(("[u'', u'a', u'b/', u'b/c']", "['a']")),
 
136
            set(("['', 'a', 'b/', 'b/c']", "['a']")),
137
137
            set(mismatch.describe().split(" != ")))
138
138
 
139
139
    def test_no_dirs(self):
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'], ['a-id', 'b-id', 'c-id'])
 
144
        t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'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
149
        self.assertEqual(
150
 
            set(("[u'', u'a', u'b/', u'b/c']", "[u'', u'a']")),
 
150
            set(("['', 'a', 'b/', 'b/c']", "['', 'a']")),
151
151
            set(mismatch.describe().split(" != ")))
152
152
 
153
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)" %
 
160
                         (t, [('a', 'b')]), str(matcher))
 
161
 
 
162
    def test_match(self):
 
163
        t = self.make_branch_and_tree('.')
 
164
        self.build_tree(['a', 'b/', 'b/c'])
 
165
        t.add(['a', 'b', 'b/c'])
 
166
        self.assertThat(t, HasPathRelations(t,
 
167
                                            [('', ''),
 
168
                                             ('a', 'a'),
 
169
                                                ('b/', 'b/'),
 
170
                                                ('b/c', 'b/c')]))
 
171
 
 
172
    def test_mismatch(self):
 
173
        t = self.make_branch_and_tree('.')
 
174
        self.build_tree(['a', 'b/', 'b/c'])
 
175
        t.add(['a', 'b', 'b/c'])
 
176
        mismatch = HasPathRelations(t, [('a', 'a')]).match(t)
 
177
        self.assertIsNot(None, mismatch)
 
178
 
 
179
 
154
180
class TestContainsNoVfsCalls(TestCase):
155
181
 
156
182
    def _make_call(self, method, args):
171
197
        self.assertIs(None, ContainsNoVfsCalls().match(calls))
172
198
 
173
199
    def test_match(self):
174
 
        calls = [self._make_call("append", ["file"]),
175
 
                 self._make_call("Branch.get_config_file", [])]
 
200
        calls = [self._make_call(b"append", [b"file"]),
 
201
                 self._make_call(b"Branch.get_config_file", [])]
176
202
        mismatch = ContainsNoVfsCalls().match(calls)
177
203
        self.assertIsNot(None, mismatch)
178
204
        self.assertEqual([calls[0].call], mismatch.vfs_calls)
179
 
        self.assertEqual("no VFS calls expected, got: append('file')""",
180
 
                mismatch.describe())
 
205
        self.assertIn(mismatch.describe(), [
 
206
            "no VFS calls expected, got: b'append'(b'file')",
 
207
            "no VFS calls expected, got: append('file')"])
181
208
 
182
209
 
183
210
class TestRevisionHistoryMatches(TestCaseWithTransport):
189
216
 
190
217
    def test_matches(self):
191
218
        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'])
 
219
        tree.commit('msg1', rev_id=b'a')
 
220
        tree.commit('msg2', rev_id=b'b')
 
221
        matcher = RevisionHistoryMatches([b'a', b'b'])
195
222
        self.assertIs(None, matcher.match(tree.branch))
196
223
 
197
224
    def test_mismatch(self):
198
225
        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'])
 
226
        tree.commit('msg1', rev_id=b'a')
 
227
        tree.commit('msg2', rev_id=b'b')
 
228
        matcher = RevisionHistoryMatches([b'a', b'b', b'c'])
202
229
        self.assertEqual(
203
 
            set(("['a', 'b']", "['a', 'b', 'c']")),
 
230
            set(("[b'a', b'b']", "[b'a', b'b', b'c']")),
204
231
            set(matcher.match(tree.branch).describe().split(" != ")))