46
46
# so won't modernize them now. - mbp 20080430
47
47
class _TestLockableFiles_mixin(object):
49
def test_read_write(self):
50
self.assertRaises(NoSuchFile,
52
deprecated_in((1, 5, 0)),
53
self.lockable.get, 'foo')
54
self.assertRaises(NoSuchFile,
56
deprecated_in((1, 5, 0)),
57
self.lockable.get_utf8, 'foo')
58
self.lockable.lock_write()
59
self.addCleanup(self.lockable.unlock)
60
unicode_string = u'bar\u1234'
61
self.assertEqual(4, len(unicode_string))
62
byte_string = unicode_string.encode('utf-8')
63
self.assertEqual(6, len(byte_string))
64
self.assertRaises(UnicodeEncodeError,
66
deprecated_in((1, 6, 0)),
67
self.lockable.put, 'foo',
68
StringIO(unicode_string))
70
deprecated_in((1, 6, 0)),
72
'foo', StringIO(byte_string))
73
byte_stream = self.applyDeprecated(
74
deprecated_in((1, 5, 0)),
77
self.assertEqual(byte_string, byte_stream.read())
78
unicode_stream = self.applyDeprecated(
79
deprecated_in((1, 5, 0)),
80
self.lockable.get_utf8,
82
self.assertEqual(unicode_string,
83
unicode_stream.read())
84
self.assertRaises(BzrBadParameterNotString,
86
deprecated_in((1, 6, 0)),
87
self.lockable.put_utf8,
89
StringIO(unicode_string))
91
deprecated_in((1, 6, 0)),
92
self.lockable.put_utf8,
95
unicode_stream = self.applyDeprecated(
96
deprecated_in((1, 5, 0)),
97
self.lockable.get_utf8,
99
self.assertEqual(unicode_string,
100
unicode_stream.read())
101
byte_stream = self.applyDeprecated(
102
deprecated_in((1, 5, 0)),
105
self.assertEqual(byte_string, byte_stream.read())
106
self.applyDeprecated(
107
deprecated_in((1, 6, 0)),
108
self.lockable.put_bytes,
109
'raw', 'raw\xffbytes')
110
byte_stream = self.applyDeprecated(
111
deprecated_in((1, 5, 0)),
114
self.assertEqual('raw\xffbytes', byte_stream.read())
116
def test_locks(self):
117
self.lockable.lock_read()
118
self.addCleanup(self.lockable.unlock)
119
self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',
120
StringIO('bar\u1234'))
49
122
def test_transactions(self):
50
123
self.assertIs(self.lockable.get_transaction().__class__,
51
124
PassThroughTransaction)
281
355
TestCaseInTempDir.setUp(self)
282
t = transport.get_transport('.')
284
self.sub_transport = t.clone('.bzr')
356
transport = get_transport('.')
357
transport.mkdir('.bzr')
358
self.sub_transport = transport.clone('.bzr')
285
359
self.lockable = self.get_lockable()
286
360
self.lockable.create_lock()
288
def stop_server(self):
289
super(TestLockableFiles_TransportLock, self).stop_server()
363
super(TestLockableFiles_TransportLock, self).tearDown()
290
364
# free the subtransport so that we do not get a 5 second
291
365
# timeout due to the SFTP connection cache.