def test_repeat_command(dir):
    c = expand_meta_ini(dir + "repeat.mini")
    assert (len(c) == 2)
    for conf in c:
        assert (len(conf["cells"].split()) == int(conf["dim"]))
Beispiel #2
0
            'Set if the script is called from CMake and should return data to it'
        )
        parser.add_argument(
            '-s',
            '--section',
            default="__static",
            help=
            'The section to treat as the static section (defaults to __static)'
        )
        return vars(parser.parse_args())

    # analyse the given arguments
    args = get_args()

    # expand the meta ini files into a list of configurations
    configurations = expand_meta_ini(args["ini"])

    # initialize a data structure to pass the list of generated ini files to CMake
    metaini = {}
    metaini["names"] = []  # TODO this should  have underscores!
    metaini["labels"] = {}

    # extract the static information from the meta ini file
    static_info = extract_static_info(args["ini"], section=args['section'])

    # write the configurations to the file specified in the name key.
    for c in configurations:
        # Discard label groups from the data
        if "__LABELS" in c:
            c["__LABELS"] = list(c["__LABELS"].values())
            metaini["labels"][c["__name"]] = c["__LABELS"]
def test_complex_command_deps(dir):
    c = expand_meta_ini(dir + "complexcommand.mini")
    assert (len(c) == 2)
    assert ("2" in [conf["b"] for conf in c])
    assert ("5" in [conf["b"] for conf in c])
def test_import(dir):
    configs = expand_meta_ini(dir + "import.ini")
    assert (configs[0]["a"] == "TEST")
    assert (len(configs) == 36)
Beispiel #5
0
def test_metaini(dir):
    c = expand_meta_ini(dir + "command.ini")
    assert ("4" in [conf["ev"] for conf in c])
    assert (6 < float(c[0]["pi"]) < 7)
    assert (len(c) == 4)
Beispiel #6
0
def test_total_order_on_configs(dir):
    configs = expand_meta_ini(dir + "metaini1.mini", addNameKey=True)
    for i in range(len(configs) - 1):
        assert(configs[i] < configs[i + 1])
Beispiel #7
0
def test_metaini2(dir):
    configs = expand_meta_ini(dir + "metaini2.mini")
    assert(check_uniqueness(configs, "__name"))
def test_curly_bracket(dir):
    configs = expand_meta_ini(dir + "escape.mini")
    assert (len(configs) == 2)
Beispiel #9
0
def call(executable, metaini=None):
    # check for the meta ini file
    if not metaini:
        sys.stderr.write("No meta ini file found for this convergence test!")
        return 1

    # expand the meta ini file
    from dune.testtools.metaini import expand_meta_ini
    configurations = expand_meta_ini(metaini)

    # Find out in which sections the test data is
    testsections = configurations[0].get(
        "wrapper.convergencetest.testsections", "").split()
    if testsections:
        testsections = [
            "wrapper.convergencetest.{}".format(s) for s in testsections
        ]
    else:
        testsections = ["wrapper.convergencetest"]

    # execute all runs with temporary ini files and process the temporary output
    output = []
    for c in configurations:
        c.setdefault("__output_extension", "out")

        # write a temporary ini file. Prefix them with the name key to be unique
        tmp_file = c["__name"] + "_tmp.ini"
        write_dict_to_ini(c, tmp_file)

        # execute the run
        command = [executable]
        iniinfo = parse_ini_file(metaini)
        if "__inifile_optionkey" in iniinfo:
            command.append(iniinfo["__inifile_optionkey"])
        command.append(tmp_file)

        if subprocess.call(command):
            return 1

        # collect the information from the output file
        output.append([
            parse_ini_file(
                os.path.basename(c["__name"]) + "." + c["__output_extension"])
        ][0])

        # remove temporary files
        os.remove(
            os.path.basename(c["__name"]) + "." + c["__output_extension"])
        os.remove(tmp_file)

    # store return value (because we do not want to return as soon as one section fails)
    returnvalue = 0

    # calculate the rate according to the outputted data
    for section in testsections:
        for idx, c in list(enumerate(configurations))[:-1]:
            # check if all necessary keys are given
            if "expectedrate" not in c[section]:
                sys.stderr.write(
                    "The convergencetest wrapper excepts a key expectedrate \
                                  in section {} of the ini file!".format(
                        section))
                return 1

            # specify all default keys if not specified already
            c[section].setdefault("absolutedifference", "0.1")
            c.setdefault("__output_extension", "out")

            norm1 = float(output[idx][section]["norm"])
            norm2 = float(output[idx + 1][section]["norm"])
            hmax1 = float(output[idx][section]["scale"])
            hmax2 = float(output[idx + 1][section]["scale"])
            rate = math.log(norm2 / norm1) / math.log(hmax2 / hmax1)
            # test passes
            if math.fabs(rate - float(c[section]["expectedrate"])) <= float(
                    c[section]["absolutedifference"]):
                sys.stdout.write(
                    "Test {} passed because the absolute difference "
                    "between the calculated convergence rate ({}) "
                    "and the expected convergence rate ({}) was within "
                    "tolerance ({}). \n".format(
                        section, rate, c[section]["expectedrate"],
                        c[section]["absolutedifference"]))
            # test fails because rates are off
            elif math.fabs(rate - float(c[section]["expectedrate"])) > float(
                    c[section]["absolutedifference"]):
                sys.stderr.write(
                    "Test {} failed because the absolute difference "
                    "between the calculated convergence rate ({}) "
                    "and the expected convergence rate ({}) was greater "
                    "than tolerance ({}). \n".format(
                        section, rate, c[section]["expectedrate"],
                        c[section]["absolutedifference"]))
                returnvalue = 1
            # test fails because rates are nan or inf
            elif math.isnan(rate) or math.isinf(rate):
                sys.stderr.write(
                    "Test {} failed because calculated rate is ({})."
                    "Expected was ({}) with tolerance ({}). \n".format(
                        section, rate, c[section]["expectedrate"],
                        c[section]["absolutedifference"]))
                returnvalue = 1
            # if we are here, something unexpcted happened
            else:
                sys.stderr.write(
                    "Test {} failed for unknown reason with calculated rate ({}), "
                    "expected rate ({}) and tolerance ({}). \n".format(
                        section, rate, c[section]["expectedrate"],
                        c[section]["absolutedifference"]))
                returnvalue = 1

    return returnvalue
def test_metaini2(dir):
    configs = expand_meta_ini(dir + "metaini2.mini")
    assert (len(configs) == 24)