Пример #1
0
def setup_module():
    '''Initual setup needed before tests can run.'''
    if not os.path.exists(OUTDIR):
        os.mkdir(OUTDIR)

    ds = report.create_local_datasource(OUTPUT_DS)
    report.set_datasource(ds)
    report.set_run_id(int(time.time()))  # a time stamp
Пример #2
0
def validate_job_definition(args, must_be_defined, create_layers=True):
    '''
    A refactored job def checker which can be usefull outside of qc_wrap.
    For now simply print both user-info and error messages and return a boolean.
    This is supposed to be executed from the command line.
    '''

    # consider using a logger (info / warning / error).
    for key in must_be_defined:
        if args[key] is None:
            print("ERROR: " + key + " must be defined.")
            return False

    if not args["TESTNAME"] in qc.tests:
        print(
            "%s,defined in parameter file, not matched to any test (yet....)\n"
            % args["TESTNAME"])
        show_tests()
        return False
    # see if test uses ref-data and reference data is defined..
    use_ref_data = qc.tests[args["TESTNAME"]][0]
    use_reporting = qc.tests[args["TESTNAME"]][1]
    ref_data_defined = False
    for key in ["REF_DATA_CONNECTION", "REF_TILE_DB"]:
        ref_data_defined |= (args[key] is not None)
    if use_ref_data:
        if not ref_data_defined:
            msg = '''Sorry, {testname} uses reference data.
                     Must be defined in parameter file in either REF_DATA_CONNECTION
                     or REF_TILE_DB!'''.format(testname=args["TESTNAME"])
            print(textwrap.dedent(msg))
            return False

    # import valid arguments from test
    test_parser = qc.get_argument_parser(args["TESTNAME"])
    if len(args["TARGS"]) > 0:  # validate targs
        print("Validating arguments for " + args["TESTNAME"])
        if test_parser is not None:
            _targs = ["dummy"]
            if use_ref_data:
                _targs.append("dummy")
            _targs.extend(args["TARGS"])
            try:
                test_parser.parse_args(_targs)
            except Exception as e:
                print("Error parsing arguments for test script " +
                      args["TESTNAME"] + ":")
                print(str(e))
                return False
        else:
            print("No argument parser in " + args["TESTNAME"] +
                  " - unable to check arguments to test.")

    if use_reporting:
        # this will not be supported for the listening client... so an optional keyword
        if "USE_LOCAL" in args and args["USE_LOCAL"]:
            # will do nothing if it already exists
            # should be done 'process safe' so that its available for writing for the
            # child processes...
            if create_layers:
                report.create_local_datasource()
            if args["SCHEMA"] is not None:  # mutually exclusive - actually checked by parser...
                msg = '''WARNING:
                         USE_LOCAL is True, local reporting database does not support schema names.
                         Will ignore SCHEMA.'''
                print(textwrap.dedent(msg))
        # check the schema arg
        else:
            if args["SCHEMA"] is None:
                print(
                    "ERROR: Schema MUST be specified when using a global datasource for reporting!"
                )
                return False

            print("Schema is set to: " + args["SCHEMA"])
            # Test if we can open the global datasource with given schema
            print("Testing connection to reporting db...")
            layers_defined = report.schema_exists(args["SCHEMA"])
            print("Layers defined: " + str(layers_defined))
            if (not layers_defined) and create_layers:
                print("Creating schema/layers...")
                try:
                    report.create_schema(args["SCHEMA"])
                except Exception as e:
                    print("Failed: " + str(e))
                    return False
    return True
Пример #3
0
                print("Error parsing arguments for test script " +
                      args["TESTNAME"] + ":")
                print(str(e))
                return False
        else:
            print("No argument parser in " + args["TESTNAME"] +
                  " - unable to check arguments to test.")

    if use_reporting:
        # this will not be supported for the listening client... so an optional keyword
        if "USE_LOCAL" in args and args["USE_LOCAL"]:
            # will do nothing if it already exists
            # should be done 'process safe' so that its available for writing for the
            # child processes...
            if create_layers:
                report.create_local_datasource()
            if args["SCHEMA"] is not None:  # mutually exclusive - actually checked by parser...
                msg = '''WARNING:
                         USE_LOCAL is True, local reporting database does not support schema names.
                         Will ignore SCHEMA.'''
                print(textwrap.dedent(msg))
        # check the schema arg
        else:
            if args["SCHEMA"] is None:
                print(
                    "ERROR: Schema MUST be specified when using a global datasource for reporting!"
                )
                return False

            print("Schema is set to: " + args["SCHEMA"])
            # Test if we can open the global datasource with given schema
Пример #4
0
    print("Running unit tests...")
    for test, test_data in UNIT_TESTS:
        print(pl)
        n_serious += run_test(test,
                              test_data["fct"],
                              test_data["files"],
                              stdout,
                              stderr,
                              test_data["args"],
                              call_as_main=False)

    # Run some tests on the demo data...
    print(sl)
    print("Running tests on demo data...")
    try:
        ds = report.create_local_datasource(OUTPUT_DS)
    except Exception, e:
        print("Unable to create a test-suite datasource:\n" + str(e))
        n_serious += 1
    else:
        report.set_datasource(ds)
        report.set_run_id(int(time.time()))  # a time stamp
        for test, test_data in TESTS:
            if pargs.test is None or pargs.test == test:
                print(sl)
                if test in loaded_tests:
                    n_serious += run_test(test, loaded_tests[test],
                                          test_data["files"], stdout, stderr,
                                          test_data["args"])
                else:
                    print(test + " was not loaded...")