示例#1
0
def get_testobj_from_cnf_test(cnf_test, testvars, bomobj, offline=False):
    if len(cnf_test.keys()) != 1:
        raise ValueError("Test configurations are " "expected to have exactly " "one key at the top level")
    logger.debug("Creating test object : " + cnf_test.keys()[0])
    testobj = get_test_object(cnf_test.keys()[0], offline=offline)
    additionalvars = cnf_test[cnf_test.keys()[0]]
    if "prep" in additionalvars.keys():
        add_prep_steps_from_cnf_prep(testobj, additionalvars.pop("prep"))
    vardict = copy.copy(testvars)
    if additionalvars is not None:
        vardict.update(additionalvars)
    logger.debug("Configuring test object : " + cnf_test.keys()[0])
    if "desc" in vardict.keys():
        testobj.desc = vardict.pop("desc")
    if "title" in vardict.keys():
        testobj.title = vardict.pop("title")
    testobj.use_bom(bomobj)
    testobj.configure(**vardict)
    logger.info("Adding Test Obj : " + repr(testobj))
    return testobj
示例#2
0
def get_testobj_from_cnf_test(cnf_test, testvars, bomobj, offline=False):
    if len(cnf_test.keys()) != 1:
        raise ValueError("Test configurations are "
                         "expected to have exactly "
                         "one key at the top level")
    logger.debug("Creating test object : " + cnf_test.keys()[0])
    testobj = get_test_object(cnf_test.keys()[0], offline=offline)
    additionalvars = cnf_test[cnf_test.keys()[0]]
    
    if 'prep' in additionalvars.keys():
        add_prep_steps_from_cnf_prep(testobj, additionalvars.pop('prep'), testvars)
    vardict = copy.copy(testvars)
    if additionalvars is not None:
        vardict.update(additionalvars)
    logger.debug("Configuring test object : " + cnf_test.keys()[0])
    if 'desc' in vardict.keys():
        testobj.desc = vardict.pop('desc')
    if 'title' in vardict.keys():
        testobj.title = vardict.pop('title')
    testobj.use_bom(bomobj)
    testobj.configure(**vardict)
    logger.info("Adding Test Obj : " + repr(testobj))
    return testobj
示例#3
0
def get_test_suite_objects(serialno=None, order_by='FILE_ORDER', session=None):
    # This reconstructs the test objects from the database. Using SQLAlchemy
    # as the ORM that it is, and letting it handle the object creation would
    # be infinitely better. It isn't done here since the models are separate
    # from the actual test objects, which in turn have other dependencies.
    # Integrating the models with the classes should be considered in the
    # future when there is time.
    # suite_names = controller.get_test_suite_names(serialno=serialno,
    #                                               session=session)
    suite_descs = controller.get_test_suite_descs(serialno=serialno,
                                                  session=session)
    devicetype = serialnos.get_serialno_efield(sno=serialno, session=session)
    projectfolder = projects.cards[devicetype]
    bomobj = import_pcb(cardfolder=projectfolder)
    # Perhaps this bomobject should not be recreated on the fly.
    bomobj.configure_motifs(devicetype)

    if order_by == 'FILE_ORDER':

        logger.info("Creating dummy test suites for file ordering")
        dummy_suites = get_electronics_test_suites(None,
                                                   devicetype,
                                                   projectfolder,
                                                   offline=True)
        ldummy_suites = []
        for suite in dummy_suites:
            suite.dummy = True
            ldummy_suites.append(suite)

        file_order = [(x.desc, [(y.desc, y.passfailonly) for y in x.tests])
                      for x in ldummy_suites]
        suite_order = [x[0] for x in file_order]
        test_order = {x[0]: x[1] for x in file_order}

    elif order_by == 'DONT_CARE':
        suite_order = []
        test_order = {}

    else:
        raise ValueError('Unknown order_by heuristic : ' + order_by)

    suites = []
    suite_descs = sort_by_order(suite_descs, suite_order)

    # for suite_name in suite_names:
    for desc, name in suite_descs:
        suite_db_obj = controller.get_latest_test_suite(serialno=serialno,
                                                        suite_class=name,
                                                        descr=desc,
                                                        session=session)
        if suite_db_obj.suite_class == \
                "<class 'tendril.testing.testbase.TestSuiteBase'>":
            suite_obj = TestSuiteBase()
        else:
            raise ValueError("Unrecognized suite_class : " +
                             suite_db_obj.suite_class)

        suite_obj.desc = suite_db_obj.desc
        suite_obj.title = suite_db_obj.title
        suite_obj.ts = suite_db_obj.created_at
        suite_obj.serialno = serialno
        if order_by == 'FILE_ORDER':
            test_display_params = {
                x[0]: x[1]
                for x in test_order[suite_obj.desc]
            }

        for test_db_obj in suite_db_obj.tests:
            class_name = rex_class.match(test_db_obj.test_class).group('cl')

            test_obj = get_test_object(class_name, offline=True)
            test_obj.desc = test_db_obj.desc
            test_obj.title = test_db_obj.title
            test_obj.ts = test_db_obj.created_at
            test_obj.use_bom(bomobj)
            test_obj.load_result_from_obj(test_db_obj.result)
            if order_by == 'FILE_ORDER':
                test_obj.passfailonly = test_display_params[test_obj.desc]
            suite_obj.add_test(test_obj)
            # Crosscheck test passed?

        # Crosscheck suite passed?

        suites.append(suite_obj)

    return suites
