def setUp(self): self.inject = injector({ unittest.TestCase: self, 'foo': 'FOO', self: 'SELF', (dict, 'foo'): 'SELF-FOO' })
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()
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
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')
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()
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()
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) ))
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()
def setUp(self): self.inject = injector({ unittest.TestCase: self })
def setUp(self): self.map = { InjectorPatchTests: self, } self.inject = injector(self.map)
def setUp(self): self.map = { unittest.TestCase: self, } self.inject = injector(self.map)
def setUp(self): self.inject = injector({unittest.TestCase: self})