Ejemplo n.º 1
0
    def execute(self, **kwargs):
        """
        Computes the percent complete, number missing items, and the pass/fail status
        """

        # Extract configuration parameters
        specs = self.specs or 'tests'

        # Get complete directory paths
        root_dir = mooseutils.git_root_dir()
        directories = [mooseutils.eval_path(d) for d in (self.directories or [root_dir])]
        for i, d in enumerate(directories):
            if not os.path.isdir(d):
                directories[i] = os.path.join(root_dir, d)
            if not os.path.isdir(directories[i]):
                raise NotADirectoryError("Supplied directory does not exist: {}".format(d))

        # Build Requirement objects and remove directory based dict
        req_dict = get_requirements_from_tests(directories, specs.split(), self.include_non_testable)
        requirements = []
        for values in req_dict.values():
            requirements += values

        # Populate the lists of tests for SQARequirementDiffReport
        self.test_names = set()
        for req in requirements:
            self.test_names.add((req.filename, req.name, req.line))

        # Get list of files to search
        if self.working_dirs is None: self.working_dirs = [mooseutils.git_root_dir()]
        file_list = SQAReport._getFiles(self.working_dirs)

        # Check the requirements
        logger = check_requirements(requirements, color_text=self.color_text, file_list=file_list, **kwargs)
        return logger
Ejemplo n.º 2
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        # Default attributes
        self.exe_directory = self.exe_directory or mooseutils.git_root_dir()
        self.exe_name = self.exe_name or os.path.basename(self.exe_directory)
        self.working_dir = self.working_dir or mooseutils.git_root_dir()
        self.content_directory = self.content_directory or os.path.join(self.exe_directory, 'doc', 'content')
        self.object_prefix = self.object_prefix or os.path.join(self.content_directory, 'source')
        self.syntax_prefix = self.syntax_prefix or os.path.join(self.content_directory, 'syntax')
