/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 bzrlib/tests/test_lockable_files.py

  • Committer: Martin Pool
  • Date: 2008-05-27 08:12:28 UTC
  • mfrom: (3453 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3455.
  • Revision ID: mbp@sourcefrog.net-20080527081228-2ft0nnz7edsz1jfa
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
class _TestLockableFiles_mixin(object):
45
45
 
46
46
    def test_read_write(self):
47
 
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
 
47
        self.assertRaises(NoSuchFile,
 
48
            self.applyDeprecated,
 
49
            deprecated_in((1, 5, 0)),
 
50
            self.lockable.get, 'foo')
48
51
        self.assertRaises(NoSuchFile,
49
52
            self.applyDeprecated,
50
53
            deprecated_in((1, 5, 0)),
55
58
            self.assertEqual(4, len(unicode_string))
56
59
            byte_string = unicode_string.encode('utf-8')
57
60
            self.assertEqual(6, len(byte_string))
58
 
            self.assertRaises(UnicodeEncodeError, self.lockable.put, 'foo',
59
 
                              StringIO(unicode_string))
60
 
            self.lockable.put('foo', StringIO(byte_string))
61
 
            self.assertEqual(byte_string,
62
 
                             self.lockable.get('foo').read())
 
61
            self.assertRaises(UnicodeEncodeError,
 
62
                self.applyDeprecated,
 
63
                deprecated_in((1, 6, 0)),
 
64
                self.lockable.put, 'foo',
 
65
                StringIO(unicode_string))
 
66
            self.applyDeprecated(
 
67
                deprecated_in((1, 6, 0)),
 
68
                self.lockable.put,
 
69
                'foo', StringIO(byte_string))
 
70
            byte_stream = self.applyDeprecated(
 
71
                deprecated_in((1, 5, 0)),
 
72
                self.lockable.get,
 
73
                'foo')
 
74
            self.assertEqual(byte_string, byte_stream.read())
63
75
            unicode_stream = self.applyDeprecated(
64
76
                deprecated_in((1, 5, 0)),
65
77
                self.lockable.get_utf8,
67
79
            self.assertEqual(unicode_string,
68
80
                unicode_stream.read())
69
81
            self.assertRaises(BzrBadParameterNotString,
70
 
                              self.lockable.put_utf8,
71
 
                              'bar',
72
 
                              StringIO(unicode_string)
73
 
                              )
74
 
            self.lockable.put_utf8('bar', unicode_string)
 
82
                self.applyDeprecated,
 
83
                deprecated_in((1, 6, 0)),
 
84
                self.lockable.put_utf8,
 
85
                'bar',
 
86
                StringIO(unicode_string))
 
87
            self.applyDeprecated(
 
88
                deprecated_in((1, 6, 0)),
 
89
                self.lockable.put_utf8,
 
90
                'bar',
 
91
                unicode_string)
75
92
            unicode_stream = self.applyDeprecated(
76
93
                deprecated_in((1, 5, 0)),
77
94
                self.lockable.get_utf8,
78
95
                'bar')
79
96
            self.assertEqual(unicode_string,
80
97
                unicode_stream.read())
81
 
            self.assertEqual(byte_string,
82
 
                             self.lockable.get('bar').read())
83
 
            self.lockable.put_bytes('raw', 'raw\xffbytes')
84
 
            self.assertEqual('raw\xffbytes',
85
 
                             self.lockable.get('raw').read())
 
98
            byte_stream = self.applyDeprecated(
 
99
                deprecated_in((1, 5, 0)),
 
100
                self.lockable.get,
 
101
                'bar')
 
102
            self.assertEqual(byte_string, byte_stream.read())
 
103
            self.applyDeprecated(
 
104
                deprecated_in((1, 6, 0)),
 
105
                self.lockable.put_bytes,
 
106
                'raw', 'raw\xffbytes')
 
107
            byte_stream = self.applyDeprecated(
 
108
                deprecated_in((1, 5, 0)),
 
109
                self.lockable.get,
 
110
                'raw')
 
111
            self.assertEqual('raw\xffbytes', byte_stream.read())
86
112
        finally:
87
113
            self.lockable.unlock()
88
114
 
89
115
    def test_locks(self):
90
116
        self.lockable.lock_read()
91
117
        try:
92
 
            self.assertRaises(ReadOnlyError, self.lockable.put, 'foo', 
 
118
            self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',
93
119
                              StringIO('bar\u1234'))
94
120
        finally:
95
121
            self.lockable.unlock()