Exemplo n.º 1
0
    def test_harvested_data(self, caplog, tmp_path):
        """
        Checks that the analyser deals with rescanning a file.
        """
        caplog.set_level(logging.DEBUG)

        first_file: Path = tmp_path / 'other.F90'
        first_file.write_text(
            dedent('''
                   program betty
                     use barney_mod, only :: dino
                     implicit none
                   end program betty

                   module barney_mod
                   end module barney_mod
                   '''))
        second_file: Path = tmp_path / 'test.f90'
        second_file.write_text(
            dedent('''
                   module barney_mod
                   end module barney_mod
                   '''))

        database: SqliteStateDatabase = SqliteStateDatabase(tmp_path)
        test_unit = FortranAnalyser(tmp_path)
        first_artifact = Artifact(first_file, FortranSource, Raw)
        second_artifact = Artifact(second_file, FortranSource, Raw)
        # Not going to test returned objects this time
        _ = test_unit.run([first_artifact])
        _ = test_unit.run([second_artifact])

        # Confirm the database has been updated
        fdb = FortranWorkingState(database)
        assert list(iter(fdb)) \
            == [FortranInfo(FortranUnitID('barney_mod', first_file)),
                FortranInfo(FortranUnitID('barney_mod', second_file)),
                FortranInfo(FortranUnitID('betty', first_file),
                            ['barney_mod'])]
        assert list(fdb.depends_on(FortranUnitID('betty', first_file))) \
            == [FortranUnitID('barney_mod', tmp_path / 'other.F90'),
                FortranUnitID('barney_mod', tmp_path / 'test.f90')]

        # Repeat the scan of second_file, there should be no change.
        #
        _ = test_unit.run([second_artifact])

        fdb = FortranWorkingState(database)
        assert list(iter(fdb)) \
            == [FortranInfo(FortranUnitID('barney_mod', first_file)),
                FortranInfo(FortranUnitID('barney_mod', second_file)),
                FortranInfo(FortranUnitID('betty', first_file),
                            ['barney_mod'])]
        assert list(fdb.depends_on(FortranUnitID('betty', first_file))) \
            == [FortranUnitID('barney_mod', tmp_path / 'other.F90'),
                FortranUnitID('barney_mod', tmp_path / 'test.f90')]
Exemplo n.º 2
0
    def test_add_remove_sequence(self, tmp_path: Path):
        database = SqliteStateDatabase(tmp_path)
        test_unit = FortranWorkingState(database)
        assert list(iter(test_unit)) == []

        # Add a file containing a program unit and an unsatisfied dependency.
        #
        test_unit.add_fortran_program_unit(
            FortranUnitID('foo', Path('foo.f90')))
        test_unit.add_fortran_dependency(FortranUnitID('foo', Path('foo.f90')),
                                         'bar')
        assert list(iter(test_unit)) \
            == [FortranInfo(FortranUnitID('foo', Path('foo.f90')),
                            ['bar'])]
        assert list(test_unit.depends_on(FortranUnitID('foo',
                                                       Path('foo.f90')))) \
            == [FortranUnitUnresolvedID('bar')]

        # Add a second file containing a second program unit.
        #
        # This satisfies the previously dangling dependency and adds a new
        # one.
        #
        test_unit.add_fortran_program_unit(
            FortranUnitID('bar', Path('bar.F90')))
        test_unit.add_fortran_dependency(FortranUnitID('bar', Path('bar.F90')),
                                         'baz')
        assert list(iter(test_unit)) \
            == [FortranInfo(FortranUnitID('bar', Path('bar.F90')),
                            ['baz']),
                FortranInfo(FortranUnitID('foo', Path('foo.f90')),
                            ['bar'])]
        assert list(test_unit.depends_on(FortranUnitID('foo',
                                                       Path('foo.f90')))) \
            == [FortranUnitID('bar', Path('bar.F90'))]
        assert list(test_unit.depends_on(FortranUnitID('bar',
                                                       Path('bar.F90')))) \
            == [FortranUnitUnresolvedID('baz')]

        # Add a third file also containing a third program unit and another
        # copy of the first.
        #
        # The new unit depends on two other units.
        #
        test_unit.add_fortran_program_unit(
            FortranUnitID('baz', Path('baz.F90')))
        test_unit.add_fortran_program_unit(
            FortranUnitID('foo', Path('baz.F90')))
        test_unit.add_fortran_dependency(FortranUnitID('baz', Path('baz.F90')),
                                         'qux')
        test_unit.add_fortran_dependency(FortranUnitID('baz', Path('baz.F90')),
                                         'cheese')
        assert list(iter(test_unit)) \
            == [FortranInfo(FortranUnitID('bar', Path('bar.F90')),
                            ['baz']),
                FortranInfo(FortranUnitID('baz', Path('baz.F90')),
                            ['cheese', 'qux']),
                FortranInfo(FortranUnitID('foo', Path('baz.F90'))),
                FortranInfo(FortranUnitID('foo', Path('foo.f90')),
                            ['bar'])]
        assert list(test_unit.depends_on(FortranUnitID('foo',
                                                       Path('foo.f90')))) \
            == [FortranUnitID('bar', Path('bar.F90'))]
        assert list(test_unit.depends_on(FortranUnitID('foo',
                                                       Path('baz.F90')))) \
            == []
        assert list(test_unit.depends_on(FortranUnitID('bar',
                                                       Path('bar.F90')))) \
            == [FortranUnitID('baz', Path('baz.F90'))]
        assert list(test_unit.depends_on(FortranUnitID('baz',
                                                       Path('baz.F90')))) \
            == [FortranUnitUnresolvedID('qux'),
                FortranUnitUnresolvedID('cheese')]

        # Remove a previously added file
        #
        test_unit.remove_fortran_file(Path('baz.F90'))
        assert list(iter(test_unit)) \
            == [FortranInfo(FortranUnitID('bar', Path('bar.F90')),
                            ['baz']),
                FortranInfo(FortranUnitID('foo', Path('foo.f90')),
                            ['bar'])]
        assert list(test_unit.depends_on(FortranUnitID('foo',
                                                       Path('foo.f90')))) \
            == [FortranUnitID('bar', Path('bar.F90'))]
        assert list(test_unit.depends_on(FortranUnitID('bar',
                                                       Path('bar.F90')))) \
            == [FortranUnitUnresolvedID('baz')]