Esempio n. 1
0
    def examine(self, subject: FortranSource) -> List[Issue]:
        issues = super(FortranRule, self).examine(subject)

        if not isinstance(subject, FortranSource):
            description = 'Non-Fortran source passed to a Fortran rule'
            raise Exception(description)

        if not subject.get_tree():
            description = "Unable to perform {} as source didn't parse: {}"
            issues.append(Issue(description.format(self.__class__.__name__,
                                                   subject.get_tree_error())))
            return issues

        issues.extend(self.examine_fortran(subject))
        return issues
    def test_constructor(self) -> None:
        """
        Checks that the source file is correctly parsed on construction.
        """
        inject = r"""! Test program
program test
  implicit none
  write(6, '("Hello ", A)') 'world'
end program test
"""
        reader = SourceStringReader(inject)
        unit_under_test = FortranSource(reader)
        assert unit_under_test.get_text() == inject

        expected_string = """! Test program
PROGRAM test
  IMPLICIT NONE
  WRITE(6, FMT = '("Hello ", A)') 'world'
END PROGRAM test"""
        assert str(unit_under_test.get_tree()) == expected_string
Esempio n. 3
0
    def test_constructor(self):
        '''
        Checks that the source file is correctly parsed on construction.
        '''
        # pylint: disable=no-self-use
        inject = r'''! Test program
program test
  implicit none
  write(6, '("Hello ", A)') 'world'
end program test
'''
        reader = SourceStringReader(inject)
        unit_under_test = FortranSource(reader)
        assert unit_under_test.get_text() == inject

        expected_string = '''! Test program
PROGRAM test
  IMPLICIT NONE
  WRITE(6, FMT = '("Hello ", A)') 'world'
END PROGRAM test'''
        assert str(unit_under_test.get_tree()) == expected_string
Esempio n. 4
0
    def examine(self, subject: FortranSource) -> List[Issue]:
        """
        Base for rules which scruitinise the parse tree of Fortran source.

        :param subject: Source file to examine.
        :return: Issues found with the source.
        """
        issues = []
        if not isinstance(subject, FortranSource):
            description = 'Non-Fortran source passed to a Fortran rule'
            raise Exception(description)

        if not subject.get_tree():
            description = "Unable to perform {} as source didn't parse: {}"
            issues.append(
                Issue(
                    description.format(self.__class__.__name__,
                                       subject.get_tree_error())))
            return issues

        issues.extend(self.examine_fortran(subject))
        return issues