コード例 #1
0
    def test_instance_binding(self):
        instance = object()
        binding = Binding(object)

        instance_binding = binding.__get__(instance, None)

        self.assertEqual(instance_binding.instance_args, [instance])
コード例 #2
0
    def test_inner_attr_proxy_test(self):
        inner = mock.Mock()
        inner.x = 10

        binding = Binding(inner)

        self.assertEqual(binding.x, inner.x)
コード例 #3
0
    def test_call_inner_pass_through_signal(self):
        def inner(*_, **__):
            raise signals.TestPass('DETAILS')

        binding = Binding(inner, instance_args=['test'])

        try:
            binding()
        except signals.TestPass as signal:
            self.assertEqual(signal.details, 'DETAILS')
コード例 #4
0
    def test_call_inner_fail_on_false(self):
        def inner(*_, **__):
            return False

        binding = Binding(inner, instance_args=['test'])

        try:
            binding()
        except signals.TestFailure:
            pass
コード例 #5
0
    def test_call_inner_pass_on_true(self):
        def inner(*args, **kwargs):
            return True

        binding = Binding(inner, instance_args=['test'])

        try:
            binding()
        except signals.TestPass:
            pass
コード例 #6
0
    def test_call_inner_pass_on_none(self):
        def inner(*args, **kwargs):
            pass

        binding = Binding(inner)

        try:
            binding()
        except signals.TestPass:
            pass
コード例 #7
0
    def test_inner_attr_proxy_test(self):
        def some_func():
            pass

        inner = some_func
        inner.x = 10

        binding = Binding(inner)

        self.assertEqual(binding.x, inner.x)
コード例 #8
0
    def test_signal_modify(self):
        def inner(*_, **__):
            raise signals.TestPass('DETAILS')

        def signal_modifier(_, signal, *__, **___):
            raise signals.TestFailure(signal.details)

        binding = Binding(inner, signal_modifier=signal_modifier)

        try:
            binding()
        except signals.TestFailure as signal:
            self.assertEqual(signal.details, 'DETAILS')
コード例 #9
0
    def test_call_inner(self):
        self.inner_args = []
        self.inner_kwargs = {}

        def inner(*args, **kwargs):
            self.inner_args = args
            self.inner_kwargs = kwargs

        binding = Binding(inner, instance_args=['test'])

        try:
            binding('arg', v=2)
        except signals.TestSignal:
            pass

        self.assertEqual(self.inner_args, ('test', 'arg'))
        self.assertEqual(self.inner_kwargs, {'v': 2})
コード例 #10
0
    def test_call_after(self):

        self.has_called_after = False

        def after(*_, **__):
            self.has_called_after = True

        def inner(*_, **__):
            self.assertFalse(self.has_called_after)

        binding = Binding(inner, after=after)

        try:
            binding()
        except signals.TestSignal:
            pass

        self.assertTrue(self.has_called_after)
コード例 #11
0
    def test_call_before(self):

        self.has_called_before = False

        def before(*_, **__):
            self.has_called_before = True

        def inner(*_, **__):
            self.assertTrue(self.has_called_before)

        binding = Binding(inner, before=before)

        try:
            binding()
        except signals.TestSignal:
            pass

        self.assertTrue(self.has_called_before)
コード例 #12
0
    def test_arg_modifier(self):
        self.inner_args = []
        self.inner_kwargs = {}

        def arg_modifier(_, *args, **kwargs):
            new_args = list(args) + ['new arg']
            new_kwargs = dict(kwargs, kw='value')

            return new_args, new_kwargs

        def inner(*args, **kwargs):
            self.inner_args = args
            self.inner_kwargs = kwargs

        binding = Binding(inner, arg_modifier=arg_modifier)

        try:
            binding('arg', v=2)
        except signals.TestSignal:
            pass

        self.assertEqual(self.inner_args, ('arg', 'new arg'))
        self.assertEqual(self.inner_kwargs, {'v': 2, 'kw': 'value'})
コード例 #13
0
ファイル: bindings.py プロジェクト: williamfzc/acts_mirror
 def _inner(func):
     return Binding(inner=func,
                    arg_modifier=_arg_modifier,
                    before=_before,
                    after=_after)