Exemple #1
0
def runtest(name):
    print("Running %s" % name)

    tests_run, tests_failed = 0, 0

    # Remove ".test" and replace with ".config" to find the input configuration
    config_file = os.path.splitext(name)[0] + '.config'

    if not os.path.exists(config_file):
        config_file = "empty_file"
    config_system.read_config(name, config_file, False)

    with open(name) as f:
        for line_number, line in enumerate(f):
            m = re.match(r"# (ASSERT|SET): (\S+)=(.+)", line)
            if not m:
                continue
            action, key, value = m.groups()
            if action == "ASSERT":
                tests_run += 1
                config = config_system.get_config(key)
                actual_value = config.get("value")
                if config['datatype'] == 'bool':
                    actual_value = 'y' if actual_value else 'n'
                if actual_value != value:
                    print(
                        "ERROR: %s:%d: assertion failed: %s=%s (should be %s)"
                        % (name, line_number, key, actual_value, value))
                    tests_failed += 1
            elif action == "SET":
                if value == 'y':
                    value = True
                elif value == 'n':
                    value = False
                config_system.set_config(key, value)
            else:
                raise Exception("Unexpected action %s" % action)

    return tests_run, tests_failed
def config_to_json(database_fname, config_fname, ignore_missing):
    config_system.read_config(database_fname, config_fname, ignore_missing)
    config_list = config_system.get_config_list()

    configs = dict()

    for key in config_list:
        c = config_system.get_config(key)
        key = key.lower()
        datatype = c['datatype']
        value = c['value']

        if 'title' in c and config_system.can_enable(c):
            if datatype in ['bool', 'string']:
                configs[key] = value
            elif datatype == 'int':
                configs[key] = int(value)
            else:
                msg = "Invalid config type: %s (with value '%s')\n"
                logger.critical(msg % (datatype, str(value)))
                sys.exit(1)

    return configs