Esempio n. 1
0
class DispatchingPluginLoaderTest (unittest.TestCase):
    def setUp (self):
        self.project = mock()
        self.fist_delegatee = mock()
        self.second_delegatee = mock()
        
        self.loader = DispatchingPluginLoader(mock, self.fist_delegatee, self.second_delegatee)
        
    def test_should_raise_exception_when_all_delgatees_raise_exception (self):
        when(self.fist_delegatee).load_plugin(self.project, "spam").thenRaise(MissingPluginException("spam"))
        when(self.second_delegatee).load_plugin(self.project, "spam").thenRaise(MissingPluginException("spam"))

        self.assertRaises(MissingPluginException, self.loader.load_plugin, self.project, "spam")

        verify(self.fist_delegatee).load_plugin(self.project, "spam")
        verify(self.second_delegatee).load_plugin(self.project, "spam")

    def test_should_return_module_returned_by_second_loader_when_first_delgatee_raises_exception (self):
        result = "result"
        when(self.fist_delegatee).load_plugin(self.project, "spam").thenRaise(MissingPluginException("spam"))
        when(self.second_delegatee).load_plugin(self.project, "spam").thenReturn(result)

        self.assertEquals(result, self.loader.load_plugin(self.project, "spam"))

        verify(self.fist_delegatee).load_plugin(self.project, "spam")
        verify(self.second_delegatee).load_plugin(self.project, "spam")

    def test_ensure_second_delegatee_is_not_trie_when_first_delegatee_loads_plugin (self):
        result = "result"
        when(self.fist_delegatee).load_plugin(self.project, "spam").thenReturn(result)

        self.assertEquals(result, self.loader.load_plugin(self.project, "spam"))

        verify(self.fist_delegatee).load_plugin(self.project, "spam")
        verify(self.second_delegatee, never).load_plugin(self.project, "spam")
Esempio n. 2
0
 def setUp (self):
     self.project = mock()
     self.fist_delegatee = mock()
     self.second_delegatee = mock()
     
     self.loader = DispatchingPluginLoader(mock, self.fist_delegatee, self.second_delegatee)