def qmlink_to_rest(self, parent, artifacts): self.items = [] def sortkey_for(art): # Arrange for stmt requirements to come first, before decision and # mcdc. Work from locations, which contain the explicit ordering # requests in the names (numeric prefixes like 1_). return str(art.location).replace("/stmt", "/a") artifacts.sort(key=sortkey_for) for art in artifacts: self.handle(art=art, depth=0) pdf_table = writer.csv_table( self.items, headers=["Kind", "Identification", "Description"], latex_format=\ '|p{0.05\linewidth}|p{0.47\linewidth}||p{0.37\linewidth}|') html_table = writer.csv_table( self.items, headers=["Kind", "Ref"], widths=[5, 47, 37]) output = "" output += writer.only(pdf_table, "latex") output += writer.only(html_table, "html") output += "\n\n" return output, []
def qmlink_to_rest(self, parent, artifacts): # cleanup missingTRfile with open(MISSING_TR_LOG, 'w') as fd: fd.write("") # Precompute sets of (artifact, importer) pairs of relevance # to our outputs. tc_or_set_links = [] src_links = [] for a in artifacts: for suba in self.get_testcases(a) + self.get_sources(a): if is_tc(suba): tc_or_set_links.append((suba, TestCaseImporter())) elif is_tcset(suba): tc_or_set_links.append((suba, TCSetImporter())) elif is_source(suba): src_links.append((suba, SourceCodeImporter())) mixed_links = src_links + tc_or_set_links # Build the html output html_output = writer.toctree( ['/%s/content' % artifact_hash(*l) for l in mixed_links], hidden=True) # Then the PDF variant. A bit more work as we need to output # intermediate section titles ourselves and we don't want to # include the sources there. pdf_output = '' pdf_output += self.tc_pdf_for(toplevel='Ada', subdirs=['stmt', 'decision', 'mcdc'], links=tc_or_set_links) pdf_output += self.tc_pdf_for( toplevel='Common', subdirs=['Report', 'UnitsOfInterest', 'GprFacilities'], links=tc_or_set_links) output = writer.only(html_output, "html") output += writer.only(pdf_output, "latex") return output, mixed_links
def qmlink_to_rest(self, parent, artifacts): items = [] html_top_index = "" for a in artifacts: items.append([writer.strong(a.name), writer.qmref(a.full_name)]) if a.name == "Ada": def key(a): d = {'stmt': 1, 'decision': 2, 'mcdc': 3} for k in d: if k in a.name: return d[k] selected = [k for k in a.relatives if not is_source(k)] selected.sort(key=key) else: selected = a.relatives for suba in selected: items.append( ["`..` %s" % suba.name, writer.qmref(suba.full_name)]) html_top_index += writer.csv_table(items, headers=["Chapter", "Description"], widths=[30, 70]) output = writer.only(html_top_index, "html") links = [(a, qm.rest.DefaultImporter()) for a in artifacts if "Index/.+" not in a.full_name] output += writer.toctree([ '/%s/content' % artifact_hash(*l) for l in links if not is_tc_or_set(l[0]) ], hidden=True) return output, links
def to_rest(self, artifact): reference = "\n\n.. _%s:\n" % artifact.full_name.replace('/', '_')[1:] result_pdf = '**TEST CASE**: %s\n\n' % artifact.full_name result_html = '%s\n%s\n' % (artifact.full_name, '=' * len(artifact.full_name)) result_pdf += qm.rest.DefaultImporter().to_rest(artifact) + '\n\n' result_html += qm.rest.DefaultImporter().to_rest(artifact) + '\n\n' result = reference + writer.only(result_pdf, "latex") result += writer.only(result_html, "html") self.log_missing_TR(artifact) # Create a navigation links from this TC up to its requirement # and group if any: result += relative_links_for(artifact) # Managing the list of the sources driver_list = [] driver_list_qmref = [] func_list = [] func_list_qmref = [] helper_list = [] helper_list_qmref = [] consolidation_list = [] consolidation_list_qmref = [] for item in self.get_sources(artifact): if is_consolidation(item): consolidation_list += [item.name] consolidation_list_qmref += [writer.qmref (item.full_name, item.name)] continue for key in item.contents_keys: if len(item.contents(key)) > 0: for resource in item.contents(key): if is_driver(resource): driver_list += [resource.basename] driver_list_qmref += [writer.qmref (item.full_name, resource.basename)] continue if is_functional(resource): func_list += [resource.basename] func_list_qmref += [writer.qmref (item.full_name, resource.basename)] continue helper_list += [resource.basename] helper_list_qmref += [writer.qmref (item.full_name, resource.basename)] driver_list.sort() driver_list_qmref.sort() func_list.sort() func_list_qmref.sort() helper_list.sort() helper_list_qmref.sort() headers = ["Functional Sources", "Drivers Sources", "Helpers Sources"] if consolidation_list: headers += ["Consolidation Sources"] consolidation_list.sort() consolidation_list_qmref.sort() for_table_qmref = izip_longest(func_list_qmref, driver_list_qmref, helper_list_qmref, consolidation_list_qmref, fillvalue="") for_table = izip_longest(func_list, driver_list, helper_list, consolidation_list, fillvalue="") else: for_table_qmref = izip_longest(func_list_qmref, driver_list_qmref, helper_list_qmref, fillvalue="") for_table = izip_longest(func_list, driver_list, helper_list, fillvalue="") html_content = writer.csv_table([k for k in for_table_qmref], headers) latex_content = writer.csv_table([k for k in for_table], headers).strip() result += writer.only(html_content, "html") # result += writer.only(latex_content, "latex") output = '\n\n' + writer.minipage(result, r'\linewidth') + "|\n\n" return output
def qmlink_to_rest(self, parent, artifacts): html_items = [] pdf_items = [] output = "" for a in artifacts: # Don't put sources in the tables if is_source(a): continue if is_tc_or_set(a): reference = write_artifact_ref(a.full_name, get_short_description(a)) html_items.append([writer.strong(class_to_string(a)), writer.strong(a.name), reference]) pdf_items.append([class_to_string(a), a.name, reference]) for suba in self.get_recursive_relatives(a, 1): # We do include in the table children artifacts only # in html format. if is_tc(suba): subref = write_artifact_ref(suba.full_name, get_short_description(suba)) if is_tcset(suba): subref = writer.qmref(suba.full_name) html_items.append([class_to_string(suba), "`..` %s" % suba.name, subref]) html_table = writer.csv_table( html_items, headers=["", "TestCases", "Description"], widths=[3, 25, 65]) pdf_table = writer.csv_table( pdf_items, headers=["", "TestCases", "Description"], widths=[3, 25, 65]).strip() output += writer.only(html_table, "html") output += writer.only(pdf_table, "latex").strip() output += "\n\n" links = [] for a in artifacts: if is_tc(a): links.append((a, TestCaseImporter())) elif is_source(a): pass else: links.append((a, default_importer(a))) output += writer.toctree( ['/%s/content' % artifact_hash(*l) for l in links if not is_tc_or_set(l[0]) or is_tc_or_set(parent)], hidden=True) return output, links
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