def test_get_unit_info(self, tmp_path): database = SqliteStateDatabase(tmp_path) test_unit = FortranWorkingState(database) test_unit.add_fortran_program_unit( FortranUnitID('foo', tmp_path / 'foo.f90')) test_unit.add_fortran_program_unit( FortranUnitID('bar', tmp_path / 'bar.F90')) test_unit.add_fortran_program_unit( FortranUnitID('bar', tmp_path / 'brb.f90')) test_unit.add_fortran_program_unit( FortranUnitID('baz', tmp_path / 'baz.f90')) test_unit.add_fortran_dependency( FortranUnitID('bar', tmp_path / 'brb.f90'), 'foo') test_unit.add_fortran_dependency( FortranUnitID('baz', tmp_path / 'baz.f90'), 'foo') test_unit.add_fortran_dependency( FortranUnitID('baz', tmp_path / 'baz.f90'), 'bar') assert test_unit.get_program_unit('foo') \ == [FortranInfo(FortranUnitID('foo', tmp_path/'foo.f90'))] assert test_unit.get_program_unit('bar') \ == [FortranInfo(FortranUnitID('bar', tmp_path/'bar.F90')), FortranInfo(FortranUnitID('bar', tmp_path/'brb.f90'), ['foo'])] assert test_unit.get_program_unit('baz') \ == [FortranInfo(FortranUnitID('baz', tmp_path/'baz.f90'), ['bar', 'foo'])]
def test_get_program_unit(self, tmp_path: Path): database = SqliteStateDatabase(tmp_path) test_unit = FortranWorkingState(database) # Test on an empty list # with pytest.raises(WorkingStateException): _ = test_unit.get_program_unit('tigger') # Test we can retrieve an item from a single element list test_unit.add_fortran_program_unit( FortranUnitID('tigger', Path('tigger.f90'))) assert test_unit.get_program_unit('tigger') \ == [FortranInfo(FortranUnitID('tigger', Path('tigger.f90')))] with pytest.raises(WorkingStateException): _ = test_unit.get_program_unit('eeor') # Test retrieval from a multi-element list and with prerequisites. # test_unit.add_fortran_program_unit( FortranUnitID('eeor', Path('eeor.f90'))) test_unit.add_fortran_dependency( FortranUnitID('eeor', Path('eeor.f90')), 'pooh') test_unit.add_fortran_dependency( FortranUnitID('eeor', Path('eeor.f90')), 'piglet') assert test_unit.get_program_unit('tigger') \ == [FortranInfo(FortranUnitID('tigger', Path('tigger.f90')))] assert test_unit.get_program_unit('eeor') \ == [FortranInfo(FortranUnitID('eeor', Path('eeor.f90')), ['piglet', 'pooh'])] with pytest.raises(WorkingStateException): _ = test_unit.get_program_unit('pooh') # Test a multiply defined program unit. # test_unit.add_fortran_program_unit( FortranUnitID('tigger', Path('hundred.f90'))) assert test_unit.get_program_unit('tigger') \ == [FortranInfo(FortranUnitID('tigger', Path('hundred.f90'))), FortranInfo(FortranUnitID('tigger', Path('tigger.f90')))] assert test_unit.get_program_unit('eeor') \ == [FortranInfo(FortranUnitID('eeor', Path('eeor.f90')), ['piglet', 'pooh'])] with pytest.raises(WorkingStateException): _ = test_unit.get_program_unit('pooh')
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')]