def test_default_general_config(self): default_general_config = config.Config._replace_data_types({ 'interval': '1', 'logging_level': 'ERROR', 'log_file': '~/.config/i3situation/log.txt', 'colors': 'True' }) self._create_default_config() conf = config.Config(self.folder_location) self.assertEqual(conf.general, default_general_config)
def __init__(self): self.config = config.Config(self.discover_folder_path()) self.output_dict = OrderedDict() self._config_file_path = self.config.config_file_path self._plugin_path = self.config.plugin_path self._config_mod_time = os.path.getmtime(self._config_file_path) self._plugin_mod_time = os.path.getmtime(self._plugin_path) log_formatting = ('[%(asctime)s] - %(levelname)s - %(filename)s - ' '%(funcName)s - %(message)s', '%d/%m/%Y %I:%M:%S %p') self.logger = setup_file_logger(self.config.general['log_file'], log_formatting, self.config.general['logging_level']) # Redirect stderr so that it doesn't confuse i3bar by outputting to it. self.log_writer = self.LoggingWriter( self.config.general['log_file'], self.config.general['logging_level']) sys.stderr = self.log_writer logging.debug('Config loaded from {0}'.format(self._config_file_path)) logging.debug('Plugin path is located at {0}'.format( self._plugin_path)) logging.debug('Last config modification time is: {0}'.format( self._config_mod_time)) logging.debug('Last plugin directory modification time is: {0}'.format( self._plugin_mod_time)) self.output_to_bar(json.dumps({ 'version': 1, 'click_events': True }), False) self.output_to_bar('[', False) logging.debug('Sent initial JSON data to i3bar.') logging.debug('Beginning plugin loading process') self.loader = plugin_manager.PluginLoader(self._plugin_path, self.config.plugin) self.thread_manager = plugin_manager.ThreadManager(self.output_dict) # Event handling is done in another thread, so that the main thread # isn't stalled. self.event_thread = threading.Thread(target=self.handle_events) self.event_thread.start()
def test_incomplete_header(self): self._create_config('[gener]') with self.assertRaises(config.IncompleteConfigurationFile): c = config.Config(self.folder_location)
def test_missing_header(self): self._create_config('WRONGDATA') with self.assertRaises(configparser.MissingSectionHeaderError): c = config.Config(self.folder_location)
def test_wrong_path(self): with self.assertRaises(OSError): c = config.Config( os.path.join(os.path.expanduser('~'), 'i3situation-test'))
def test_wrong_permissions(self): with self.assertRaises(PermissionError): c = config.Config('/root/')
def test_empty_config(self): self._create_config('') with self.assertRaises(config.IncompleteConfigurationFile): c = config.Config(self.folder_location)
def test_no_config(self): with self.assertRaises(TypeError): c = config.Config()