示例#4
0
def get_suiteobj_from_cnf_suite(cnf_suite, gcf, devicetype,
                                offline=False):
    """

    :param cnf_suite:
    :param gcf:
    :type gcf: tendril.gedaif.conffile.ConfigsFile
    :param devicetype:
    :param offline:
    :param dummy:
    :return:
    """
    if len(cnf_suite.keys()) != 1:
        raise ValueError("Suite configurations are expected "
                         "to have exactly one key at the top level")

    cnf_suite_name = cnf_suite.keys()[0]
    testvars = gcf.testvars(devicetype)
    bomobj = import_pcb(gcf.projectfolder)
    bomobj.configure_motifs(devicetype)
    cnf_grouplist = gcf.configuration_grouplist(devicetype)

    desc = None
    title = None
    if 'desc' in cnf_suite[cnf_suite.keys()[0]].keys():
        logger.debug("Found Test Suite Description")
        desc = cnf_suite[cnf_suite.keys()[0]]['desc']
    if 'title' in cnf_suite[cnf_suite.keys()[0]].keys():
        logger.debug("Found Test Suite Title")
        title = cnf_suite[cnf_suite.keys()[0]]['title']

    logger.debug("Creating test suite : " + cnf_suite_name)
    if cnf_suite_name == "TestSuiteBase":
        suite = []
        suite_detail = cnf_suite[cnf_suite_name]

        if 'group-tests' in suite_detail.keys():
            suite.append(TestSuiteBase())

            if 'prep' in suite_detail.keys():
                add_prep_steps_from_cnf_prep(suite[0], suite_detail['prep'])

            if desc is not None:
                suite[0].desc = desc
            if title is not None:
                suite[0].title = title

            cnf_groups = suite_detail['group-tests']
            for cnf_group in cnf_groups:
                if len(cnf_suite.keys()) != 1:
                    raise ValueError("Group test configurations are "
                                     "expected to have exactly one "
                                     "key at the top level")

                logger.debug("Creating group tests : " + cnf_group.keys()[0])
                if cnf_group.keys()[0] in cnf_grouplist:
                    cnf_test_list = cnf_group[cnf_group.keys()[0]]
                    for cnf_test in cnf_test_list:
                        suite[0].add_test(
                            get_testobj_from_cnf_test(
                                cnf_test, testvars, bomobj, offline=offline
                            )
                        )

        if 'channel-tests' in suite_detail.keys():
            channel_defs = get_channel_defs_from_cnf_channels(
                suite_detail['channels'], cnf_grouplist
            )

            lsuites = []
            for channel_def in channel_defs:
                lsuite = TestSuiteBase()
                if 'prep' in suite_detail.keys():
                    add_prep_steps_from_cnf_prep(
                        lsuite,
                        replace_in_test_cnf_dict(
                            suite_detail['prep'], '<CH>', channel_def.idx
                        )
                    )
                if desc is not None:
                    lsuite.desc = replace_in_string(
                        desc, '<CH>', channel_def.idx
                    )
                if title is not None:
                    lsuite.title = replace_in_string(
                        title, '<CH>', channel_def.idx
                    )
                for test in suite_detail['channel-tests']:
                    if 'motif-map' in suite_detail.keys():
                        motifmap = suite_detail['motif-map']
                    else:
                        motifmap = None
                    cnf_test_dict = replace_in_test_cnf_dict(
                        test, '<CH>', channel_def.idx, motifmap
                    )
                    lsuite.add_test(
                        get_testobj_from_cnf_test(
                            cnf_test_dict, testvars, bomobj, offline=offline
                        )
                    )
                lsuites.append(lsuite)

            suite.extend(lsuites)
    else:
        suite = [get_test_object(cnf_suite)]

    return suite
