Exemplo n.º 1
0
    def testBasic(self):
        MOOSE_DIR = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..', '..'))
        loc = [os.path.join(MOOSE_DIR, 'test', 'tests', 'markers')]
        req = get_requirements_from_tests(loc, ['tests'])

        r0 = req['box_marker'][0]
        r1 = req['box_marker'][1]

        self.assertEqual(r0.issues, ['#1275'])
        self.assertEqual(r1.issues, ['#1275'])

        self.assertEqual(r0.design, ['/Markers/index.md', '/BoxMarker.md'])
        self.assertEqual(r1.design, ['/Markers/index.md', '/BoxMarker.md'])

        self.assertIn('create an aux', r0.requirement)
        self.assertIn('within a rec', r1.requirement)

        self.assertEqual(r0.name, 'mark_only')
        self.assertEqual(r1.name, 'mark_and_adapt')

        self.assertIn('markers/box_marker/tests', r0.filename)
        self.assertIn('markers/box_marker/tests', r1.filename)

        spec0 = r0.specification
        self.assertEqual(spec0.name, 'mark_only')
        self.assertIn('markers/box_marker/tests', spec0.filename)
Exemplo n.º 2
0
    def preExecute(self):
        """Initialize requirement information"""

        # Clear any existing counts
        self.__counts.clear()

        # Do not repopulate
        if self.__requirements:
            return

        start = time.time()
        LOG.info("Gathering SQA requirement information...")

        for category, info in self.get('categories').items():
            specs = info.get('specs', ['tests'])
            repo = info.get('repo', 'default')
            reports = info.get('reports', None)

            # Build the requirements, dependencies, remotes, and reports data structures
            directories = list()
            for d in info.get('directories', []):
                path = mooseutils.eval_path(d)
                if not os.path.isdir(path):
                    path = os.path.join(MooseDocs.ROOT_DIR, d)
                if not os.path.isdir(path):
                    msg = "Input directory does not exist: %s"
                    LOG.error(msg, path)
                    continue
                directories.append(path)

            # Create requirement database from tests
            self.__requirements[
                category] = moosesqa.get_requirements_from_tests(
                    directories, specs,
                    self.get('include_non_testable_requirements'))

            # Create dependency database
            self.__dependencies[category] = info.get('dependencies', [])

            # Create remote repository database
            repos = self.get('repos')
            self.__remotes[category] = repos.get(repo, None)

            # Create reports from included SQA apps (e.g., moose/modulus/stochastic_tools)
            if reports:
                self.__reports[category] = moosesqa.get_sqa_reports(reports)

        # Number the requirements
        for c, req_dict in enumerate(self.__requirements.values(), start=1):
            moosesqa.number_requirements(req_dict, c)

        # Report for the entire app (e.g, moose/modules/doc)
        general_reports = self.get('reports')
        if general_reports is not None:
            self.__reports['_empty_'] = moosesqa.get_sqa_reports(
                general_reports)

        # The following attempts to save computation time by avoiding re-computing the application
        # syntax for each report. This is done by extracting the syntax from the appsyntax extension
        # and using it within the SQAMooseAppReport objects.

        # Get the syntax tree and executable info from the appsyntax extension
        app_syntax = None
        exe_dir = None
        exe_name = None
        for ext in self.translator.extensions:
            if isinstance(ext, appsyntax.AppSyntaxExtension):
                app_syntax = ext.syntax
                exe_dir, exe_name = os.path.split(
                    ext.executable) if ext.executable else (None, None)
                break

        # Setup the SQAMooseAppReports to use the syntax from the running app
        for reports in self.__reports.values():
            for app_report in reports[2]:
                app_report.app_syntax = app_syntax
                app_report.exe_directory = exe_dir
                app_report.exe_name = exe_name.rsplit(
                    '-', maxsplit=1)[0] if exe_name else None
                if app_syntax is None:
                    msg = 'Attempting to inject application syntax into SQAMooseAppReport, but the syntax does not exist.'
                    LOG.warning(msg)

        # Set default collection and add RunException tests to FAILURE_ANALYSIS collection
        d_type = self['default_collection']
        for req_category in self.__requirements.values():
            for requirements in req_category.values():
                for req in requirements:
                    t_types = req.types
                    if (req.collections is
                            None) and (t_types is not None) and ('RunException'
                                                                 in t_types):
                        req.collections = set([d_type, 'FAILURE_ANALYSIS'])
                    elif (req.collections is None):
                        req.collections = set([d_type])

        LOG.info("Gathering SQA requirement information complete [%s sec.]",
                 time.time() - start)
