~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockable_files.py

  • Committer: Robert Collins
  • Date: 2006-01-25 01:43:34 UTC
  • mto: (1534.1.15 integration)
  • mto: This revision was merged to the branch mainline in revision 1550.
  • Revision ID: robertc@robertcollins.net-20060125014334-8dd9ed73c26c5956
Implement final review suggestions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from StringIO import StringIO
18
18
 
19
19
from bzrlib.branch import Branch
20
 
from bzrlib.errors import NoSuchFile, ReadOnlyError
 
20
from bzrlib.errors import BzrBadParameterNotString, NoSuchFile, ReadOnlyError
21
21
from bzrlib.lockable_files import LockableFiles
22
22
from bzrlib.tests import TestCaseInTempDir
23
23
from bzrlib.transactions import PassThroughTransaction, ReadOnlyTransaction
33
33
        self.lockable = LockableFiles(transport.clone('.bzr'), 'my-lock')
34
34
 
35
35
    def test_read_write(self):
36
 
        self.assertRaises(NoSuchFile, self.lockable.controlfile, 'foo')
 
36
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
 
37
        self.assertRaises(NoSuchFile, self.lockable.get_utf8, 'foo')
37
38
        self.lockable.lock_write()
38
39
        try:
39
40
            unicode_string = u'bar\u1234'
44
45
                              StringIO(unicode_string))
45
46
            self.lockable.put('foo', StringIO(byte_string))
46
47
            self.assertEqual(byte_string,
47
 
                             self.lockable.controlfile('foo', 'rb').read())
 
48
                             self.lockable.get('foo').read())
48
49
            self.assertEqual(unicode_string,
49
 
                             self.lockable.controlfile('foo', 'r').read())
50
 
            self.lockable.put_utf8('bar', StringIO(unicode_string))
 
50
                             self.lockable.get_utf8('foo').read())
 
51
            self.assertRaises(BzrBadParameterNotString,
 
52
                              self.lockable.put_utf8,
 
53
                              'bar',
 
54
                              StringIO(unicode_string)
 
55
                              )
 
56
            self.lockable.put_utf8('bar', unicode_string)
51
57
            self.assertEqual(unicode_string, 
52
 
                             self.lockable.controlfile('bar', 'r').read())
 
58
                             self.lockable.get_utf8('bar').read())
53
59
            self.assertEqual(byte_string, 
54
 
                             self.lockable.controlfile('bar', 'rb').read())
 
60
                             self.lockable.get('bar').read())
55
61
        finally:
56
62
            self.lockable.unlock()
57
63