~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_store.py

(John Arbash Meinel) Update dirstate._iter_changes to return unicode for all paths (bug #92608)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007 Canonical Ltd
 
1
# Copyright (C) 2005 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
38
38
        f = store.get(fileid)
39
39
        self.assertEqual(f.read(), value)
40
40
 
 
41
    def test_add_str_deprecated(self):
 
42
        os.mkdir('a')
 
43
        store = self.get_store('a')
 
44
        self.callDeprecated(['Passing a string to Store.add'
 
45
                             ' was deprecated in version 0.11.'],
 
46
                            store.add, 'foo', '1')
 
47
        self.assertEqual('foo', store.get('1').read())
 
48
 
41
49
    def fill_store(self, store):
42
50
        store.add(StringIO('hello'), 'a')
43
51
        store.add(StringIO('other'), 'b')
398
406
 
399
407
    def test_escaped_uppercase(self):
400
408
        """Uppercase letters are escaped for safety on Windows"""
401
 
        my_store = store.TransportStore(MemoryTransport(), prefixed=True,
402
 
            escaped=True)
 
409
        my_store = store.TransportStore(MemoryTransport(), escaped=True)
403
410
        # a particularly perverse file-id! :-)
404
 
        self.assertEquals(my_store._relpath('C:<>'), 'be/%2543%253a%253c%253e')
 
411
        self.assertEquals(my_store._escape_file_id('C:<>'), '%43%3a%3c%3e')
405
412
 
406
413
 
407
414
class TestVersionFileStore(TestCaseWithTransport):
408
415
 
409
 
    def get_scope(self):
410
 
        return self._transaction
411
 
 
412
416
    def setUp(self):
413
417
        super(TestVersionFileStore, self).setUp()
414
418
        self.vfstore = store.versioned.VersionedFileStore(MemoryTransport())
415
 
        self.vfstore.get_scope = self.get_scope
416
 
        self._transaction = None
417
419
 
418
420
    def test_get_weave_registers_dirty_in_write(self):
419
 
        self._transaction = transactions.WriteTransaction()
420
 
        vf = self.vfstore.get_weave_or_empty('id', self._transaction)
421
 
        self._transaction.finish()
422
 
        self._transaction = None
423
 
        self.assertRaises(errors.OutSideTransaction, vf.add_lines, 'b', [], [])
424
 
        self._transaction = transactions.WriteTransaction()
425
 
        vf = self.vfstore.get_weave('id', self._transaction)
426
 
        self._transaction.finish()
427
 
        self._transaction = None
428
 
        self.assertRaises(errors.OutSideTransaction, vf.add_lines, 'b', [], [])
 
421
        transaction = transactions.WriteTransaction()
 
422
        vf = self.vfstore.get_weave_or_empty('id', transaction)
 
423
        transaction.finish()
 
424
        self.assertRaises(errors.OutSideTransaction, vf.add_lines, 'b', [], [])
 
425
        transaction = transactions.WriteTransaction()
 
426
        vf = self.vfstore.get_weave('id', transaction)
 
427
        transaction.finish()
 
428
        self.assertRaises(errors.OutSideTransaction, vf.add_lines, 'b', [], [])
 
429
 
 
430
    def test_get_weave_or_empty_readonly_fails(self):
 
431
        transaction = transactions.ReadOnlyTransaction()
 
432
        vf = self.assertRaises(errors.ReadOnlyError,
 
433
                               self.vfstore.get_weave_or_empty,
 
434
                               'id',
 
435
                               transaction)
429
436
 
430
437
    def test_get_weave_readonly_cant_write(self):
431
 
        self._transaction = transactions.WriteTransaction()
432
 
        vf = self.vfstore.get_weave_or_empty('id', self._transaction)
433
 
        self._transaction.finish()
434
 
        self._transaction = transactions.ReadOnlyTransaction()
435
 
        vf = self.vfstore.get_weave_or_empty('id', self._transaction)
 
438
        transaction = transactions.WriteTransaction()
 
439
        vf = self.vfstore.get_weave_or_empty('id', transaction)
 
440
        transaction.finish()
 
441
        transaction = transactions.ReadOnlyTransaction()
 
442
        vf = self.vfstore.get_weave_or_empty('id', transaction)
436
443
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'b', [], [])
437
444
 
438
 
    def test___iter__escaped(self):
439
 
        self.vfstore = store.versioned.VersionedFileStore(MemoryTransport(),
440
 
            prefixed=True, escaped=True)
441
 
        self.vfstore.get_scope = self.get_scope
442
 
        self._transaction = transactions.WriteTransaction()
443
 
        vf = self.vfstore.get_weave_or_empty(' ', self._transaction)
444
 
        vf.add_lines('a', [], [])
445
 
        del vf
446
 
        self._transaction.finish()
447
 
        self.assertEqual([' '], list(self.vfstore))