/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/plugins/weave_fmt/test_store.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-20 23:20:37 UTC
  • mto: (6973.5.1 python3-c)
  • mto: This revision was merged to the branch mainline in revision 6984.
  • Revision ID: jelmer@jelmer.uk-20180520232037-inu6kdob1k6gwsyd
Fix a bunch of tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        self.assertEqual(f.read(), value)
43
43
 
44
44
    def fill_store(self, store):
45
 
        store.add(BytesIO(b'hello'), 'a')
46
 
        store.add(BytesIO(b'other'), 'b')
47
 
        store.add(BytesIO(b'something'), 'c')
48
 
        store.add(BytesIO(b'goodbye'), '123123')
 
45
        store.add(BytesIO(b'hello'), b'a')
 
46
        store.add(BytesIO(b'other'), b'b')
 
47
        store.add(BytesIO(b'something'), b'c')
 
48
        store.add(BytesIO(b'goodbye'), b'123123')
49
49
 
50
50
    def test_get(self):
51
51
        store = self.get_store()
62
62
        """Multiple add with same ID should raise a BzrError"""
63
63
        store = self.get_store()
64
64
        self.fill_store(store)
65
 
        self.assertRaises(BzrError, store.add, BytesIO(b'goodbye'), '123123')
 
65
        self.assertRaises(BzrError, store.add, BytesIO(b'goodbye'), b'123123')
66
66
 
67
67
 
68
68
class TestCompressedTextStore(TestCaseInTempDir, TestStores):
74
74
    def test_total_size(self):
75
75
        store = self.get_store(u'.')
76
76
        store.register_suffix('dsc')
77
 
        store.add(BytesIO(b'goodbye'), '123123')
78
 
        store.add(BytesIO(b'goodbye2'), '123123', 'dsc')
 
77
        store.add(BytesIO(b'goodbye'), b'123123')
 
78
        store.add(BytesIO(b'goodbye2'), b'123123', 'dsc')
79
79
        # these get gzipped - content should be stable
80
80
        self.assertEqual(store.total_size(), (2, 55))
81
81
 
83
83
        my_store = TextStore(MockTransport(),
84
84
                             prefixed=True, compressed=True)
85
85
        my_store.register_suffix('dsc')
86
 
        self.assertEqual('45/foo.dsc', my_store._relpath('foo', ['dsc']))
 
86
        self.assertEqual('45/foo.dsc', my_store._relpath(b'foo', ['dsc']))
87
87
 
88
88
 
89
89
class TestMemoryStore(TestCase):
106
106
 
107
107
    def test_adding_fails_when_present(self):
108
108
        my_store = self.get_store()
109
 
        my_store.add(BytesIO(b'hello'), 'aa')
 
109
        my_store.add(BytesIO(b'hello'), b'aa')
110
110
        self.assertRaises(BzrError,
111
 
                          my_store.add, BytesIO(b'hello'), 'aa')
 
111
                          my_store.add, BytesIO(b'hello'), b'aa')
112
112
 
113
113
    def test_total_size(self):
114
114
        store = self.get_store()
115
 
        store.add(BytesIO(b'goodbye'), '123123')
116
 
        store.add(BytesIO(b'goodbye2'), '123123.dsc')
 
115
        store.add(BytesIO(b'goodbye'), b'123123')
 
116
        store.add(BytesIO(b'goodbye2'), b'123123.dsc')
117
117
        self.assertEqual(store.total_size(), (2, 15))
118
118
        # TODO: Switch the exception form UnlistableStore to
119
119
        #       or make Stores throw UnlistableStore if their
130
130
 
131
131
    def test_total_size(self):
132
132
        store = self.get_store()
133
 
        store.add(BytesIO(b'goodbye'), '123123')
134
 
        store.add(BytesIO(b'goodbye2'), '123123.dsc')
 
133
        store.add(BytesIO(b'goodbye'), b'123123')
 
134
        store.add(BytesIO(b'goodbye2'), b'123123.dsc')
135
135
        self.assertEqual(store.total_size(), (2, 15))
136
136
        # TODO: Switch the exception form UnlistableStore to
137
137
        #       or make Stores throw UnlistableStore if their
229
229
 
230
230
    def test__relpath_invalid(self):
231
231
        my_store = TransportStore(MockTransport())
232
 
        self.assertRaises(ValueError, my_store._relpath, '/foo')
233
 
        self.assertRaises(ValueError, my_store._relpath, 'foo/')
 
232
        self.assertRaises(ValueError, my_store._relpath, b'/foo')
 
233
        self.assertRaises(ValueError, my_store._relpath, b'foo/')
234
234
 
235
235
    def test_register_invalid_suffixes(self):
236
236
        my_store = TransportStore(MockTransport())
239
239
 
240
240
    def test__relpath_unregister_suffixes(self):
241
241
        my_store = TransportStore(MockTransport())
242
 
        self.assertRaises(ValueError, my_store._relpath, 'foo', ['gz'])
243
 
        self.assertRaises(ValueError, my_store._relpath, 'foo', ['dsc', 'gz'])
 
242
        self.assertRaises(ValueError, my_store._relpath, b'foo', [b'gz'])
 
243
        self.assertRaises(ValueError, my_store._relpath, b'foo', [b'dsc', b'gz'])
244
244
 
245
245
    def test__relpath_simple(self):
246
246
        my_store = TransportStore(MockTransport())
247
 
        self.assertEqual("foo", my_store._relpath('foo'))
 
