Package elisa :: Package core :: Package tests :: Module elisa_test_case

Source Code for Module elisa.core.tests.elisa_test_case

  1  # Moovida - Home multimedia server 
  2  # Copyright (C) 2006-2009 Fluendo Embedded S.L. (www.fluendo.com). 
  3  # All rights reserved. 
  4  # 
  5  # This file is available under one of two license agreements. 
  6  # 
  7  # This file is licensed under the GPL version 3. 
  8  # See "LICENSE.GPL" in the root of this distribution including a special 
  9  # exception to use Moovida with Fluendo's plugins. 
 10  # 
 11  # The GPL part of Moovida is also available under a commercial licensing 
 12  # agreement from Fluendo. 
 13  # See "LICENSE.Moovida" in the root directory of this distribution package 
 14  # for details on that license. 
 15   
 16  from elisa.extern.translation import Translator 
 17   
 18  from elisa.core import log, common 
 19   
 20  from elisa.core import config, plugin_registry 
 21  from elisa.core import interface_controller 
 22  from elisa.core import metadata_manager 
 23  from elisa.core import input_manager 
 24  from elisa.core import bus 
 25  from elisa.extern.log import log as extern_log 
 26   
 27  from twisted.trial import unittest 
 28  import os, sys, inspect 
 29   
 30   
 31   
 32  DEFAULT_CONFIG = """\ 
 33  [general] 
 34  version = '%(version)s' 
 35  install_date = '%(install_date)s' 
 36  metadata_providers = [] 
 37  service_providers = [] 
 38   
 39  [media_db:media_scanner] 
 40  enabled = '1' 
 41  fivemin_location_updates = [] 
 42  hourly_location_updates = [] 
 43  daily_location_updates = [] 
 44  weekly_location_updates = [] 
 45  unmonitored_locations = [] 
 46   
 47  [media_db:db] 
 48  db_backend = 'sqlite' 
 49  database = 'elisa.db' 
 50   
 51  [xmlmenu:locations_builder] 
 52  locations = [] 
 53  auto_locations = 1 
 54   
 55  [lirc:lirc_input] 
 56  # filename of the LIRC config map to use 
 57  lirc_rc = 'streamzap.lirc' 
 58  delay = '4' 
 59  repeat = '1' 
 60   
 61  [coherence:coherence_service] 
 62  logmode = 'none' 
 63  controlpoint = 'yes' 
 64   
 65  [[plugins]] 
 66   
 67  """ 
 68   
 69   
70 -class BoilerPlateApp:
71
72 - def __init__(self, config_file, default_config=None, load_all_plugins=False):
73 #self.config = config.Config(config_file) 74 if not default_config: 75 default_config = DEFAULT_CONFIG 76 self.errors = [] 77 78 default_config = default_config % {'version': 'test', 79 'install_date': 'none'} 80 self.config = config.Config('empty.conf', default_config) 81 common.set_application(self) 82 83 self.translator = Translator() 84 manager = plugin_registry.PluginRegistry(self.config) 85 if load_all_plugins: 86 manager.load_plugins() 87 88 self.plugin_registry = manager 89 self.bus = bus.Bus() 90 self.metadata_manager = metadata_manager.MetadataManager() 91 self.input_manager = input_manager.InputManager() 92 self.interface_controller = interface_controller.InterfaceController() 93 self.interface_controller.initialize()
94
95 - def log_traceback(self):
96 info = sys.exc_info() 97 self.errors.append(info)
98
99 - def log_failure(self, failure):
100 self.errors.append(failure)
101
102 -class ElisaTestCase(unittest.TestCase, extern_log.Loggable):
103 default_config = DEFAULT_CONFIG 104 load_all_plugins = False 105 tests_dir = os.path.dirname(__file__) 106
107 - def __init__(self, methodName='runTest'):
108 self._booted = False 109 110 test_file_path = inspect.getsourcefile(self.__class__) 111 if test_file_path is not None: 112 fname = os.path.basename(test_file_path) 113 114 fname, _ = os.path.splitext(fname) 115 self.logCategory = fname 116 self.directory = os.path.dirname(test_file_path) 117 118 #extern_log.init('ELISA_TESTS') 119 unittest.TestCase.__init__(self, methodName=methodName)
120 121 debug = extern_log.Loggable.debug 122 info = extern_log.Loggable.info 123
124 - def _boot(self):
125 if self._booted == False: 126 if 'ELISA_DEBUG' not in os.environ: 127 log.setDebug('*:0') 128 129 app = BoilerPlateApp('empty.conf', self.default_config, 130 self.load_all_plugins) 131 self.debug("Set common.application to %r", app) 132 133 self._booted = True
134
135 - def setUp(self):
136 self._boot()
137
138 - def check_called(self, callback):
139 self.failUnless(hasattr(callback, 'called')) 140 self.assertEquals(callback.called, True)
141