Ejemplo n.º 3
0
def get_options():
    """Return the command-line options"""
    parser = argparse.ArgumentParser(
        description='Tool for listing author line counts.',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('locations',
                        nargs='*',
                        type=str,
                        default=[mooseutils.git_root_dir()],
                        help='The repository directory to consider.')
    parser.add_argument(
        '-j',
        '--num-threads',
        type=int,
        default=os.cpu_count(),
        help="The number of threads to use for computing the counts.")
    parser.add_argument('--exclude',
                        nargs=1,
                        type=str,
                        default='contrib',
                        help="Exclude pattern passed to git ls-files call.")
    parser.add_argument('-l',
                        '--languages',
                        nargs='+',
                        type=str,
                        choices=list(LANGUAGES.keys()),
                        default=list(LANGUAGES.keys()),
                        help="Limit the analysis the the listed languages.")

    return parser.parse_args()
Ejemplo n.º 4
0
 def testNoneError(self):
     fname = 'markers/box_marker/wrong'
     root_dir = mooseutils.git_root_dir(os.path.dirname(__file__))
     with self.assertRaises(NameError) as e:
         filename = _find_file(root_dir, fname)
     self.assertIn('Unable to locate a test specification',
                   str(e.exception))
Ejemplo n.º 5
0
 def testLanguage(self):
     locations = [
         os.path.join(mooseutils.git_root_dir(), 'python', 'mooseutils')
     ]
     out = mooseutils.check_output(
         ['./authors.py', *locations, '-j', '1', '-l', 'Python'],
         cwd=os.path.join(mooseutils.git_root_dir(), 'scripts'))
     self.assertIn('Andrew', out)
     self.assertNotIn('C++', out)
     self.assertIn('Python', out)
     self.assertNotIn('Input', out)
     self.assertNotIn('Markdown', out)
     self.assertNotIn('Make', out)
     self.assertNotIn('YAML', out)
     self.assertIn('Total', out)
     self.assertIn('TOTAL', out)
Ejemplo n.º 6
0
def get_options():
    """Command-line options."""
    parser = argparse.ArgumentParser(
        description='SQA Requirement checking tool.')

    parser.add_argument('-d',
                        '--directory',
                        type=str,
                        default=mooseutils.git_root_dir(),
                        help="The directory to search.")
    parser.add_argument('-r',
                        '--remote',
                        type=str,
                        default='origin',
                        help="The name of the git remote to compare against.")
    parser.add_argument('-b',
                        '--branch',
                        type=str,
                        default='devel',
                        help="The name of the branch to compare against.")
    parser.add_argument(
        '--specs',
        type=list,
        default=['tests'],
        help="The name of the specification files to consider.")
    parser.add_argument('--skip',
                        nargs='+',
                        default=[],
                        help="Partial directory paths to ignore.")
    return parser.parse_args()
Ejemplo n.º 7
0
def sqa_check(working_dir=os.getcwd(),
              remote='origin',
              branch='devel',
              specs=['tests'],
              skip=[]):
    """Check that test specifications that were modified include requirements."""

    # Fetch
    cmd = ['git', 'fetch', remote]
    subprocess.call(cmd)

    # Root directory of repository
    root = git_root_dir(working_dir)

    # Check requirements on changed tests specs
    count = 0
    cmd = ['git', 'merge-base', '{}/{}'.format(remote, branch), 'HEAD']
    sha = subprocess.check_output(cmd).strip()
    cmd = ['git', 'diff', sha, '--name-only']
    for filename in subprocess.check_output(cmd).split('\n'):
        if os.path.isfile(filename) and (os.path.basename(filename) in specs) and \
           not any(s in filename for s in skip):
            count += check_requirement(os.path.join(root, filename))

    return count
Ejemplo n.º 8
0
    def testGitInitSubmodule(self, status_func, call_func):
        status_func.return_value = {'test':'-'}

        root = mooseutils.git_root_dir()
        mooseutils.git_init_submodule('test', root)

        status_func.assert_called_with(root)
        call_func.assert_called_with(['git', 'submodule', 'update', '--init', 'test'], cwd=root)
Ejemplo n.º 9
0
def doc_tree(items):
    """
    Create a tree of files for processing.

    Inputs:
        inputs: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
    """
    # Error checking
    if not isinstance(items, list) or any(not isinstance(x, dict)
                                          for x in items):
        LOG.error(
            'The supplied items must be a list of dict items, each with a "root_dir" and '
            'optionally a "content" entry.')
        return None

    # Define a dict for storing nodes by path
    nodes = dict()

    # Create the root node
    nodes[()] = page.DirectoryNode(source='')

    # Create the file tree
    for value in items:

        if 'root_dir' not in value:
            LOG.error(
                'The supplied items must be a list of dict items, each with a "root_dir" and '
                'optionally a "content" entry.')

        root = mooseutils.eval_path(value['root_dir'])
        if not os.path.isabs(root):
            root = os.path.join(MooseDocs.ROOT_DIR, root)

        # Update the project files
        MooseDocs.PROJECT_FILES.update(
            mooseutils.git_ls_files(mooseutils.git_root_dir(root)))

        files = doc_import(root, content=value.get('content', None))
        for filename in files:
            key = tuple(filename.replace(root, '').strip('/').split('/'))

            # Create directory nodes if they don't exist
            for i in range(1, len(key)):
                dir_key = key[:i]
                if dir_key not in nodes:
                    nodes[dir_key] = page.DirectoryNode(nodes[key[:i - 1]],
                                                        name=key[i - 1],
                                                        source=os.path.join(
                                                            root, *dir_key))

            # Create the file node, if it doesn't already exist. This enforces that the first
            # item in the supplied content lists is the page that is rendered.
            if key not in nodes:
                nodes[key] = create_file_node(nodes[key[:-1]], key[-1],
                                              filename)

    return nodes[()]
Ejemplo n.º 10
0
    def testEndswith(self):
        fname = 'markers/box_marker/tests'
        root_dir = mooseutils.git_root_dir(os.path.dirname(__file__))

        filename = _find_file(root_dir, fname)
        self.assertEqual(
            filename,
            os.path.join(root_dir, 'test', 'tests', 'markers', 'box_marker',
                         'tests'))
Ejemplo n.º 11
0
 def testGitSubmoduleInfo(self):
     root = mooseutils.git_root_dir()
     status = mooseutils.git_submodule_info(root)
     self.assertIn('large_media', status)
     self.assertIn('libmesh', status)
     self.assertIn('petsc', status)
     self.assertEqual(len(status['large_media']), 3)
     self.assertEqual(len(status['libmesh']), 3)
     self.assertEqual(len(status['petsc']), 3)
Ejemplo n.º 12
0
 def __init__(self, **kwargs):
     self._documents = dict()
     kwargs.setdefault('required_documents', INL_DOCUMENTS)
     self._documents = {
         name: kwargs.pop(name, None)
         for name in kwargs.get('required_documents')
     }
     super().__init__(**kwargs)
     self.working_dir = self.working_dir or mooseutils.git_root_dir()
Ejemplo n.º 13
0
 def setUpClass(cls):
     cls.ROOT_DIR = mooseutils.git_root_dir(os.path.dirname(__file__))
     cls.TEMPLATE_DIR = os.path.join(cls.ROOT_DIR, 'framework', 'doc', 'content', 'templates', 'sqa')
     cls.TEMPLATE_NAMES =['far.md.template', 'rtm.md.template', 'sdd.md.template', 'srs.md.template',
                          'stp.md.template', 'vvr.md.template', 'cci.md.template', 'scs.md.template',
                          'sll.md.template', 'app_index.md.template',
                          'app_far.md.template', 'app_rtm.md.template', 'app_sdd.md.template',
                          'app_srs.md.template', 'app_stp.md.template', 'app_vvr.md.template',
                          'app_cci.md.template', 'app_scs.md.template', 'app_sll.md.template']
     cls.DOC_FILE = os.path.join(cls.ROOT_DIR, 'modules', 'doc', 'content', 'python', 'MooseDocs', 'extensions', 'sqa.md')
     cls.COLLECTIONS = {'FUNCTIONAL', 'USABILITY', 'PERFORMANCE', 'SYSTEM', 'FAILURE_ANALYSIS'}
Ejemplo n.º 14
0
    def __init__(self, **kwargs):

        self.app_syntax = kwargs.pop('app_syntax', None)
        self.app_types = kwargs.pop('app_types', None)
        self.working_dir = kwargs.pop('working_dir', mooseutils.git_root_dir())
        self.exe_directory = kwargs.pop('exe_directory',
                                        mooseutils.git_root_dir())
        self.exe_name = kwargs.pop('exe_name',
                                   os.path.basename(self.exe_directory))
        self.content_directory = kwargs.pop(
            'content_directory',
            os.path.join(self.exe_directory, 'doc', 'content'))
        self.object_prefix = kwargs.pop(
            'object_prefix', os.path.join(self.content_directory, 'source'))
        self.syntax_prefix = kwargs.pop(
            'syntax_prefix', os.path.join(self.content_directory, 'syntax'))
        self.remove = kwargs.pop('remove', None)
        self.alias = kwargs.pop('alias', None)
        self.unregister = kwargs.pop('unregister', None)
        self.allow_test_objects = kwargs.pop('allow_test_objects', False)
        super().__init__(**kwargs)
Ejemplo n.º 15
0
    def __init__(self, **kwargs):
        self._documents = dict()
        kwargs.setdefault('required_documents', INL_DOCUMENTS)
        for name in kwargs.get('required_documents'):
            doc = kwargs.pop(name, None)
            if doc is not None:
                doc = mooseutils.eval_path(doc)
            self._documents[name] = doc

        super().__init__(**kwargs)
        if self.working_dirs is None:
            self.working_dirs = [mooseutils.git_root_dir()]
Ejemplo n.º 16
0
def compute_requirement_stats(location,
                              specs=['tests'],
                              working_dir=None,
                              show=True,
                              list_missing=False):
    """
    Report requirement statistics for the test spec files with the supplied location.

    Inputs:
        location: Path to directory contain test specifications, the supplied path should be
                  relative to the cwd input.
        specs: The filename(s) to consider
        working_dir: The working directory, if not supplied the root directory of the repository is used
    """
    from .hit_load import hit_load

    tests_with_missing_requirements = set()
    working_dir = git_root_dir(
        os.getcwd()) if working_dir is None else working_dir
    data = SQAStats(location)
    location = os.path.join(working_dir, location)
    for filename in git_ls_files(location):
        if not os.path.isfile(filename):
            continue
        fname = os.path.basename(filename)
        if fname in specs:
            root = hit_load(filename)
            has_requirement = False
            for child in root.children[0]:
                data.tests += 1

                deprecated = root.children[0].get(
                    'deprecated', False) or child.get('deprecated', False)
                if deprecated:
                    data.tests_deprecated += 1

                if child.get('requirement', None):
                    has_requirement = True
                    data.tests_with_requirement += 1
                elif not deprecated:
                    tests_with_missing_requirements.add((filename, child.name))

            data.files += 1

    if show:
        print(data)
    if list_missing and tests_with_missing_requirements:
        print('\nMissing Requirements:')
        for filename, test in tests_with_missing_requirements:
            print('{}:{}'.format(filename, test))

    return data
Ejemplo n.º 17
0
def doc_tree(items):
    """
    Create a tree of files for processing.

    Inputs:
        inputs: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
    """
    # Error checking
    if not isinstance(items, list) or any(not isinstance(x, dict) for x in items):
        LOG.error('The supplied items must be a list of dict items, each with a "root_dir" and '
                  'optionally a "content" entry.')
        return None

    # Define a dict for storing nodes by path
    nodes = dict()

    # Create the root node
    nodes[()] = page.DirectoryNode(source='')

    # Create the file tree
    for value in items:

        if 'root_dir' not in value:
            LOG.error('The supplied items must be a list of dict items, each with a "root_dir" and '
                      'optionally a "content" entry.')

        root = mooseutils.eval_path(value['root_dir'])
        if not os.path.isabs(root):
            root = os.path.join(MooseDocs.ROOT_DIR, root)

        # Update the project files
        MooseDocs.PROJECT_FILES.update(mooseutils.git_ls_files(mooseutils.git_root_dir(root)))

        files = doc_import(root, content=value.get('content', None))
        for filename in files:
            key = tuple(filename.replace(root, '').strip('/').split('/'))

            # Create directory nodes if they don't exist
            for i in range(1, len(key)):
                dir_key = key[:i]
                if dir_key not in nodes:
                    nodes[dir_key] = page.DirectoryNode(nodes[key[:i-1]],
                                                        name=key[i-1],
                                                        source=os.path.join(root, *dir_key))

            # Create the file node
            nodes[key] = create_file_node(nodes[key[:-1]], key[-1], filename)

    return nodes[()]
Ejemplo n.º 18
0
def get_content(items, in_ext):
    """
    Create a tree of files for processing.

    Inputs:
        items: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
        in_ext[tuple]: Set of extensions to be converted (e.g., ('.md', )).
        out_ext[str]: The extension of rendered result (e.g., '.html').
    """
    if not isinstance(items, list) or any(not isinstance(x, dict)
                                          for x in items):
        LOG.error(
            'The supplied items must be a list of dict items, each with a "root_dir" and '
            'optionally a "content" entry.')
        return None

    roots = set()
    nodes = dict()
    for root, filename, external in get_files(items, in_ext):
        roots.add(root)
        key = filename.replace(root, '').strip('/')
        parts = key.split('/')

        # Create directory nodes if they don't exist
        for i in range(1, len(parts)):
            dir_key = os.path.join(*parts[:i])
            if dir_key not in nodes:
                nodes[dir_key] = pages.Directory(dir_key,
                                                 external=external,
                                                 source=os.path.join(
                                                     root, dir_key))

        # Create the file node, if it doesn't already exist. This enforces that the first
        # item in the supplied content lists is the page that is rendered.
        if key not in nodes:
            nodes[key] = create_file_page(key, filename, in_ext)

        nodes[key].external = external

    # Update the project files
    for root in roots:
        if mooseutils.is_git_repo(root):
            MooseDocs.PROJECT_FILES.update(
                mooseutils.git_ls_files(mooseutils.git_root_dir(root)))
        else:
            MooseDocs.PROJECT_FILES.update(mooseutils.list_files(root))

    return list(nodes.values())
Ejemplo n.º 19
0
def get_options():
    """Command-line options."""
    parser = argparse.ArgumentParser(description='SQA Requirement checking tool.')

    parser.add_argument('-d', '--directory', type=str, default=mooseutils.git_root_dir(),
                        help="The directory to search.")
    parser.add_argument('-r', '--remote', type=str, default='origin',
                        help="The name of the git remote to compare against.")
    parser.add_argument('-b', '--branch', type=str, default='devel',
                        help="The name of the branch to compare against.")
    parser.add_argument('--specs', type=list, default=['tests'],
                        help="The name of the specification files to consider.")
    parser.add_argument('--skip', nargs='+', default=[],
                        help="Partial directory paths to ignore.")
    return parser.parse_args()
Ejemplo n.º 20
0
    def execute(self, **kwargs):
        """
        Computes the percent complete, number missing items, and the pass/fail status
        """

        # Extract configuration parameters
        working_dir = self.working_dir or mooseutils.git_root_dir()
        local_dirs = self.directories
        specs = self.specs or 'tests'

        # Get complete directory paths
        if local_dirs:
            directories = list()
            for local_dir in local_dirs:
                d = mooseutils.eval_path(local_dir)
                if not os.path.isdir(d):
                    d = os.path.join(working_dir, d)
                directories.append(d)
        else:
            directories = [working_dir]

        # Check that directories exist
        for d in directories:
            if not os.path.isdir(d):
                raise NotADirectoryError(
                    "Supplied directory does not exist: {}".format(d))

        # Build Requirement objects and remove directory based dict
        req_dict = get_requirements(directories, specs.split())
        requirements = []
        for values in req_dict.values():
            requirements += values

        # Populate the lists of tests for SQARequirementDiffReport
        self.test_names = set()
        for req in requirements:
            self.test_names.add((req.filename, req.name, req.line))

        # Check the requirements
        logger = check_requirements(requirements,
                                    color_text=self.color_text,
                                    **kwargs)

        return logger
Ejemplo n.º 21
0
def get_content(items, in_ext):
    """
    Create a tree of files for processing.

    Inputs:
        items: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
        in_ext[tuple]: Set of extensions to be converted (e.g., ('.md', )).
        out_ext[str]: The extension of rendered result (e.g., '.html').
    """
    if not isinstance(items, list) or any(not isinstance(x, dict) for x in items):
        LOG.error('The supplied items must be a list of dict items, each with a "root_dir" and '
                  'optionally a "content" entry.')
        return None

    roots = set()
    nodes = dict()
    for root, filename in get_files(items, in_ext):
        roots.add(root)
        key = filename.replace(root, '').strip('/')
        parts = key.split('/')

        # Create directory nodes if they don't exist
        for i in range(1, len(parts)):
            dir_key = os.path.join(*parts[:i])
            if dir_key not in nodes:
                nodes[dir_key] = MooseDocs.tree.pages.Directory(dir_key,
                                                                source=os.path.join(root, dir_key))

        # Create the file node, if it doesn't already exist. This enforces that the first
        # item in the supplied content lists is the page that is rendered.
        if key not in nodes:
            nodes[key] = create_file_page(key, filename, in_ext)

    # Update the project files
    for root in roots:
        if mooseutils.is_git_repo(root):
            MooseDocs.PROJECT_FILES.update(mooseutils.git_ls_files(mooseutils.git_root_dir(root)))
        else:
            MooseDocs.PROJECT_FILES.update(mooseutils.list_files(root))

    return nodes.values()
Ejemplo n.º 22
0
def get_requirements_from_tests(directories, specs, include_non_testable=False):
    """
    Build requirements dictionary from the provided directories.

    Input:
        directories[list]: A list of directories to consider
        specs[list]: A list of test specification names (e.g., ['tests'])
    """
    out = collections.defaultdict(list)
    for location in directories:
        root_dir = mooseutils.git_root_dir(location)
        for filename in sorted(mooseutils.git_ls_files(location)):
            if os.path.isfile(filename) and (os.path.basename(filename) in specs):
                local = os.path.relpath(filename, location)
                group = local.split('/')[0]
                out[group] += get_requirements_from_file(filename,
                                                         os.path.dirname(local),
                                                         include_non_testable,
                                                         root_dir)
    return out
Ejemplo n.º 23
0
def get_test_specification(filename, block):
    """
    Create a TestSpecification object from the HIT file and block name.

    Input:
        filename[str]: Complete filename of a HIT file containing test specification(s)
        block[str]: The name of the block to use for creating the TestSpecification object

    This function exists to allow for requirements to be defined outside of the test specifications,
    but still reference tests for the purpose of SQA traceability. Support for this was added to
    allow for non-functional requirements to be defined outside of the test specifications.
    """
    root = pyhit.load(filename)

    # Locate the desired block
    node = moosetree.find(root, lambda n: n.fullpath.endswith(block))
    if node is None:
        raise KeyError("Unable to locate '{}' in {}".format(block, filename))

    # Build/return TestSpecification object
    name = node.name if node.parent.parent.is_root else '{}/{}'.format(node.parent.name, node.name)
    return _create_specification(node, name, filename, mooseutils.git_root_dir(os.path.dirname(filename)))
Ejemplo n.º 24
0
def compute_requirement_stats(location,
                              specs=['tests'],
                              working_dir=None,
                              show=True):
    """
    Report requirement statistics for the test spec files with the supplied location.

    Inputs:
        location: Path to directory contain test specifications, the supplied path should be
                  relative to the cwd input.
        specs: The filename(s) to consider
        working_dir: The working directory, if not supplied the root directory of the repository is used

    """
    working_dir = git_root_dir(
        os.getcwd()) if working_dir is None else working_dir
    data = SQAStats(location)
    location = os.path.join(working_dir, location)
    for filename in git_ls_files(location):
        if not os.path.isfile(filename):
            continue
        fname = os.path.basename(filename)
        if fname in specs:
            root = hit_load(filename)
            has_requirement = False
            for child in root.children[0]:
                data.tests += 1
                if child.get('requirement', None):
                    has_requirement = True
                    data.tests_with_requirement += 1

            data.files += 1
            if has_requirement:
                data.files_with_requirement += 1

    if show:
        print(data)
    return data
Ejemplo n.º 25
0
def check_documents(documents, file_list=None, **kwargs):
    """
    Tool for checking SQA document deficiencies
    """

    # Setup logger, assume the names of the documents with a "log_" prefix are the logging flags (see get_documents)
    for doc in documents:
        kwargs.setdefault("log_" + doc.name, logging.ERROR)
    logger = LogHelper(__name__, **kwargs)

    # Setup file_list, if not provided
    if (file_list is None) and (not mooseutils.is_git_repo()):
        msg = "If the 'file_list' is not provided then the working directory must be a git repository."
        raise ValueError(msg)
    elif file_list is None:
        root = mooseutils.git_root_dir()
        file_list = mooseutils.git_ls_files(root, recurse_submodules=False)

    # Perform document checks
    for doc in documents:
        _check_document(doc.name, doc.filename, file_list, logger)

    return logger
Ejemplo n.º 26
0
import os
import sys
import subprocess
import mooseutils

moose_dir = mooseutils.git_root_dir(os.path.dirname(__file__))
status = mooseutils.git_submodule_status(moose_dir)

# Use framework/contrib/hit because moosetools submodule is not available
if status['moosetools'] == '-':
    hit_dir = os.path.join(moose_dir, 'framework', 'contrib', 'hit')
    sys.path.append(hit_dir)
    try:
        import hit
    except:
        moose_test_dir = os.path.abspath(os.path.join(moose_dir, 'test'))
        subprocess.run(['make', 'hit'], cwd=moose_test_dir)
        import hit
# Use hit in moosetools submodule
else:
    hit_dir = os.path.join(moose_dir, 'moosetools', 'contrib', 'hit')
    sys.path.append(hit_dir)
    try:
        import hit
    except:
        subprocess.run(['make', 'hit.so'], cwd=hit_dir)
        import hit

from hit import TokenType, Token
from .pyhit import Node, load, write, parse, tokenize
Ejemplo n.º 27
0
import logging

if sys.version_info < (3, 6):
    print('"MOOSEDocs" requires python version 3.6 or greater, version {}.{} is being used.' \
          .format(sys.version_info[0], sys.version_info[1]))
    sys.exit(1)

import mooseutils

# Current logging level, used to allow for debug only type checking, etc.
LOG_LEVEL = logging.NOTSET

# The repository root location
is_git_repo = mooseutils.git_is_repo()
if is_git_repo:
    os.environ.setdefault('ROOT_DIR',  mooseutils.git_root_dir())
elif 'ROOT_DIR' not in os.environ:
    print('MooseDocs requires the ROOT_DIR environment variable to set when operating outside of a git repository.')
    sys.exit(1)

ROOT_DIR = os.environ['ROOT_DIR']

# Setup MOOSE_DIR/ROOT_DIR
MOOSE_DIR = os.getenv('MOOSE_DIR', None)
if MOOSE_DIR is None:
    print("The MOOSE_DIR environment must be set, this should be set within moosedocs.py.")
    sys.exit(1)

# Initialize submodule(s)
mooseutils.git_init_submodule('large_media', MOOSE_DIR)
Ejemplo n.º 28
0
#!/usr/bin/env python
import os
import sys
import unittest
import mooseutils

ROOT_DIR = mooseutils.git_root_dir()
sys.path.insert(0, os.path.join(ROOT_DIR, 'scripts'))
from sqa_check import check_requirement

class Test(unittest.TestCase):
    def testScript(self):
        """Test the SQA checker."""
        check_requirement('[Tests][foo][][]')
        output = sys.stdout.getvalue()
        self.assertIn('requirement', output)
        self.assertIn('design', output)
        self.assertIn('issues', output)

if __name__ == '__main__':
    unittest.main(verbosity=2, buffer=True)
Ejemplo n.º 29
0
    if messages:
        print 'ERROR in {}'.format(filename)
        print '\n'.join(messages) + '\n'
        return 1
    return 0


if __name__ == '__main__':

    opt = get_options()

    # Fetch
    cmd = ['git', 'fetch', opt.remote]
    subprocess.call(cmd)

    # Root git directory
    root = mooseutils.git_root_dir()

    # Check requirements on changed tests specs
    count = 0
    cmd = [
        'git', 'diff', '{}/{}'.format(opt.remote, opt.branch), '--name-only'
    ]
    for filename in subprocess.check_output(cmd).split('\n'):
        if os.path.isfile(filename) and (os.path.basename(filename)
                                         in opt.specs):
            count += check_requirement(os.path.join(root, filename))

    sys.exit(count)
Ejemplo n.º 30
0
#!/usr/bin/env python3
#* This file is part of the MOOSE framework
#* https://www.mooseframework.org
#*
#* All rights reserved, see COPYRIGHT for full restrictions
#* https://github.com/idaholab/moose/blob/master/COPYRIGHT
#*
#* Licensed under LGPL 2.1, please see LICENSE for details
#* https://www.gnu.org/licenses/lgpl-2.1.html

import os
import sys
import unittest
import mooseutils

ROOT_DIR = mooseutils.git_root_dir()
sys.path.insert(0, os.path.join(ROOT_DIR, 'scripts'))
from git_news import main


class Test(unittest.TestCase):
    def testScript(self):
        """Test the get_news.py script"""
        proc = main()
        self.assertFalse(proc.returncode)


if __name__ == '__main__':
    unittest.main(verbosity=2, buffer=True)
Ejemplo n.º 31
0
        if child.get('issues', issues) is None:
            messages.append("    'issues' parameter is missing in '{}' block.".format(child.name))

    if messages:
        print 'ERROR in {}'.format(filename)
        print '\n'.join(messages) + '\n'
        return 1
    return 0

if __name__ == '__main__':

    opt = get_options()

    # Fetch
    cmd = ['git', 'fetch', opt.remote]
    subprocess.call(cmd)

    # Root git directory
    root = mooseutils.git_root_dir()

    # Check requirements on changed tests specs
    count = 0
    cmd = ['git', 'merge-base', '{}/{}'.format(opt.remote, opt.branch), 'HEAD']
    sha = subprocess.check_output(cmd).strip()
    cmd = ['git', 'diff', sha, '--name-only']
    for filename in subprocess.check_output(cmd).split('\n'):
        if os.path.isfile(filename) and (os.path.basename(filename) in opt.specs):
            count += check_requirement(os.path.join(root, filename))

    sys.exit(count)
Ejemplo n.º 32
0
def check_requirements(requirements,
                       file_list=None,
                       color_text=True,
                       allowed_collections=None,
                       allowed_classifications=None,
                       **kwargs):
    """
    Tool for checking Requirement for deficiencies
    """

    # Create key values for the logging messages
    log_default = kwargs.get('log_default', logging.ERROR)
    kwargs.setdefault('log_deprecated_requirement', log_default)
    kwargs.setdefault('log_deprecated_design', log_default)
    kwargs.setdefault('log_deprecated_issues', log_default)
    kwargs.setdefault('log_deprecated_detail', log_default)
    kwargs.setdefault('log_deprecated_verification', log_default)
    kwargs.setdefault('log_deprecated_validation', log_default)
    kwargs.setdefault('log_deprecated_with_details', log_default)
    kwargs.setdefault('log_missing', log_default)
    kwargs.setdefault('log_missing_requirement', log_default)
    kwargs.setdefault('log_missing_design', log_default)
    kwargs.setdefault('log_missing_issues', log_default)
    kwargs.setdefault('log_empty_requirement', log_default)
    kwargs.setdefault('log_empty_design', log_default)
    kwargs.setdefault('log_empty_issues', log_default)
    kwargs.setdefault('log_empty_verification', log_default)
    kwargs.setdefault('log_empty_validation', log_default)
    kwargs.setdefault('log_top_level_detail', log_default)
    kwargs.setdefault('log_missing_detail', log_default)
    kwargs.setdefault('log_empty_detail', log_default)
    kwargs.setdefault('log_extra_requirement', log_default)
    kwargs.setdefault('log_extra_design', log_default)
    kwargs.setdefault('log_extra_issues', log_default)
    kwargs.setdefault('log_extra_collections', log_default)
    kwargs.setdefault('log_invalid_collection', log_default)
    kwargs.setdefault('log_issue_format', log_default)
    kwargs.setdefault('log_design_files', log_default)
    kwargs.setdefault('log_validation_files', log_default)
    kwargs.setdefault('log_verification_files', log_default)
    kwargs.setdefault('log_testable', log_default)
    kwargs.setdefault('log_duplicate_requirement', log_default)
    kwargs.setdefault('log_duplicate_detail', log_default)

    logger = RequirementLogHelper(__name__, **kwargs)
    RequirementLogHelper.COLOR_TEXT = color_text

    # Setup file_list, if not provided
    if (file_list is None) and (not mooseutils.git_is_repo()):
        msg = "If the 'file_list' is not provided then the working directory must be a git repository."
        raise ValueError(msg)
    elif file_list is None:
        root = mooseutils.git_root_dir()
        ver = mooseutils.git_version()
        file_list = mooseutils.git_ls_files(root, recurse_submodules=True)

    # Setup allowed collections
    if allowed_collections is None:
        allowed_collections = set(moosesqa.MOOSESQA_COLLECTIONS)

    # Storage container for duplicate detection
    requirement_dict = collections.defaultdict(set)

    # Check each Requirement object for deficiencies
    for req in requirements:
        _check_requirement(req, logger, file_list, allowed_collections)
        if req.requirement is not None:
            key = [req.requirement]
            for detail in req.details:
                if detail.detail is not None:
                    key.append(detail.detail)
            requirement_dict['\n'.join(key)].add(req)

    # Duplicate checking
    for txt, value in requirement_dict.items():
        if len(value) > 1:
            msg = 'Duplicate requirements found:'
            msg += '\n{}\n'.format(
                mooseutils.colorText(txt, 'GREY', colored=color_text))
            for r in value:
                r.duplicate = True
                msg += RequirementLogHelper._colorTestInfo(r, None, None, None)

            LogHelper.log(logger, 'log_duplicate_requirement', msg.strip('\n'))

    return logger
Ejemplo n.º 33
0
 def testGitSubmoduleStatus(self):
     root = mooseutils.git_root_dir()
     status = mooseutils.git_submodule_status(root)
     self.assertIn('large_media', status)
     self.assertIn('libmesh', status)
     self.assertIn('petsc', status)
Ejemplo n.º 34
0
 def testGitRootDir(self):
     root = mooseutils.git_root_dir()
     self.assertEqual(
         root,
         os.path.abspath(
             os.path.join(os.path.dirname(__file__), '..', '..', '..')))
Ejemplo n.º 35
0
 def testToManyError(self):
     fname = 'box_marker/tests'
     root_dir = mooseutils.git_root_dir(os.path.dirname(__file__))
     with self.assertRaises(NameError) as e:
         filename = _find_file(root_dir, fname)
     self.assertIn('Located multiple test specifications', str(e.exception))