247
        self.assertEqual("foo", my_store._relpath(b'foo'))
248
248
 
249
249
    def test__relpath_prefixed(self):
250
250
        my_store = TransportStore(MockTransport(), True)
251
 
        self.assertEqual('45/foo', my_store._relpath('foo'))
 
251
        self.assertEqual('45/foo', my_store._relpath(b'foo'))
252
252
 
253
253
    def test__relpath_simple_suffixed(self):
254
254
        my_store = TransportStore(MockTransport())
255
255
        my_store.register_suffix('bar')
256
256
        my_store.register_suffix('baz')
257
 
        self.assertEqual('foo.baz', my_store._relpath('foo', ['baz']))
258
 
        self.assertEqual('foo.bar.baz', my_store._relpath('foo', ['bar', 'baz']))
 
257
        self.assertEqual('foo.baz', my_store._relpath(b'foo', ['baz']))
 
258
        self.assertEqual('foo.bar.baz', my_store._relpath(b'foo', ['bar', 'baz']))
259
259
 
260
260
    def test__relpath_prefixed_suffixed(self):
261
261
        my_store = TransportStore(MockTransport(), True)
262
262
        my_store.register_suffix('bar')
263
263
        my_store.register_suffix('baz')
264
 
        self.assertEqual('45/foo.baz', my_store._relpath('foo', ['baz']))
 
264
        self.assertEqual('45/foo.baz', my_store._relpath(b'foo', [b'baz']))
265
265
        self.assertEqual('45/foo.bar.baz',
266
 
                         my_store._relpath('foo', ['bar', 'baz']))
 
266
                         my_store._relpath(b'foo', [b'bar', b'baz']))
267
267
 
268
268
    def test_add_simple(self):
269
269
        stream = BytesIO(b"content")
270
270
        my_store = InstrumentedTransportStore(MockTransport())
271
 
        my_store.add(stream, "foo")
 
271
        my_store.add(stream, b"foo")
272
272
        self.assertEqual([("_add", "foo", stream)], my_store._calls)
273
273
 
274
274
    def test_add_prefixed(self):
275
275
        stream = BytesIO(b"content")
276
276
        my_store = InstrumentedTransportStore(MockTransport(), True)
277
 
        my_store.add(stream, "foo")
 
277
        my_store.add(stream, b"foo")
278
278
        self.assertEqual([("_add", "45/foo", stream)], my_store._calls)
279
279
 
280
280
    def test_add_simple_suffixed(self):
281
281
        stream = BytesIO(b"content")
282
282
        my_store = InstrumentedTransportStore(MockTransport())
283
283
        my_store.register_suffix('dsc')
284
 
        my_store.add(stream, "foo", 'dsc')
 
284
        my_store.add(stream, b"foo", b'dsc')
285
285
        self.assertEqual([("_add", "foo.dsc", stream)], my_store._calls)
286
286
 
287
287
    def test_add_simple_suffixed(self):
288
288
        stream = BytesIO(b"content")
289
289
        my_store = InstrumentedTransportStore(MockTransport(), True)
290
290
        my_store.register_suffix('dsc')
291
 
        my_store.add(stream, "foo", 'dsc')
 
291
        my_store.add(stream, b"foo", b'dsc')
292
292
        self.assertEqual([("_add", "45/foo.dsc", stream)], my_store._calls)
293
293
 
294
294
    def get_populated_store(self, prefixed=False,
297
297
                               compressed=compressed)
298
298
        my_store.register_suffix('sig')
299
299
        stream = BytesIO(b"signature")
300
 
        my_store.add(stream, "foo", 'sig')
 
300
        my_store.add(stream, b"foo", 'sig')
301
301
        stream = BytesIO(b"content")
302
 
        my_store.add(stream, "foo")
 
302
        my_store.add(stream, b"foo")
303
303
        stream = BytesIO(b"signature for missing base")
304
 
        my_store.add(stream, "missing", 'sig')
 
304
        my_store.add(stream, b"missing", 'sig')
305
305
        return my_store
306
306
 
307
307
    def test_has_simple(self):
346
346
        my_store = TextStore(MemoryTransport(),
347
347
                             prefixed=False, compressed=False)
348
348
        stream = BytesIO(b"content")
349
 
        my_store.add(stream, "foo")
350
 
        self.assertEqual({'foo'},
 
349
        my_store.add(stream, b"foo")
 
350
        self.assertEqual({b'foo'},
351
351
                         set(my_store.__iter__()))
352
352
 
353
353
    def test___iter__(self):
369
369
 
370
370
    def test_relpath_escaped(self):
371
371
        my_store = TransportStore(MemoryTransport())
372
 
        self.assertEqual('%25', my_store._relpath('%'))
 
372
        self.assertEqual('%25', my_store._relpath(b'%'))
373
373
 
374
374
    def test_escaped_uppercase(self):
375
375
        """Uppercase letters are escaped for safety on Windows"""
376
376
        my_store = TransportStore(MemoryTransport(), prefixed=True,
377
377
            escaped=True)
378
378
        # a particularly perverse file-id! :-)
379
 
        self.assertEqual(my_store._relpath('C:<>'), 'be/%2543%253a%253c%253e')
 
379
        self.assertEqual(my_store._relpath(b'C:<>'), 'be/%2543%253a%253c%253e')
380
380
 
381
381
 
382
382
class TestVersionFileStore(TestCaseWithTransport):