def test_get_config(self):
     cfg = dict(self.cfg)
     cfg_result = dict(self.cfg)
     cfg_result['parsing_error'] = float(cfg_result['parsing_error'])
     cfg_result['report_size'] = int(cfg_result['report_size'])
     null_ini = self.test_dir + 'null.ini'
     self.assertEqual(log_analyzer.get_config(dict(), None), None)
     self.assertEqual(log_analyzer.get_config(cfg, null_ini), cfg_result)
     cfg['config_filename'] = null_ini
     cfg_result['config_filename'] = null_ini
     self.assertEqual(log_analyzer.get_config(cfg, None), cfg_result)
Ejemplo n.º 2
0
    def test_get_config_where_full_config_from_file(self):
        config_file_name = "config-file.py"
        full_config = la.get_config(Namespace())
        full_config['REPORT_SIZE'] = 1000
        full_config['REPORT_DIR'] = './report_other_dir'

        with open(config_file_name, 'w') as fd:
            fd.write("config = " + str(full_config))

        self.assertEqual(la.get_config(Namespace(config=[config_file_name])),
                         full_config)
        os.remove(config_file_name)
        os.remove(config_file_name + 'c')
Ejemplo n.º 3
0
    def test_get_config_where_config_is_broken(self):
        config_file_name = "config-broken.py"
        with open(config_file_name, 'w') as fd:
            fd.write("config = something broken")

        self.assertEqual(la.get_config(Namespace(config=[config_file_name])),
                         self.default_config)

        os.remove(config_file_name)
Ejemplo n.º 4
0
    def test_get_config_where_config_is_empty(self):
        config_file_name = "config-empty.py"
        with open(config_file_name, 'w') as fd:
            fd.write("")

        self.assertEqual(la.get_config(Namespace(config=[config_file_name])),
                         self.default_config)
        os.remove(config_file_name)
        os.remove(config_file_name + 'c')
Ejemplo n.º 5
0
 def test_file_config(self):
     config = get_config({
         'REPORT_SIZE': 1000,
         'REPORT_DIR': './tests/reports',
         'REPORT_TEMPLATE_PATH': './report.html',
         'LOG_DIR': './tests/log',
         'ERROR_LIMIT': 20,
     }, get_file_config('./tests/fixtures/config.json'))
     self.assertEqual(config['REPORT_SIZE'], 10)
Ejemplo n.º 6
0
    def test_get_config_where_half_config_from_file(self):
        config_file_name = "half_config-file.py"
        half_config = {'LOG_OUTPUT_FILE': "./log.log", 'REPORT_SIZE': 2000}

        self.default_config['LOG_OUTPUT_FILE'] = "./log.log"
        self.default_config['REPORT_SIZE'] = 2000

        with open(config_file_name, 'w') as fd:
            fd.write("config = " + str(half_config))

        self.assertEqual(la.get_config(Namespace(config=[config_file_name])),
                         self.default_config)
        os.remove(config_file_name)
        os.remove(config_file_name + 'c')
Ejemplo n.º 7
0
    def test_get_config_where_half_config_in_dir(self):
        dir_name = "./TEMP_DIR/"
        half_config = {
            'REPORT_SIZE': 4000,
            'REPORT_TEMPLATE': 'report-template.html'
        }

        self.default_config['REPORT_SIZE'] = 4000
        self.default_config['REPORT_TEMPLATE'] = 'report-template.html'

        os.mkdir(dir_name)
        with open(dir_name + "config.py", 'w') as fd:
            fd.write("config = " + str(half_config))

        self.assertEqual(la.get_config(Namespace(config=[dir_name])),
                         self.default_config)

        os.remove(dir_name + "config.py")
        os.remove(dir_name + "config.pyc")
        os.rmdir(dir_name)
Ejemplo n.º 8
0
 def testGetConfig(self):
     testconfig = log_analyzer.get_config("tests/config")
     self.assertEqual(testconfig['REPORT_SIZE'],
                      '1000')
     self.assertEqual(testconfig['LOG_DIR'],
                     './log')
Ejemplo n.º 9
0
 def test_get_config_where_config_not_found(self):
     with self.assertRaises(SystemExit):
         la.get_config(Namespace(config=['./config-file1.py']))
Ejemplo n.º 10
0
 def test_get_config_default(self):
     self.assertEqual(la.get_config(Namespace()), self.default_config)
Ejemplo n.º 11
0
 def setUp(self):
     self.default_config = la.get_config(Namespace())
Ejemplo n.º 12
0
 def test_bad_json_config(self):
     empty_conf = log_analyzer.get_config(self.bad_conf_path)
     self.assertIsNone(empty_conf)
Ejemplo n.º 13
0
 def test_empty_config(self):
     empty_conf = log_analyzer.get_config(self.empty_conf_path,
                                          self.analyzer_def_config)
     self.assertEqual(self.analyzer_def_config, empty_conf)
 def test_config(self):
     self.assertEqual(log_analyzer.get_config('con.conf'), {
         'REPORT_DIR': u'.',
         'REPORT_SIZE': 10,
         'LOG_DIR': u'.'
     })
 def test_get_config(self):
     config_file = 'config.py'
     conf = get_config(default_config=config, config_file=config_file)
     self.assertEqual(conf['REPORT_SIZE'], 1000)