43
35
# these tests are applied in each parameterized suite for LockableFiles
45
# they use an old style of parameterization, but we want to remove this class
46
# so won't modernize them now. - mbp 20080430
47
36
class _TestLockableFiles_mixin(object):
49
38
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')
39
self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
40
self.assertRaises(NoSuchFile, self.lockable.get_utf8, 'foo')
58
41
self.lockable.lock_write()
60
43
unicode_string = u'bar\u1234'
61
44
self.assertEqual(4, len(unicode_string))
62
45
byte_string = unicode_string.encode('utf-8')
63
46
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,
47
self.assertRaises(UnicodeEncodeError, self.lockable.put, 'foo',
48
StringIO(unicode_string))
49
self.lockable.put('foo', StringIO(byte_string))
50
self.assertEqual(byte_string,
51
self.lockable.get('foo').read())
82
52
self.assertEqual(unicode_string,
83
unicode_stream.read())
53
self.lockable.get_utf8('foo').read())
84
54
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,
55
self.lockable.put_utf8,
57
StringIO(unicode_string)
59
self.lockable.put_utf8('bar', unicode_string)
99
60
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())
61
self.lockable.get_utf8('bar').read())
62
self.assertEqual(byte_string,
63
self.lockable.get('bar').read())
64
self.lockable.put_bytes('raw', 'raw\xffbytes')
65
self.assertEqual('raw\xffbytes',
66
self.lockable.get('raw').read())
116
68
self.lockable.unlock()
118
70
def test_locks(self):
119
71
self.lockable.lock_read()
121
self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',
73
self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',
122
74
StringIO('bar\u1234'))
124
76
self.lockable.unlock()
408
357
self.assertFalse(self.transport.has('my-lock/held/info'))
409
358
self.assertTrue(self.transport.has('my-lock'))
411
def test__file_modes(self):
412
self.transport.mkdir('readonly')
413
osutils.make_readonly('readonly')
414
lockable = LockableFiles(self.transport.clone('readonly'), 'test-lock',
416
# The directory mode should be read-write-execute for the current user
417
self.assertEqual(00700, lockable._dir_mode & 00700)
418
# Files should be read-write for the current user
419
self.assertEqual(00600, lockable._file_mode & 00700)
361
# TODO: Test the lockdir inherits the right file and directory permissions
362
# from the LockableFiles.
422
365
class TestLockableFiles_RemoteLockDir(TestCaseWithSmartMedium,
423
366
_TestLockableFiles_mixin):