def write_artifact_ref(artifact_full_name, label=None): """ Returns a sphinx :ref: on 'artifact_full_name' using as label: 'label' if declared, 'artifact_full_name' otherwise :param artifact_full_name: the full name of the artifact :type artifact_full_name: string :param label: the label to be used un the hyperlink :type label: string """ if label is None: label = artifact_full_name return writer.role( 'ref', '%s <%s>' % (label, artifact_full_name.replace('/', '_')[1:]))
def tc_pdf_for(self, toplevel, subdirs, links): """ String to emit in the PDF output for testcases (or sets) found in the ``links`` list underneath the list of candidate ``subdirs`` of the ``toplevel`` directory within the Qualif tree (eg. toplevel='Ada', subdirs=['stmt', 'decision', 'mcdc']). :param toplevel: Name of toplevel subdirectory within the Qualif hierarchy, such as 'Ada' or 'Common'. :type toplevel: string :param subdirs: List of immediate subdirectories of ``toplevel`` where we should be searching for testcases, possiby through intermediate sets. There may be no testcase in any of these. :type subdirs: list[str] :param links: List of (artifact, importer) tuples for actual tc_or_set artifacts to include in the document we're generating. :type links: list[(artifact,importer)] """ pdf_output = '' for subdir in subdirs: subdir_output = self.tc_pdf_for_subdir(toplevel=toplevel, subdir=subdir, links=links) if subdir_output: if len(pdf_output) == 0: pdf_output += writer.section( '%s Testcases' % toplevel) + '\n' else: pdf_output += writer.role('raw-latex', r'\newpage') + '\n\n' pdf_output += subdir_output return pdf_output
def qmlink_to_rest(self, parent, artifacts): """ Returns a matrix of traceability between lrm section artifact and thi associated test cases and requirements. chosen format was dicussed in MB23-001. :param parent: the artifact calling the qmlink :type parent: artifact :param artifacts: the list of artifacts listed in qmlink :type artifacts: list of artifacts """ REQ_NAME_PREFIX = "/TOR/Ada" pdf_items = [] html_items = [] output = "" language_version = None for a in artifacts: if is_lrm_section(a): if not language_version: language_version = a.attributes['language'].strip() ref = {} for children in a.derived_to: for child in children.all: if is_tc(child): parent = get_first_req_relative(child).full_name if parent not in ref.keys(): ref[parent] = [] ref[parent].append([child.full_name, child.full_name.replace( parent, '')]) pdf_tc_list = "" html_tc_list = "" pdf_comment = "" html_comment = "" for req in ref.keys(): pdf_other_tcs = "" html_tcs = "" if len(ref[req]) > 1: pdf_other_tcs = "%s + %d other tests" % \ (writer.role("raw-latex", r'\newline'), (len(ref[req]) - 1)) html_tcs = writer.role("raw-html", r'<br>').join( [write_artifact_ref(k[0], label=k[1]) for k in ref[req]]) requirement_str = "Req: %s" % \ write_artifact_ref(req, req.replace(REQ_NAME_PREFIX, '')).strip() first_tc_str = "* TC: %s" % \ write_artifact_ref(ref[req][0][0], label=ref[req][0][1]).strip() pdf_tc_list += "%s %s %s %s %s " % ( requirement_str, writer.role("raw-latex", r'\newline'), first_tc_str, pdf_other_tcs, writer.role("raw-latex", r'\newline')) html_tc_list += "%s %s * TC: %s %s " % ( requirement_str, writer.role("raw-html", r'<br>'), html_tcs, writer.role("raw-html", r'<br>')) applicable = a.attributes['relevance'].strip() if pdf_tc_list != "": if applicable == "no" or applicable == "partial": relevance = applicable comment = a.attributes['comment'].strip() pdf_comment = comment + ' ' + \ writer.role("raw-latex", r'\newline') + ' ' html_comment = comment + ' ' + \ writer.role("raw-html", r'<br>') + ' ' elif applicable == "yes": relevance = "yes" elif applicable == "no*": relevance = "no" comment = "Section does not require SCA-related " + \ "tests, but some are supplied " pdf_comment = comment + \ writer.role("raw-latex", r'\newline') + ' ' html_comment = comment + \ writer.role("raw-html", r'<br>') + ' ' else: relevance = "unexpected value %s" % applicable if relevance != "no": # when applicable is set to no, the list of # tc must be ommitted. # otherwise it is added to the comment column # see N102-011 Feb 8, 2014 pdf_comment += pdf_tc_list html_comment += html_tc_list else: if applicable == "no": relevance = "no" comment = a.attributes['comment'].strip() pdf_comment = comment html_comment = comment + ' ' + \ writer.role("raw-html", r'<br>') + ' ' elif applicable == "partial": relevance = "PARTIAL but not covered" comment = a.attributes['comment'].strip() pdf_comment = comment html_comment = comment + ' ' + \ writer.role("raw-html", r'<br>') + ' ' elif applicable == "yes": relevance = "YES but not covered" elif applicable == "no*": relevance = "NO but" comment = "Indicated as no* in matrix." + \ " Some test should be provided." pdf_comment = comment html_comment = comment + ' ' else: relevance = "unexpected value %s" % applicable pdf_items.append(["%s" % a.full_name.replace('/', ''), a.attributes['title'].strip(), relevance, pdf_comment]) html_items.append(["%s" % a.full_name.replace('/', ''), a.attributes['title'].strip(), relevance, html_comment]) pdf_table = writer.csv_table( pdf_items, title="TOR/LRM Traceability Matrix for Ada %s" % language_version, headers=["Section", "Title", "Applicable", "Comment"], latex_format='|p{0.08\linewidth}|p{0.20\linewidth}|' + 'p{0.10\linewidth}|p{0.50\linewidth}|') html_table = writer.csv_table( html_items, headers=["Section", "Title", "Applicable", "Comment"], widths=[8, 20, 10, 50]) output += writer.paragraph( "This particular table is established for **Ada %s**." % language_version + "\n\The requirement identifiers in this table were shortened by " "removing the *%s* common prefix.\n\n" % REQ_NAME_PREFIX) + \ writer.only(pdf_table, "latex") + \ writer.only(html_table, "html") output += "\n\n" return output, []
def qmlink_to_rest(self, parent, artifacts): items = [] for a in artifacts: items += self.get_testcases(a) items += self.get_sources(a) links = [] for a in items: if is_tc(a): links.append((a, TestCaseImporter())) elif is_source(a): links.append((a, SourceCodeImporter())) else: links.append((a, default_importer(a))) html_output = writer.toctree(['/%s/content' % artifact_hash(*l) for l in links], hidden=True) # We don't include the tests sources in the pdf version pdf_output = writer.section('Ada Testcases') + '\n' # cleanup missingTRfile with open(MISSING_TR_LOG, 'w') as fd: fd.write("") # stmt links_stmt = [l for l in links if not is_source(l[0]) and "stmt" in l[0].full_name] if links_stmt: links_dict = OrderedDict() for l in links_stmt: main_desc, desc = self.short_descs_of_main_ancestors(l[0], "stmt") if desc not in links_dict: links_dict[desc] = [] links_dict[desc].append(l) pdf_output += writer.subsection('%s' % main_desc) + '\n' for desc in links_dict.keys(): pdf_output += writer.subsubsection(desc) + '\n' pdf_output += writer.toctree(['/%s/content' % artifact_hash(*l) for l in links_dict[desc]], hidden=True) # decision links_dec = [l for l in links if not is_source(l[0]) and "decision" in l[0].full_name] if links_dec: links_dict = OrderedDict() for l in links_dec: main_desc, desc = self.short_descs_of_main_ancestors(l[0], "decision" ) if desc not in links_dict: links_dict[desc] = [] links_dict[desc].append(l) pdf_output += writer.role('raw-latex', r'\newpage') + '\n\n' pdf_output += writer.subsection('%s' % main_desc) + '\n\n' for desc in links_dict.keys(): pdf_output += writer.subsubsection(desc) + '\n\n' pdf_output += writer.toctree(['/%s/content' % artifact_hash(*l) for l in links_dict[desc]], hidden=True) links_mcdc = [l for l in links if not is_source(l[0]) and "mcdc" in l[0].full_name] if links_mcdc: links_dict = OrderedDict() for l in links_mcdc: main_desc, desc = self.short_descs_of_main_ancestors(l[0], "mcdc") if desc not in links_dict: links_dict[desc] = [] links_dict[desc].append(l) pdf_output += writer.role('raw-latex', r'\newpage') + '\n\n' pdf_output += writer.subsection('%s' % main_desc) + '\n\n' for desc in links_dict.keys(): pdf_output += writer.subsubsection(desc) + '\n\n' pdf_output += writer.toctree(['/%s/content' % artifact_hash(*l) for l in links_dict[desc]], hidden=True) links_rep = [l for l in links if not is_source(l[0]) and "Report" in l[0].full_name] if links_rep: for l in links_rep: main_desc, desc = self.short_descs_of_main_ancestors(l[0], "Report") break section = "Language-independent Testcases" pdf_output += writer.section('%s' % section) + '\n\n' pdf_output += writer.subsection('%s' % main_desc) + '\n\n' pdf_output += writer.toctree(['/%s/content' % artifact_hash(*l) for l in links_rep], hidden=True) output = writer.only(html_output, "html") output += writer.only(pdf_output, "latex") return output, links