def test_no_candidate(self): """ Test that a :exc:`syringe.NoCandidateError` is raised when no candidate exists. """ with self.assertRaises(syringe.NoCandidateError) as e: syringe.get('mock') self.assertEqual('No provider found for [mock]', e.exception.args[0])
def test_provide_subclass_no_duplicate(self): """ Test that a subclass is not marked as a duplicate. """ @syringe.provides('A') class A(object): pass @syringe.provides('B') class B(A): pass a = A() b = B() self.assertIs(syringe.get('A'), a) self.assertIs(syringe.get('B'), b)
def test_get(self): """ Test simply getting a provided instance. """ @syringe.provides('mock') class CLS(object): pass instance = CLS() self.assertIs(instance, syringe.get('mock'))
def test_custom_mock(self): """ Test that a custom object can be used as a mock. """ class MyMock(object): pass m = MyMock() copy = syringe.mock('mymock', m) self.assertIs(m, copy) self.assertIs(m, syringe.get('mymock'))