示例#5
0
def get_test_suite_objects(serialno=None, order_by='FILE_ORDER',
                           session=None):
    # This reconstructs the test objects from the database. Using SQLAlchemy
    # as the ORM that it is, and letting it handle the object creation would
    # be infinitely better. It isn't done here since the models are separate
    # from the actual test objects, which in turn have other dependencies.
    # Integrating the models with the classes should be considered in the
    # future when there is time.
    # suite_names = controller.get_test_suite_names(serialno=serialno,
    #                                               session=session)
    suite_descs = controller.get_test_suite_descs(serialno=serialno,
                                                  session=session)
    devicetype = serialnos.get_serialno_efield(sno=serialno, session=session)
    projectfolder = projects.cards[devicetype]
    bomobj = import_pcb(cardfolder=projectfolder)
    # Perhaps this bomobject should not be recreated on the fly.
    bomobj.configure_motifs(devicetype)

    if order_by == 'FILE_ORDER':

        logger.info("Creating dummy test suites for file ordering")
        dummy_suites = get_electronics_test_suites(None, devicetype,
                                                   projectfolder,
                                                   offline=True)
        ldummy_suites = []
        for suite in dummy_suites:
            suite.dummy = True
            ldummy_suites.append(suite)

        file_order = [(x.desc, [(y.desc, y.passfailonly) for y in x.tests])
                      for x in ldummy_suites]
        suite_order = [x[0] for x in file_order]
        test_order = {x[0]: x[1] for x in file_order}

    elif order_by == 'DONT_CARE':
        suite_order = []
        test_order = {}

    else:
        raise ValueError('Unknown order_by heuristic : ' + order_by)

    suites = []
    suite_descs = sort_by_order(suite_descs, suite_order)

    # for suite_name in suite_names:
    for desc, name in suite_descs:
        suite_db_obj = controller.get_latest_test_suite(
            serialno=serialno, suite_class=name, descr=desc, session=session
        )
        if suite_db_obj.suite_class == \
                "<class 'tendril.testing.testbase.TestSuiteBase'>":
            suite_obj = TestSuiteBase()
        else:
            raise ValueError("Unrecognized suite_class : " +
                             suite_db_obj.suite_class)

        suite_obj.desc = suite_db_obj.desc
        suite_obj.title = suite_db_obj.title
        suite_obj.ts = suite_db_obj.created_at
        suite_obj.serialno = serialno
        if order_by == 'FILE_ORDER':
            test_display_params = {x[0]: x[1]
                                   for x in test_order[suite_obj.desc]}

        for test_db_obj in suite_db_obj.tests:
            class_name = rex_class.match(test_db_obj.test_class).group('cl')

            test_obj = get_test_object(class_name, offline=True)
            test_obj.desc = test_db_obj.desc
            test_obj.title = test_db_obj.title
            test_obj.ts = test_db_obj.created_at
            test_obj.use_bom(bomobj)
            test_obj.load_result_from_obj(test_db_obj.result)
            if order_by == 'FILE_ORDER':
                test_obj.passfailonly = test_display_params[test_obj.desc]
            suite_obj.add_test(test_obj)
            # Crosscheck test passed?

        # Crosscheck suite passed?

        suites.append(suite_obj)

    return suites
