def testConfigFromParsedArgs(self, mock_parsed_args, mock_read_config): mock_options = mock.Mock() mock_parsed_args.return_value = (mock_options, mock.sentinel.args) conf = Config() # object is singleton, for this case, it needs to be reloaded. conf.__init__() self.assertEqual(mock_options.config_file, conf._configFile)
def testConfigFileFromDefault(self, mock_os, mock_parsed_args, mock_read_config): mock_os.path.exists = mock.create_autospec(mock_os.path.exists, return_value=True) mock_options = mock.Mock() mock_options.config_file = None mock_parsed_args.return_value = (mock_options, mock.sentinel.args) conf = Config() # object is singleton, for this case, it needs to be reloaded. conf.__init__() self.assertEqual(config.DEFAULT_CONFIG_FILE, conf._configFile) mock_os.path.exists.assert_called_once_with(config.DEFAULT_CONFIG_FILE)
def testConfigIsSingleton(self): # create a temp conf file tempdir = tempfile.mkdtemp() conf_file = os.path.join(tempdir, 'agent.yaml') with open(conf_file, 'wb') as fd: fd.write(b""" Logging: collector_log_file: /var/log/monasca/agent/collector.log forwarder_log_file: /var/log/monasca/agent/forwarder.log log_level: DEBUG statsd_log_file: /var/log/monasca/agent/statsd.log Main: check_freq: 60 dimensions: {} hostname: example.com """) conf_1 = Config(configFile=conf_file) conf_2 = Config(configFile=conf_file) conf_3 = Config() self.assertTrue(conf_1 is conf_2) self.assertTrue(conf_1 is conf_3)
def xtestWhiteSpaceConfig(self): """Leading whitespace confuse ConfigParser """ agent_config = Config.get_config( cfg_path=os.path.join(os.path.dirname(os.path.realpath(__file__)), "badconfig.conf")) self.assertEqual(agent_config["api_key"], "1234")