Permalink
Browse files

Merge pull request #12607 from aeslaughter/sqa-fix-12528

Update SQA for MOOSEDocs API change
  • Loading branch information...
rwcarlsen committed Dec 13, 2018
2 parents 3c1bf59 + be946f2 commit 2290c8ddd3ba5f27dc72e7d18679b1aa2f6e82e7
@@ -706,6 +706,11 @@ footer.page-footer {
font-weight:100;
}

.collection-header a
{
color:white;
}

.moose-requirements.collection .collection-item{
display:flex;
}
@@ -855,6 +860,11 @@ li p {
height:100px;
}

.card-content .moose-alert-content img
{
width:unset;
}

.moose-alert-title-brand{
text-transform: uppercase;
padding-right: 1ex;
@@ -79,7 +79,6 @@ Extensions:
MooseDocs.extensions.acronym:
acronyms: !include framework/doc/acronyms.yml
MooseDocs.extensions.sqa:
active: False
requirement-groups:
dgkernels: DGKernel Objects
interfacekernels: InterfaceKernel Objects
@@ -57,7 +57,7 @@ def read(self, page):
LOG.debug('READ %s', page.source)
return common.read(page.source).lstrip('\n')

def tokenize(self, root, content, page, group=None, line=1):
def tokenize(self, root, content, page, group=None, line=1, report=True):
"""
Perform the parsing of the supplied content into an AST with the provided root node.
@@ -75,11 +75,15 @@ def tokenize(self, root, content, page, group=None, line=1):
self.__lexer.tokenize(root, content, page, self.__lexer.grammar(group), line)

# Report errors
for token in anytree.PreOrderIter(root):
if token.name == 'ErrorToken':
msg = common.report_error(token['message'], page, token.info, token['traceback'],
u'TOKENIZE ERROR')
with MooseDocs.base.translators.Translator.LOCK:
if report:
for token in anytree.PreOrderIter(root):
if token.name == 'ErrorToken':
msg = common.report_error(token['message'],
page.source,
token.info.line,
token.info[0],
token['traceback'],
u'TOKENIZE ERROR')
LOG.error(msg)

def add(self, group, component, location='_end'):
@@ -80,7 +80,11 @@ def render(self, parent, token, page):

except Exception as e: #pylint: disable=broad-except
el = None
msg = common.report_error(e.message, page, token.info, traceback.format_exc(),
msg = common.report_error(e.message,
page.source,
token.info.line,
token.info[0],
traceback.format_exc(),
u'RENDER ERROR')
with MooseDocs.base.translators.Translator.LOCK:
LOG.error(msg)
@@ -177,6 +177,7 @@ def main(options):
if options.fast:
options.disable.append('appsyntax')
options.disable.append('navigation')
options.disable.append('sqa')

# Disable extensions based on command line arguments
if options.disable:
@@ -18,13 +18,23 @@

class Requirement(object):
"""struct for storing Requirement information."""
def __init__(self, name=None, path=None, filename=None, text=None, design=None, issues=None,
def __init__(self,
name=None,
path=None,
filename=None,
text=None,
text_line=None,
design=None,
design_line=None,
issues=None,
satisfied=True):
self.name = name
self.path = path
self.filename = filename
self.text = text
self.text_line = text_line
self.design = design
self.design_line = design_line
self.issues = issues
self.label = None # added by get_requirements function
self.satisfied = satisfied
@@ -58,11 +68,13 @@ def _add_requirements(out, location, filename):
"""Opens tests specification and extracts requirement items."""
root = mooseutils.hit_load(filename)
design = root.children[0].get('design', None)
design_line = root.children[0].line('design', None)
issues = root.children[0].get('issues', None)
for child in root.children[0]:
if 'requirement' in child:

local_design = child.get('design', design)
local_design_line = child.line('design', design_line)
if local_design is None:
msg = "The 'design' parameter is missing from '%s' in %s. It must be defined at " \
"the top level and/or within the individual test specification. It " \
@@ -90,7 +102,9 @@ def _add_requirements(out, location, filename):
path=os.path.relpath(os.path.dirname(filename), location),
filename=filename,
text=unicode(text),
text_line=child.line('requirement', None),
design=local_design.split(),
design_line=local_design_line,
issues=local_issues.split(),
satisfied=satisfied)

@@ -10,7 +10,7 @@

import mooseutils
from box import box
def report_error(message, page, info, traceback=None, prefix=u'ERROR'):
def report_error(message, filename, line, src, traceback=None, prefix=u'ERROR'):
"""
Helper for reporting error to logging module.
@@ -21,13 +21,7 @@ def report_error(message, page, info, traceback=None, prefix=u'ERROR'):
traceback: The traceback (should be a string from traceback.format_exc())
"""
title = '{}: {}'.format(prefix, message)
if info is not None:
src = mooseutils.colorText(box(info[0], line=info.line, width=100), 'LIGHT_CYAN')
line = info.line
else:
src = ''
line = u'?'
filename = mooseutils.colorText('{}:{}\n'.format(page.source, line), 'RESET')

src = mooseutils.colorText(box(src, line=line, width=100), 'LIGHT_CYAN')
filename = mooseutils.colorText('{}:{}\n'.format(filename, line), 'RESET')
trace = u'\n' + mooseutils.colorText(traceback, 'GREY') if traceback else ''
return u'\n{}\n{}{}{}\n'.format(title, filename, src, trace)
@@ -96,7 +96,7 @@ def createMaterialize(self, parent, token, page):
content = html.Tag(card_content, 'div', class_='moose-alert-content')

if token['icon'] and (token['brand'] == 'construction'):
src = os.path.relpath('media/under-construction.gif',
src = os.path.relpath('media/framework/under-construction.gif',
os.path.dirname(page.local))
html.Tag(content, 'img', class_='moose-alert-construction-img', src=src)

@@ -13,7 +13,7 @@
import codecs
import logging
import collections

import traceback
import anytree

import MooseDocs
@@ -74,10 +74,10 @@ def extend(self, reader, renderer):
self.addCommand(reader, SQARequirementsMatrixCommand())
self.addCommand(reader, SQAVerificationCommand())

renderer.add(SQATemplateItem, RenderSQATemplateItem())
renderer.add(SQARequirementMatrix, RenderSQARequirementMatrix())
renderer.add(SQARequirementMatrixItem, RenderSQARequirementMatrixItem())
renderer.add(SQARequirementMatrixHeading, RenderSQARequirementMatrixHeading())
renderer.add('SQATemplateItem', RenderSQATemplateItem())
renderer.add('SQARequirementMatrix', RenderSQARequirementMatrix())
renderer.add('SQARequirementMatrixItem', RenderSQARequirementMatrixItem())
renderer.add('SQARequirementMatrixHeading', RenderSQARequirementMatrixHeading())

SQADocumentItem = tokens.newToken('SQADocumentItem', key=u'')
SQATemplateItem = tokens.newToken('SQATemplateItem', key=u'')
@@ -127,7 +127,18 @@ def _addRequirement(self, parent, info, page, req, requirements):
label=unicode(req.label),
satisfied=req.satisfied,
id_=req.path)
self.reader.tokenize(item, req.text, page)

self.reader.tokenize(item, req.text, page, MooseDocs.INLINE, info.line, report=False)
for token in anytree.PreOrderIter(item):
if token.name == 'ErrorToken':
msg = common.report_error("Failed to tokenize SQA requirement.",
req.filename,
req.text_line,
req.text,
token['traceback'],
u'SQA TOKENIZE ERROR')
LOG.critical(msg)


if self.settings['link']:
if self.settings['link-spec']:
@@ -138,11 +149,9 @@ def _addRequirement(self, parent, info, page, req, requirements):
content = fid.read()

floats.create_modal_link(p,
url=u"#",
title=tokens.String(None, content=unicode(req.filename)),
content=core.Code(None, language=u'text', code=content),
string=u"{}:{}".format(req.path, req.name),
tooltip=False)
title=req.filename,
content=core.Code(None, language=u'text', content=content),
string=u"{}:{}".format(req.path, req.name))

if self.settings['link-design'] and req.design:
p = core.Paragraph(item)
@@ -152,7 +161,7 @@ def _addRequirement(self, parent, info, page, req, requirements):

if self.settings['link-issues'] and req.issues:
p = core.Paragraph(item)
tokens.String(p, content=u'Issues: ')
tokens.String(p, content=u'Issue(s): ')
for issue in req.issues:
if issue.startswith('#'):
url = u"https://github.com/idaholab/moose/issues/{}".format(issue[1:])
@@ -180,13 +189,22 @@ def createToken(self, parent, info, page):
for requirements in self.extension.requirements.itervalues():
for req in requirements:
for d in req.design:
node = self.translator.findPage(d)
design[node].append(req)
try:
node = self.translator.findPage(d)
design[node].append(req)
except exceptions.MooseDocsException:
msg = "Failed to locate the design page '{}'".format(d)
LOG.critical(common.report_error(msg,
req.filename,
req.design_line,
' '.join(req.design),
traceback.format_exc(),
'SQA ERROR'))

for node, requirements in design.iteritems():
matrix = SQARequirementMatrix(parent)#, heading=link)
matrix = SQARequirementMatrix(parent)
heading = SQARequirementMatrixHeading(matrix)
autolink.AutoLink(heading, page=unicode(node.fullpath))
autolink.AutoLink(heading, page=unicode(node.local))
for req in requirements:
self._addRequirement(matrix, info, page, req, requirements)

@@ -218,7 +236,8 @@ def createToken(self, parent, info, page):
ul.parent = None

# Check the list type
if not isinstance(ul, core.UnorderedListBlock):
if ul.name != 'UnorderedList':
print ul.name
msg = "The content is required to be an unordered list (i.e., use '-')."
raise exceptions.MooseDocsException(msg)

@@ -343,19 +362,28 @@ def _addRequirement(self, parent, info, page, req):
label=unicode(req.label),
satisfied=req.satisfied,
id_=req.path)
self.reader.tokenize(item, req.text, page, line=info.line)


self.reader.tokenize(item, req.text, page, MooseDocs.INLINE, info.line, report=False)
for token in anytree.PreOrderIter(item):
if token.name == 'ErrorToken':
msg = common.report_error("Failed to tokenize SQA requirement.",
req.filename,
req.text_line,
req.text,
token['traceback'],
u'SQA TOKENIZE ERROR')
LOG.critical(msg)

p = core.Paragraph(item)
tokens.String(p, content=u'Specification: ')

with codecs.open(req.filename, encoding='utf-8') as fid:
content = fid.read()
floats.create_modal_link(p,
tooltip=False,
url=u"#",
string=u"{}:{}".format(req.path, req.name),
title=tokens.String(None, content=unicode(req.filename)),
content=core.Code(None, language=u'text', code=content))
content=core.Code(None, language=u'text', content=content),
title=unicode(req.filename))

p = core.Paragraph(item)
tokens.String(p, content=u'Details: ')
@@ -369,8 +397,8 @@ def createHTML(self, parent, token, page):

def createMaterialize(self, parent, token, page):

key = token.key
func = lambda n: isinstance(n, SQADocumentItem) and (n.key == key)
key = token['key']
func = lambda n: (n.name == 'SQADocumentItem') and (n['key'] == key)
replacement = anytree.search.find(token.root, filter_=func, maxlevel=2)

if replacement:
@@ -419,14 +447,14 @@ def createMaterialize(self, parent, token, page):
class RenderSQARequirementMatrixItem(core.RenderListItem):
def createMaterialize(self, parent, token, page): #pylint: disable=no-self-use,unused-argument
li = html.Tag(parent, 'li', class_="collection-item", **token.attributes)
num = html.Tag(li, 'span', string=token.label, class_='moose-requirement-number')
num = html.Tag(li, 'span', string=token['label'], class_='moose-requirement-number')

id_ = token.get('id', None)
if id_:
num.addClass('tooltipped')
num['data-tooltip'] = id_

if not token.satisfied:
if not token['satisfied']:
num = html.Tag(li, 'i', string=u'block',
class_='material-icons moose-requirement-unsatisfied')

Oops, something went wrong.

0 comments on commit 2290c8d

Please sign in to comment.