Ejemplo n.º 1
0
 def invert(self):
     """
     Get requirement versus file
     ex:
     Input:
         {'SSCS_ESSNESS_ET2788_S-6D1': [u'SSCS_ESSNESS_0001', etc.
     Output:
         {'SSCS_ESSNESS_9020': ['SSCS_ESSNESS_ET2788_S-6D1'], 'SSCS_ESSNESS_9141': ['SSCS_ESSNESS_ET2788_S-6D1'],
     :return:
     """
     self.list_llr_vs_file = Tool._invert_dol(self.tbl_file_llr)
Ejemplo n.º 2
0
    def extract(self,
                dirname="",
                type=("SWRD","PLDRD"),
                component="SW_ENM",
                log_handler=None,
                enable_check_bproc=False):
        """
        This function call listDir to parse each files in folder and collect all requirements with their attributes.
        self.list_upper_req contains all upper requirements reference
        :param dirname: directory where to search files
        :param type: type of specification document
        :param component: came form IHM
        :return:
        """
        # TODO: Create xlsx file instead of csv file
        if log_handler is not None:
            self.log_handler = log_handler
        # Recursive function to parse directory to find documents
        # Parse document to extract requirements or test cases
        #self.listDir(dirname,
        #             type,
        #             component)
        self.invert()
        # Summary
        type_tag = "test cases"
        derived = "forward"
        verify = "verified"
        nb_proc_linked = 0
        for tc,dico_attributes in self.tbl_list_llr.iteritems():
            if "proc" in dico_attributes:
                list_proc = dico_attributes["proc"]
                nb_proc_linked += len(list_proc)
                self.dico_tc_vs_proc[tc]=list_proc
        #for tc,tps in self.dico_tc_vs_proc.iteritems():
        #    nb_proc_linked += len(self.dico_tc_vs_proc[tc])
        nb_proc_in_folder = len(self.list_proc)
        # revert dico
        dico_proc_vs_tc = Tool._invert_dol(self.dico_tc_vs_proc)
        self.log("Found {:d} procedures in document body.".format(nb_proc_linked),gui_display=True)
        self.log("Found {:d} procedures in folder.".format(nb_proc_in_folder),gui_display=True)
        if enable_check_bproc:
            for procedure in dico_proc_vs_tc:
                if procedure not in self.list_proc:
                    self.log("Procedure {:s} found in SHLVCP but not in procedures folder.".format(procedure),gui_display=True)
            for procedure in self.list_proc:
                if procedure not in dico_proc_vs_tc:
                    self.log("Procedure {:s} found in procedures folder but not in SHLVCP.".format(procedure),gui_display=True)
            print "Procedures in folder:"
            for x in self.list_proc:
                print "Folder:",x
        print "Procedures in SHLVCP:"
        for x in dico_proc_vs_tc:
            print "SHLVCP:",x

        #union = set(dico_proc_vs_tc) & set(self.list_proc)
        #exclusion = set(dico_proc_vs_tc) ^ set(self.list_proc)
        #print "UNION",union
        #for x in exclusion:
        #    print "EXCLUSION:",x

        #nb_upper_req = 0
        self.log("Found {:d} {:s} in document body.".format(self.nb_reqs,type_tag),gui_display=True)
        self.log("Found {:d} {:s} modified in document body.".format(self.nb_reqs_modified,type_tag),gui_display=True)
        self.log("Found {:d} {:s} {:s} in document body.".format(self.nb_derived_req,derived,type_tag),gui_display=True)
        self.log("Found {:d} deleted {:s} in document body.".format(self.nb_deleted_req,type_tag),gui_display=True)
        #self.log("Found {:d} {:s} requirements in document body.".format(nb_upper_req,verify),gui_display=True)

        for list,error in self.dico_errors.iteritems():
            rule_tag = list[1]
            self.log("ERROR: {:s}: {:s}".format(rule_tag,error[0]),gui_display=True)
        self.log("{:d} warnings found in document.".format(len(self.dico_warnings)),gui_display=True)
        for list,error in self.dico_warnings.iteritems():
            rule_tag = list[1]
            self.log("WARNING: {:s}: {:s}".format(rule_tag,error[0]),gui_display=True)
        filename = "test_cases_%d.xlsx" % floor(time.time())
        filename_tc_vs_tp = "test_cases_vs_procedures_%d.xlsx" % floor(time.time())
        file_check_filename = "test_cases_file_check_%d.csv" % floor(time.time())
        attr_check_filename = "test_cases_attr_check_%d.csv" % floor(time.time())
        with open(join("result",file_check_filename), 'w') as of:
            of.write("{:s};{:s};{:s};{:s}\n".format("Dir","Files","nb reqs","pages"))
            for file in self.tbl_file_llr:
                # dir not sorted here !
                dir = self.tbl_file_dir[file]
                of.write("{:s};{:s};{:};{:}\n".format(dir,                    # Folder
                                                   file,                        # File
                                                   self.tbl_file_nb_llr[file],  # nb requirements
                                                   self.tbl_file_nb_pages[file]                           # nb pages
                                                  )
                        )
                #for reqs in llr.tbl_file_llr[file]:
                #    of.write("   " + reqs + "\n")

        with open(join("result",attr_check_filename), 'w') as of:
            ws,wb = self.createWorkBook("Test Cases",["Test cases","Nb links","Nb used I/O"])
            ws2,wb2 = self.createWorkBook("Test Cases vs Procedures",["Test cases","Procedures"])
            of.write("{:s};{:s};{:s};{:s};{:s};{:s};{:s};{:s};{:s}\n".format("File","Req tag","Objective","Verifies","Rationale","Forward","Issue","Status","Used IO"))
            # get all test cases from self.tbl_list_llr
            row = 10
            row_proc = 10
            for req,value in self.tbl_list_llr.iteritems():
                #list_verify,list_constraints = self.getLLR_Trace(value,keyword="verify")
                # File,Req,Refer_to,Constraint,Derived,Rationale,Additional
                req_txt = str(req)
                if req_txt in self.list_llr_vs_file:
                    file = self.list_llr_vs_file[req_txt][0]
                else:
                    file = "None"

                rationale = self.getAtribute(value,"rationale")
                forward = self.getAtribute(value,"forward")
                issue = self.getAtribute(value,"issue")
                status = self.getAtribute(value,"status")
                objective = self.getAtribute(value,"objective")
                if "used_io" in value:
                    used_io = ",".join(value["used_io"])
                else:
                    used_io = ""
                if not re.search(r'DELETED',status):
                    nb_link = len(value["verify"])
                    if "used_io" in value:
                        nb_used_io = len(value["used_io"])
                    else:
                        nb_used_io = 0
                    line = (req_txt,nb_link,nb_used_io)
                    for col_idx in range(1,len(line)+1):
                        Style.setCell(ws,line,row,col_idx)
                    row += 1
                    for verify in value["verify"]:
                        of.write("{:s};{:s};{:s};{:s};{:s};{:s};{:s};{:s};{:s}\n".format(file,
                                                                                req,
                                                                                objective,
                                                                                verify,
                                                                                rationale,
                                                                                forward,
                                                                                issue,
                                                                                status,
                                                                                used_io
                                                                                ))
                    if "proc" in value:
                        for proc in value["proc"]:
                            line = (req_txt,proc)
                            for col_idx in range(1,len(line)+1):
                                Style.setCell(ws2,line,row_proc,col_idx)
                            row_proc += 1

            wb.save(join("result",filename))
            wb2.save(join("result",filename_tc_vs_tp))

        return attr_check_filename,file_check_filename