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')