Beispiel #1
0
 def setUp(self):
     self.inject = injector({
         unittest.TestCase: self,
         'foo': 'FOO',
         self: 'SELF',
         (dict, 'foo'): 'SELF-FOO'
     })
Beispiel #2
0
 def setUp(self):
     self.inject = injector({
         unittest.TestCase: self,
         'foo': 'FOO',
         self: 'SELF',
         (dict, 'foo'): 'SELF-FOO'
     })
Beispiel #3
0
 def setUp(self):
     self.map = ContextualDependencyMap()
     self.map[ContextualDependencyMap] = self.map
     self.inject = injector(self.map)
     @self.map.singleton(Ham)
     def fn(deps):
         return Ham()
Beispiel #4
0
    def setUp(self):
        self.map = ContextualDependencyMap()
        self.map[ContextualDependencyMap] = self.map
        self.inject = injector(self.map)

        @self.map.singleton(Ham)
        def fn(deps):
            return Ham()
Beispiel #5
0
class Foo(object):
    DEPS = {}
    inject = injector(DEPS)

    @inject
    def __init__(self, test=unittest.TestCase):
        self.test = test

    @inject
    def foo(self, test=unittest.TestCase):
        return test
Beispiel #6
0
def test_py3_kwonlydefaults():

    inject = injector({KeyA: 'A', KeyB: 'B', KeyC: 'C'})

    @inject
    def foo(a, b=KeyB, *, c=KeyC):
        return (b, c)

    foo(10) | should.eql(('B', 'C'))

    @inject
    def bar(a, *, b=KeyB):
        return b

    bar(10) | should.eql('B')
Beispiel #7
0
    def setUp(self):
        self.ham = Ham()
        self.map = {Ham: self.ham}
        self.inject = injector(self.map)

        class Foo(object):
            __metaclass__ = MetaInject(self.inject)

            def echo(self, test=Ham):
                return test

            def nouse(self):
                pass

        self.foo = Foo()
Beispiel #8
0
    def setUp(self):
        self.ham = Ham()
        self.map = {
            Ham: self.ham
        }
        self.inject = injector(self.map)

        class Foo(object):
            __metaclass__ = MetaInject(self.inject)

            def echo(self, test=Ham):
                return test

            def nouse(self):
                pass

        self.foo = Foo()
Beispiel #9
0
def test_py3_annotations():

    class Foo: pass
    class Bar: pass
    class Baz: pass
    class Qux: pass

    inject = injector({Foo: Foo(), Bar: Bar(), Baz: Baz(), Qux: Qux()})

    @inject
    def foo(a: Foo = Key, b: Any = Bar, c: Baz = Baz, d=Qux):
        return (a, b, c, d)

    foo() | should.eql((
        should.be_a(Foo),
        should.be_a(Bar),
        should.be_a(Baz),
        should.be_a(Qux)
    ))
Beispiel #10
0
    def setUp(self):
        # Python 3 metaclass syntax is not compatible with Python 2.x
        import sys
        if sys.version_info[0] >= 3:
            from nose.plugins.skip import SkipTest
            raise SkipTest

        self.ham = Ham()
        self.map = {
            Ham: self.ham
        }
        self.inject = injector(self.map)

        class Foo(object):
            __metaclass__ = MetaInject(self.inject)
            def echo(self, test=Ham):
                return test

        self.foo = Foo()
Beispiel #11
0
 def setUp(self):
     self.inject = injector({
         unittest.TestCase: self
     })
Beispiel #12
0
 def setUp(self):
     self.map = {
         InjectorPatchTests: self,
     }
     self.inject = injector(self.map)
Beispiel #13
0
 def setUp(self):
     self.map = {
         unittest.TestCase: self,
     }
     self.inject = injector(self.map)
Beispiel #14
0
 def setUp(self):
     self.inject = injector({unittest.TestCase: self})
Beispiel #15
0
 def setUp(self):
     self.map = {
         InjectorPatchTests: self,
     }
     self.inject = injector(self.map)
Beispiel #16
0
 def setUp(self):
     self.map = {
         unittest.TestCase: self,
     }
     self.inject = injector(self.map)