Exemplo n.º 3
0
    def testRequirementWithDetails(self):
        loc = [os.getcwd()]
        req = get_requirements_from_tests(loc, ['test_get_requirements_spec0'])

        self.assertEqual(len(req), 1)
        self.assertEqual(len(req['test_get_requirements_spec0']), 19)

        r = req['test_get_requirements_spec0'][0]
        self.assertEqual(r.issues, ['#1234'])
        self.assertEqual(r.design, ['core.md'])
        self.assertEqual(r.requirement, "Requirement One")

        r = req['test_get_requirements_spec0'][1]
        self.assertEqual(r.issues, ['#3456'])
        self.assertEqual(r.design, ['core.md'])
        self.assertEqual(r.requirement, "Requirement Two")

        r = req['test_get_requirements_spec0'][2]
        self.assertEqual(r.issues, ['#1234'])
        self.assertEqual(r.design, ['bibtex.md'])
        self.assertEqual(r.requirement, "Requirement Three")

        r = req['test_get_requirements_spec0'][3]
        self.assertEqual(r.issues, ['#4567'])
        self.assertEqual(r.design, ['katex.md'])
        self.assertEqual(r.requirement, "Requirement Four")

        r = req['test_get_requirements_spec0'][4]
        self.assertEqual(r.issues, ['#1234'])
        self.assertEqual(r.design, ['core.md'])
        self.assertEqual(r.requirement, "Requirement Group One")
        self.assertEqual(len(r.details), 2)

        d = r.details[0]
        self.assertEqual(d.name, 'group0-a')
        self.assertEqual(d.detail, '1D')
        self.assertEqual(d.detail_line, 27)

        d = r.details[1]
        self.assertEqual(d.name, 'group0-b')
        self.assertEqual(d.detail, '2D')
        self.assertEqual(d.detail_line, 30)

        r = req['test_get_requirements_spec0'][5]
        self.assertEqual(r.issues, ['#8910'])
        self.assertEqual(r.design, ['core.md'])
        self.assertEqual(r.requirement, "Requirement Group Two")
        self.assertEqual(len(r.details), 2)

        d = r.details[0]
        self.assertEqual(d.name, 'group1-a')
        self.assertEqual(d.detail, '3D')
        self.assertEqual(d.detail_line, 38)

        d = r.details[1]
        self.assertEqual(d.name, 'group1-b')
        self.assertEqual(d.detail, '4D')
        self.assertEqual(d.detail_line, 41)

        r = req['test_get_requirements_spec0'][6]
        self.assertEqual(r.issues, ['#1234'])
        self.assertEqual(r.design, ['bibtex.md'])
        self.assertEqual(r.requirement, "Requirement Group Three")
        self.assertEqual(len(r.details), 2)

        d = r.details[0]
        self.assertEqual(d.name, 'group2-a')
        self.assertEqual(d.detail, '5D')
        self.assertEqual(d.detail_line, 50)

        d = r.details[1]
        self.assertEqual(d.name, 'group2-b')
        self.assertEqual(d.detail, '6D')
        self.assertEqual(d.detail_line, 53)

        r = req['test_get_requirements_spec0'][7]
        self.assertEqual(r.issues, ['#4321'])
        self.assertEqual(r.design, ['katex.md'])
        self.assertEqual(r.requirement, "Requirement Group Four")
        self.assertEqual(len(r.details), 2)

        d = r.details[0]
        self.assertEqual(d.name, 'group3-a')
        self.assertEqual(d.detail, '7D')
        self.assertEqual(d.detail_line, 62)

        d = r.details[1]
        self.assertEqual(d.name, 'group3-b')
        self.assertEqual(d.detail, '8D')
        self.assertEqual(d.detail_line, 65)

        # collections_default
        r = req['test_get_requirements_spec0'][9]
        self.assertIsNone(r.collections)

        # collections_override
        r = req['test_get_requirements_spec0'][10]
        self.assertEqual(r.collections, {'A'})

        # collections_group
        r = req['test_get_requirements_spec0'][11]
        self.assertEqual(r.collections, {'A', 'B'})

        # types
        r = req['test_get_requirements_spec0'][12]
        self.assertEqual(r.types, {'A'})

        # types_group
        r = req['test_get_requirements_spec0'][13]
        self.assertEqual(r.types, {'A', 'B'})

        # names
        r = req['test_get_requirements_spec0'][14]
        self.assertEqual(r.names, {'names'})

        # names_group
        r = req['test_get_requirements_spec0'][15]
        self.assertEqual(r.names, {'names_group/a', 'names_group/b'})

        # prereq_first
        r = req['test_get_requirements_spec0'][16]
        self.assertEqual(r.prerequisites, set())

        # prereq_first
        r = req['test_get_requirements_spec0'][17]
        self.assertEqual(r.prerequisites, {'prereq_first'})

        # prereq_group
        r = req['test_get_requirements_spec0'][18]
        self.assertEqual(r.prerequisites, {'prereq_first', 'prereq_group/a'})