home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / computerjanitor / plugin_tests.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  6.5 KB  |  141 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import tempfile
  6. import unittest
  7. import computerjanitor
  8.  
  9. class PluginTests(unittest.TestCase):
  10.     
  11.     def testGetCruftRaisesException(self):
  12.         p = computerjanitor.Plugin()
  13.         self.assertRaises(computerjanitor.UnimplementedMethod, p.get_cruft)
  14.  
  15.     
  16.     def testPostCleanupReturnsNone(self):
  17.         p = computerjanitor.Plugin()
  18.         self.assertEqual(p.post_cleanup(), None)
  19.  
  20.     
  21.     def testDoesNotHaveAppAttributeByDefault(self):
  22.         p = computerjanitor.Plugin()
  23.         self.assertFalse(hasattr(p, 'app'))
  24.  
  25.     
  26.     def testSetApplicationSetsApp(self):
  27.         p = computerjanitor.Plugin()
  28.         p.set_application('foo')
  29.         self.assertEqual(p.app, 'foo')
  30.  
  31.     
  32.     def testSetsRequiredConditionToNoneByDefault(self):
  33.         p = computerjanitor.Plugin()
  34.         self.assertEqual(p.condition, [])
  35.  
  36.  
  37.  
  38. class PluginManagerTests(unittest.TestCase):
  39.     
  40.     def testFindsNoPluginsInEmptyDirectory(self):
  41.         tempdir = tempfile.mkdtemp()
  42.         pm = computerjanitor.PluginManager(None, [
  43.             tempdir])
  44.         plugins = pm.get_plugins()
  45.         os.rmdir(tempdir)
  46.         self.assertEqual(plugins, [])
  47.  
  48.     
  49.     def testFindsOnePluginFileInTestPluginDirectory(self):
  50.         pm = computerjanitor.PluginManager(None, [
  51.             'testplugins'])
  52.         self.assertEqual(pm.get_plugin_files(), [
  53.             'testplugins/hello_plugin.py'])
  54.  
  55.     
  56.     def testFindsOnePluginInTestPluginDirectory(self):
  57.         pm = computerjanitor.PluginManager(None, [
  58.             'testplugins'])
  59.         self.assertEqual(len(pm.get_plugins()), 1)
  60.  
  61.     
  62.     def testFindPluginsSetsApplicationInPluginsFound(self):
  63.         pm = computerjanitor.PluginManager('foo', [
  64.             'testplugins'])
  65.         self.assertEqual(pm.get_plugins()[0].app, 'foo')
  66.  
  67.     
  68.     def callback(self, filename, index, count):
  69.         self.callback_called = True
  70.  
  71.     
  72.     def testCallsCallbackWhenFindingPlugins(self):
  73.         pm = computerjanitor.PluginManager(None, [
  74.             'testplugins'])
  75.         self.callback_called = False
  76.         pm.get_plugins(callback = self.callback)
  77.         self.assert_(self.callback_called)
  78.  
  79.  
  80.  
  81. class ConditionTests(unittest.TestCase):
  82.     
  83.     def setUp(self):
  84.         self.pm = computerjanitor.PluginManager(None, [
  85.             'testplugins'])
  86.         
  87.         class White(computerjanitor.Plugin):
  88.             pass
  89.  
  90.         
  91.         class Red(computerjanitor.Plugin):
  92.             
  93.             def __init__(self):
  94.                 self.condition = [
  95.                     'red']
  96.  
  97.  
  98.         
  99.         class RedBlack(computerjanitor.Plugin):
  100.             
  101.             def __init__(self):
  102.                 self.condition = [
  103.                     'red',
  104.                     'black']
  105.  
  106.  
  107.         self.white = White()
  108.         self.red = Red()
  109.         self.redblack = RedBlack()
  110.         self.pm._plugins = [
  111.             self.white,
  112.             self.red,
  113.             self.redblack]
  114.  
  115.     
  116.     def testReturnsOnlyConditionlessPluginByDefault(self):
  117.         self.assertEqual(self.pm.get_plugins(), [
  118.             self.white])
  119.  
  120.     
  121.     def testReturnsOnlyRedPluginWhenConditionIsRed(self):
  122.         self.assertEqual(self.pm.get_plugins(condition = 'red'), [
  123.             self.red,
  124.             self.redblack])
  125.  
  126.     
  127.     def testReturnsOnlyRedPluginWhenConditionIsRedAndBlack(self):
  128.         self.assertEqual(self.pm.get_plugins(condition = [
  129.             'red',
  130.             'black']), [
  131.             self.redblack])
  132.  
  133.     
  134.     def testReturnsEallPluginsWhenRequested(self):
  135.         self.assertEqual(set(self.pm.get_plugins(condition = '*')), set([
  136.             self.white,
  137.             self.red,
  138.             self.redblack]))
  139.  
  140.  
  141.