old_contents: from mock import call, MagicMock as Mock, patch
  from nose.tools import raises
  
  import spreads
  import spreads.plugin as plugin
  from spreads.util import DeviceException
  
  
  class TestPlugin(object):
      def setUp(self):
          reload(plugin)
          spreads.config.clear()
          spreads.config.read(user=False)
          spreads.config['plugins'] = []
  
      def test_pluginmanager(self):
          plugin.SpreadsNamedExtensionManager = Mock()
          pm = plugin.get_pluginmanager()
          pm_new = plugin.get_pluginmanager()
          assert pm is pm_new
  
      def test_get_devices(self):
          device = Mock()
          device.match = Mock(return_value=True)
          device.__name__ = "Mock"
          usb_mock = Mock()
          extension_mock = Mock()
          plugin.usb.core.find = Mock(return_value=[usb_mock])
          plugin.DriverManager = Mock(return_value=extension_mock)
          extension_mock.driver = device
          plugin.get_devices()
          assert call(spreads.config, usb_mock) in device.call_args_list
          assert device.match.call_args_list == [call(usb_mock)]
  
      @raises(DeviceException)
      def test_no_devices(self):
          device_a = Mock()
          device_a.plugin.match = Mock(return_value=True)
          device_b = Mock()
          device_b.plugin.match = Mock(return_value=False)
          plugin.usb.core.find = Mock(return_value=[])
          dm = Mock()
          dm.map = lambda x, y: [x(z, y) for z in [device_a, device_b]]
          plugin.get_devicemanager = Mock(return_value=dm)
          plugin.get_devices()
  
new_contents: from mock import call, MagicMock as Mock, patch
  from nose.tools import raises
  
  import spreads.confit as confit
  import spreads.plugin as plugin
  from spreads.util import DeviceException
  
  
  class TestPlugin(object):
      def setUp(self):
          pass
  
      def test_get_driver(self):
          cfg = confit.Configuration('test_plugin')
          cfg["driver"] = u"dummy"
          assert "dummy" in plugin.get_driver(cfg).names()
  
      @patch('spreads.plugin.get_driver')
      def test_get_devices(self, get_driver):
          cfg = Mock()
          driver = Mock()
          usb_mock = Mock()
          plugin.usb.core.find = Mock(return_value=[usb_mock])
          get_driver.return_value = driver
          plugin.get_driver = get_driver
          plugin.get_devices(cfg)
          assert call(cfg, usb_mock) in driver.driver.call_args_list
          assert driver.driver.match.call_args_list == [call(usb_mock)]
  
      @raises(DeviceException)
      @patch('spreads.plugin.get_driver')
      def test_no_devices(self, get_driver):
          cfg = Mock()
          driver = Mock()
          driver.driver.match = Mock(return_value=False)
          usb_mock = Mock()
          plugin.usb.core.find = Mock(return_value=[usb_mock])
          get_driver.return_value = driver
          plugin.get_driver = get_driver
          plugin.get_devices(cfg)
  
subject: Fix plugin_test for workflow object