示例#6
0
def get_suiteobj_from_cnf_suite(cnf_suite, gcf, devicetype, offline=False):
    """

    :param cnf_suite:
    :param gcf:
    :type gcf: tendril.gedaif.conffile.ConfigsFile
    :param devicetype:
    :param offline:
    :return:
    """
    if len(cnf_suite.keys()) != 1:
        raise ValueError("Suite configurations are expected " "to have exactly one key at the top level")

    cnf_suite_name = cnf_suite.keys()[0]
    testvars = gcf.testvars(devicetype)
    bomobj = import_pcb(gcf.projectfolder)
    bomobj.configure_motifs(devicetype)
    cnf_grouplist = gcf.configuration_grouplist(devicetype)

    desc = None
    title = None
    if "desc" in cnf_suite[cnf_suite.keys()[0]].keys():
        logger.debug("Found Test Suite Description")
        desc = cnf_suite[cnf_suite.keys()[0]]["desc"]
    if "title" in cnf_suite[cnf_suite.keys()[0]].keys():
        logger.debug("Found Test Suite Title")
        title = cnf_suite[cnf_suite.keys()[0]]["title"]

    logger.debug("Creating test suite : " + cnf_suite_name)
    if cnf_suite_name == "TestSuiteBase":
        suite = []
        suite_detail = cnf_suite[cnf_suite_name]

        if "group-tests" in suite_detail.keys():
            suite.append(TestSuiteBase())

            if "prep" in suite_detail.keys():
                add_prep_steps_from_cnf_prep(suite[0], suite_detail["prep"])

            if desc is not None:
                suite[0].desc = desc
            if title is not None:
                suite[0].title = title

            cnf_groups = suite_detail["group-tests"]
            for cnf_group in cnf_groups:
                if len(cnf_suite.keys()) != 1:
                    raise ValueError(
                        "Group test configurations are " "expected to have exactly one " "key at the top level"
                    )

                logger.debug("Creating group tests : " + cnf_group.keys()[0])
                if cnf_group.keys()[0] in cnf_grouplist:
                    cnf_test_list = cnf_group[cnf_group.keys()[0]]
                    for cnf_test in cnf_test_list:
                        suite[0].add_test(get_testobj_from_cnf_test(cnf_test, testvars, bomobj, offline=offline))

        if "channel-tests" in suite_detail.keys():
            channel_defs = get_channel_defs_from_cnf_channels(suite_detail["channels"], cnf_grouplist)

            lsuites = []
            for channel_def in channel_defs:
                lsuite = TestSuiteBase()
                if "prep" in suite_detail.keys():
                    add_prep_steps_from_cnf_prep(
                        lsuite, replace_in_test_cnf_dict(suite_detail["prep"], "<CH>", channel_def.idx)
                    )
                if desc is not None:
                    lsuite.desc = replace_in_string(desc, "<CH>", channel_def.idx)
                if title is not None:
                    lsuite.title = replace_in_string(title, "<CH>", channel_def.idx)
                for test in suite_detail["channel-tests"]:
                    if "motif-map" in suite_detail.keys():
                        motifmap = suite_detail["motif-map"]
                    else:
                        motifmap = None
                    cnf_test_dict = replace_in_test_cnf_dict(test, "<CH>", channel_def.idx, motifmap)
                    lsuite.add_test(get_testobj_from_cnf_test(cnf_test_dict, testvars, bomobj, offline=offline))
                lsuites.append(lsuite)

            suite.extend(lsuites)
    else:
        suite = [get_test_object(cnf_suite)]

    return suite