~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_decorators.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    pass
28
28
 
29
29
 
30
 
def create_decorator_sample(style, unlock_error=None):
 
30
def create_decorator_sample(style, unlock_error=None, meth=None):
31
31
    """Create a DecoratorSample object, using specific lock operators.
32
32
 
33
33
    :param style: The type of lock decorators to use (fast/pretty/None)
34
34
    :param unlock_error: If specified, an error to raise from unlock.
 
35
    :param meth: a function to be decorated and added as a 'meth_read' and
 
36
        'meth_write' to the object.
35
37
    :return: An instantiated DecoratorSample object.
36
38
    """
37
39
 
92
94
            self.actions.append('fail_during_write')
93
95
            raise TypeError('during write')
94
96
 
 
97
        if meth is not None:
 
98
            meth_read = needs_read_lock(meth)
 
99
            meth_write = needs_write_lock(meth)
 
100
 
95
101
    return DecoratorSample()
96
102
 
97
103
 
149
155
        self.assertEqual(['lock_write', ('bank', 'bar', 'bing'),
150
156
                          'unlock_fail'], sam.actions)
151
157
 
 
158
    def test_read_lock_preserves_default_str_kwarg_identity(self):
 
159
        a_constant = 'A str used as a constant'
 
160
        def meth(self, param=a_constant):
 
161
            return param
 
162
        sam = create_decorator_sample(self._decorator_style, meth=meth)
 
163
        self.assertIs(a_constant, sam.meth_read())
 
164
 
 
165
    def test_write_lock_preserves_default_str_kwarg_identity(self):
 
166
        a_constant = 'A str used as a constant'
 
167
        def meth(self, param=a_constant):
 
168
            return param
 
169
        sam = create_decorator_sample(self._decorator_style, meth=meth)
 
170
        self.assertIs(a_constant, sam.meth_write())
 
171
 
152
172
 
153
173
class TestFastDecoratorActions(TestDecoratorActions):
154
174