/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

Merge bzr.dev r3466

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008 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
24
24
    )
25
25
from bzrlib.errors import BzrBadParameterNotString, NoSuchFile, ReadOnlyError
26
26
from bzrlib.lockable_files import LockableFiles, TransportLock
 
27
from bzrlib.symbol_versioning import (
 
28
    deprecated_in,
 
29
    )
27
30
from bzrlib.tests import TestCaseInTempDir
28
31
from bzrlib.tests.test_smart import TestCaseWithSmartMedium
29
32
from bzrlib.tests.test_transactions import DummyWeave
35
38
 
36
39
 
37
40
# these tests are applied in each parameterized suite for LockableFiles
 
41
#
 
42
# they use an old style of parameterization, but we want to remove this class
 
43
# so won't modernize them now. - mbp 20080430
38
44
class _TestLockableFiles_mixin(object):
39
45
 
40
46
    def test_read_write(self):
41
 
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
42
 
        self.assertRaises(NoSuchFile, self.lockable.get_utf8, 'foo')
 
47
        self.assertRaises(NoSuchFile,
 
48
            self.applyDeprecated,
 
49
            deprecated_in((1, 5, 0)),
 
50
            self.lockable.get, 'foo')
 
51
        self.assertRaises(NoSuchFile,
 
52
            self.applyDeprecated,
 
53
            deprecated_in((1, 5, 0)),
 
54
            self.lockable.get_utf8, 'foo')
43
55
        self.lockable.lock_write()
44
56
        try:
45
57
            unicode_string = u'bar\u1234'
46
58
            self.assertEqual(4, len(unicode_string))
47
59
            byte_string = unicode_string.encode('utf-8')
48
60
            self.assertEqual(6, len(byte_string))
49
 
            self.assertRaises(UnicodeEncodeError, self.lockable.put, 'foo',
50
 
                              StringIO(unicode_string))
51
 
            self.lockable.put('foo', StringIO(byte_string))
52
 
            self.assertEqual(byte_string,
53
 
                             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())
 
75
            unicode_stream = self.applyDeprecated(
 
76
                deprecated_in((1, 5, 0)),
 
77
                self.lockable.get_utf8,
 
78
                'foo')
54
79
            self.assertEqual(unicode_string,
55
 
                             self.lockable.get_utf8('foo').read())
 
80
                unicode_stream.read())
56
81
            self.assertRaises(BzrBadParameterNotString,
57
 
                              self.lockable.put_utf8,
58
 
                              'bar',
59
 
                              StringIO(unicode_string)
60
 
                              )
61
 
            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)
 
92
            unicode_stream = self.applyDeprecated(
 
93
                deprecated_in((1, 5, 0)),
 
94
                self.lockable.get_utf8,
 
95
                'bar')
62
96
            self.assertEqual(unicode_string,
63
 
                             self.lockable.get_utf8('bar').read())
64
 
            self.assertEqual(byte_string,
65
 
                             self.lockable.get('bar').read())
66
 
            self.lockable.put_bytes('raw', 'raw\xffbytes')
67
 
            self.assertEqual('raw\xffbytes',
68
 
                             self.lockable.get('raw').read())
 
97
                unicode_stream.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())
69
112
        finally:
70
113
            self.lockable.unlock()
71
114
 
72
115
    def test_locks(self):
73
116
        self.lockable.lock_read()
74
117
        try:
75
 
            self.assertRaises(ReadOnlyError, self.lockable.put, 'foo', 
 
118
            self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',
76
119
                              StringIO('bar\u1234'))
77
120
        finally:
78
121
            self.lockable.unlock()