コード例 #1
0
ファイル: test_plugins.py プロジェクト: nkaul/ocp-checkbox
 def test_load(self, mock_iter):
     # Create a collection
     col = PlugInCollection(self._NAMESPACE)
     # Create a mocked entry point
     mock_ep1 = mock.Mock()
     mock_ep1.name = "zzz"
     mock_ep1.load.return_value = "two"
     # Create another mocked entry point
     mock_ep2 = mock.Mock()
     mock_ep2.name = "aaa"
     mock_ep2.load.return_value = "one"
     # Make the collection load both mocked entry points
     mock_iter.return_value = [mock_ep1, mock_ep2]
     # Load plugins
     col.load()
     # Ensure that pkg_resources were interrogated
     mock_iter.assert_calledwith(self._NAMESPACE)
     # Ensure that both entry points were loaded
     mock_ep1.load.assert_called_with()
     mock_ep2.load.assert_called_with()
コード例 #2
0
ファイル: test_plugins.py プロジェクト: nkaul/ocp-checkbox
 def test_load_failing(self, mock_iter, mock_logger):
     # Create a collection
     col = PlugInCollection(self._NAMESPACE)
     # Create a mocked entry point
     mock_ep1 = mock.Mock()
     mock_ep1.name = "zzz"
     mock_ep1.load.return_value = "two"
     # Create another mockeed antry point
     mock_ep2 = mock.Mock()
     mock_ep2.name = "aaa"
     mock_ep2.load.side_effect = ImportError("boom")
     # Make the collection load both mocked entry points
     mock_iter.return_value = [mock_ep1, mock_ep2]
     # Load plugins
     col.load()
     # Ensure that pkg_resources were interrogated
     mock_iter.assert_calledwith(self._NAMESPACE)
     # Ensure that both entry points were loaded
     mock_ep1.load.assert_called_with()
     mock_ep2.load.assert_called_with()
     # Ensure that an exception was logged
     mock_logger.exception.assert_called_with(
         "Unable to import %s", mock_ep2)