예제 #1
0
    def test_extend_throws_error_when_service_id_does_not_exist(self):
        c = MedleyContainer()
        c._keys = Mock()
        c._keys.__contains__ = Mock(return_value=False)

        with self.assertRaises(Exception):
            c.extend('foo', self.foo)
예제 #2
0
    def test_extends_adds_wrapped_function_to_factories_when_exists(self):
        c = MedleyContainer()
        c._keys = set(['foo'])
        c._values = {'foo': self.foo}
        factories = set([self.foo])

        with patch.object(c, '_factories') as f:
            f.__contains__.side_effect = factories.__contains__
            f.add.side_effect = factories.add
            f.remove.side_effect = factories.remove

            c.extend('foo', self.bar)
            f.__contains__.assert_called_with(self.foo)
            f.remove.assert_called_once()
            f.add.assert_called_once()
예제 #3
0
    def test_create_extends_decorator_calls_extend(self):
        c = MedleyContainer()
        c.extend = Mock()

        @c.extends('foo')
        def foo(c):
            return 'bar'

        c.extend.assert_called_once()
예제 #4
0
    def test_extends_wraps_function_and_calls_setitem(self):
        c = MedleyContainer()
        c._keys = set(['foo'])
        c._values = {'foo': self.foo}

        with patch.object(MedleyContainer, '__setitem__',
                          wraps=c.__setitem__) as setitem:
            result = c.extend('foo', self.bar)
            self.assertEqual(type(result), types.FunctionType)
            self.assertEqual(c['foo'], result(c))
            setitem.assert_called_once()
예제 #5
0
    def test_extend_throws_error_if_second_argument_is_not_function_def(self):
        c = MedleyContainer()

        with self.assertRaises(Exception):
            c.extend('foo', 'bar')
예제 #6
0
    def test_extend_throws_error_if_service_id_is_not_function_def(self):
        c = MedleyContainer()
        c._values = {'foo': 'bar'}

        with self.assertRaises(Exception):
            c.extend('foo', self.foo)