def before_request():
    g.config = parse_config('config.ini', 'config_local.ini')
    g.db = DB(g.config['db']['conn_url'])

    # Template settings.
    app.jinja_env.lstrip_blocks = True
    app.jinja_env.trim_blocks = True

    # Filters.
    app.jinja_env.filters['age'] = format_age
    app.jinja_env.filters['date'] = format_date
    app.jinja_env.filters['id'] = format_id
    app.jinja_env.filters['runtime'] = format_runtime
    app.jinja_env.filters['nl2br'] = nl2br
    def test_single_file_is_parsed_correctly(self):
        config_content = '''
        ; Global configuration file

        [sec1]
            var1 = value1

        [sec2]
            var2 = value2
        '''
        with TemporaryFile(config_content) as cf:
            parsed_config = parse_config([cf.path])
            self.assertEqual(parsed_config.sections(), ['sec1', 'sec2'])
            self.assertEqual(parsed_config['sec1']['var1'], 'value1')
            self.assertEqual(parsed_config['sec2']['var2'], 'value2')
    def test_two_files_are_parsed_correctly(self):
        global_config_content = '''
        ; Global configuration file

        [sec1]
            var1 = value1

        [sec2]
            var2 = value2
        '''
        local_config_content = '''
        ; Local configuration file

        [sec2]
            var2 = other_value2
            var3 = value3
        '''
        with TemporaryFile(global_config_content) as global_cf:
            with TemporaryFile(local_config_content) as local_cf:
                parsed_config = parse_config([global_cf.path, local_cf.path])
                self.assertEqual(parsed_config.sections(), ['sec1', 'sec2'])
                self.assertEqual(parsed_config['sec1']['var1'], 'value1')
                self.assertEqual(parsed_config['sec2']['var2'], 'other_value2')
                self.assertEqual(parsed_config['sec2']['var3'], 'value3')
    """Parses command-line arguments and returns them."""
    parser = argparse.ArgumentParser(
        description='Daemon that automatically runs regression tests for new commits.'
    )
    args = parser.parse_args()
    return args


# Do not put the following call to the try block because we want the PID file
# to be removed only if the process that created it ends.
exit_if_already_running()


try:
    # Config.
    config = parse_config('config.ini', 'config_local.ini')

    # Logging.
    setup_logging(config, os.path.basename(__file__))
    logging.info('script started (`' + ' '.join(sys.argv) + '`)')

    # Quality of Service.
    qos_enabled = config.getboolean('qos', 'enabled')
    qos_max_tries = int(config['qos']['max_tries'])
    qos_wait_time = int(config['qos']['wait_time'])

    # Database.
    db = DB(config['db']['conn_url'])
    if qos_enabled:
        db = WithQoS(db, qos_max_tries, qos_wait_time)
 def test_file_that_cannot_be_read_is_ignored(self):
     parsed_config = parse_config(['/hopefully-non-existing-file.txt'])
     self.assertEqual(parsed_config.sections(), [])
 def test_empty_config_is_returned_when_no_files_are_given(self):
     parsed_config = parse_config([])
     self.assertEqual(parsed_config.sections(), [])