diff --git a/tests/system_tests/CFortranInterop/test_CFortranInterop.py b/tests/system_tests/CFortranInterop/test_CFortranInterop.py index 5e7b9067..483b6968 100644 --- a/tests/system_tests/CFortranInterop/test_CFortranInterop.py +++ b/tests/system_tests/CFortranInterop/test_CFortranInterop.py @@ -17,6 +17,7 @@ from fab.steps.link import link_exe from fab.steps.preprocess import preprocess_fortran, preprocess_c +import pytest PROJECT_SOURCE = Path(__file__).parent / 'project-source' @@ -24,7 +25,8 @@ def test_CFortranInterop(tmp_path): # build - with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config: + with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config, \ + pytest.warns(UserWarning, match="removing managed flag"): grab_folder(config, src=PROJECT_SOURCE), find_source_files(config), diff --git a/tests/system_tests/FortranDependencies/test_FortranDependencies.py b/tests/system_tests/FortranDependencies/test_FortranDependencies.py index 48932b5c..6971bf83 100644 --- a/tests/system_tests/FortranDependencies/test_FortranDependencies.py +++ b/tests/system_tests/FortranDependencies/test_FortranDependencies.py @@ -17,11 +17,14 @@ from fab.steps.link import link_exe from fab.steps.preprocess import preprocess_fortran +import pytest + def test_FortranDependencies(tmp_path): # build - with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config: + with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config, \ + pytest.warns(UserWarning, match="removing managed flag"): grab_folder(config, src=Path(__file__).parent / 'project-source'), find_source_files(config), preprocess_fortran(config), # nothing to preprocess, actually, it's all little f90 files diff --git a/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py b/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py index 49652641..f45ea74c 100644 --- a/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py +++ b/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py @@ -15,9 +15,12 @@ from fab.steps.link import link_exe from fab.steps.preprocess import preprocess_fortran +import pytest + def build(fab_workspace, fpp_flags=None): - with BuildConfig(fab_workspace=fab_workspace, project_label='foo', multiprocessing=False) as config: + with BuildConfig(fab_workspace=fab_workspace, project_label='foo', multiprocessing=False) as config, \ + pytest.warns(UserWarning, match="removing managed flag"): grab_folder(config, Path(__file__).parent / 'project-source'), find_source_files(config), preprocess_fortran(config, common_flags=fpp_flags), diff --git a/tests/system_tests/MinimalFortran/test_MinimalFortran.py b/tests/system_tests/MinimalFortran/test_MinimalFortran.py index 66fb221a..6dd7615f 100644 --- a/tests/system_tests/MinimalFortran/test_MinimalFortran.py +++ b/tests/system_tests/MinimalFortran/test_MinimalFortran.py @@ -15,13 +15,16 @@ from fab.steps.link import link_exe from fab.steps.preprocess import preprocess_fortran +import pytest + PROJECT_SOURCE = Path(__file__).parent / 'project-source' def test_MinimalFortran(tmp_path): # build - with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config: + with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config, \ + pytest.warns(UserWarning, match="removing managed flag"): grab_folder(config, PROJECT_SOURCE), find_source_files(config), preprocess_fortran(config), diff --git a/tests/system_tests/git/test_git.py b/tests/system_tests/git/test_git.py index dabbc137..32895dfe 100644 --- a/tests/system_tests/git/test_git.py +++ b/tests/system_tests/git/test_git.py @@ -38,21 +38,25 @@ def url(self): return 'https://github.com/metomi/fab-test-data.git' def test_checkout_url(self, tmp_path, url, config): - git_checkout(config, src=url, dst_label='tiny_fortran') - # todo: The commit will keep changing. Perhaps make a non-changing branch - assert current_commit(config.source_root / 'tiny_fortran') == '3cba55e' + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + git_checkout(config, src=url, dst_label='tiny_fortran') + # todo: The commit will keep changing. Perhaps make a non-changing branch + assert current_commit(config.source_root / 'tiny_fortran') == '3cba55e' def test_checkout_branch(self, tmp_path, url, config): - git_checkout(config, src=url, dst_label='tiny_fortran', revision='main') - assert current_commit(config.source_root / 'tiny_fortran') == '3cba55e' + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + git_checkout(config, src=url, dst_label='tiny_fortran', revision='main') + assert current_commit(config.source_root / 'tiny_fortran') == '3cba55e' def test_checkout_tag(self, tmp_path, url, config): - git_checkout(config, src=url, dst_label='tiny_fortran', revision='early') - assert current_commit(config.source_root / 'tiny_fortran') == 'ee56489' + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + git_checkout(config, src=url, dst_label='tiny_fortran', revision='early') + assert current_commit(config.source_root / 'tiny_fortran') == 'ee56489' def test_checkout_commit(self, tmp_path, url, config): - git_checkout(config, src=url, dst_label='tiny_fortran', revision='ee5648928893701c5dbccdbf0561c0038352a5ff') - assert current_commit(config.source_root / 'tiny_fortran') == 'ee56489' + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + git_checkout(config, src=url, dst_label='tiny_fortran', revision='ee5648928893701c5dbccdbf0561c0038352a5ff') + assert current_commit(config.source_root / 'tiny_fortran') == 'ee56489' # todo: we could do with a test to ensure left-over files from previous fetches are cleaned away @@ -65,18 +69,25 @@ def repo_url(self, tmp_path): shutil.unpack_archive(Path(__file__).parent / 'repo.tar.gz', tmp_path) return f'file://{tmp_path}/repo' + @pytest.mark.filterwarnings("ignore: Python 3.14 will, " + "by default, filter extracted tar archives " + "and reject files or modify their metadata. " + "Use the filter argument to control this behavior.") def test_vanilla(self, repo_url, config): # checkout master - git_checkout(config, src=repo_url, dst_label='tiny_fortran', revision='master') - check_file = config.source_root / 'tiny_fortran/file1.txt' - assert 'This is sentence one in file one.' in open(check_file).read() + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + git_checkout(config, src=repo_url, dst_label='tiny_fortran', revision='master') + check_file = config.source_root / 'tiny_fortran/file1.txt' + assert 'This is sentence one in file one.' in open(check_file).read() - git_merge(config, src=repo_url, dst_label='tiny_fortran', revision='experiment_a') - assert 'This is sentence one, with Experiment A modification.' in open(check_file).read() + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + git_merge(config, src=repo_url, dst_label='tiny_fortran', revision='experiment_a') + assert 'This is sentence one, with Experiment A modification.' in open(check_file).read() with pytest.raises(RuntimeError): git_merge(config, src=repo_url, dst_label='tiny_fortran', revision='experiment_b') # The conflicted merge must have been aborted, check that we can do another checkout of master - git_checkout(config, src=repo_url, dst_label='tiny_fortran', revision='master') + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + git_checkout(config, src=repo_url, dst_label='tiny_fortran', revision='master') diff --git a/tests/system_tests/grab_archive/test_grab_archive.py b/tests/system_tests/grab_archive/test_grab_archive.py index 73d7543e..aa4251ea 100644 --- a/tests/system_tests/grab_archive/test_grab_archive.py +++ b/tests/system_tests/grab_archive/test_grab_archive.py @@ -8,11 +8,14 @@ from fab.steps.grab.archive import grab_archive +import pytest + class TestGrabArchive(object): def test(self, tmp_path): - tar_file = Path(__file__).parent / '../git/tiny_fortran.tar' - grab_archive(config=mock.Mock(source_root=tmp_path), src=tar_file) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + tar_file = Path(__file__).parent / '../git/tiny_fortran.tar' + grab_archive(config=mock.Mock(source_root=tmp_path), src=tar_file) - assert (tmp_path / 'tiny_fortran/src/my_mod.F90').exists() + assert (tmp_path / 'tiny_fortran/src/my_mod.F90').exists() diff --git a/tests/system_tests/psyclone/test_psyclone_system_test.py b/tests/system_tests/psyclone/test_psyclone_system_test.py index b033573d..20cd7761 100644 --- a/tests/system_tests/psyclone/test_psyclone_system_test.py +++ b/tests/system_tests/psyclone/test_psyclone_system_test.py @@ -173,20 +173,20 @@ def test_run(self, config): # So use a list instead: assert all(list(config.prebuild_folder.glob(f)) == [] for f in expect_prebuild_files) assert all(list(config.build_output.glob(f)) == [] for f in expect_build_files) - with config: + with config, pytest.warns(UserWarning, match="no transformation script specified"): self.steps(config) assert all(list(config.prebuild_folder.glob(f)) != [] for f in expect_prebuild_files) assert all(list(config.build_output.glob(f)) != [] for f in expect_build_files) def test_prebuild(self, tmp_path, config): - with config: + with config, pytest.warns(UserWarning, match="no transformation script specified"): self.steps(config) # make sure no work gets done the second time round with mock.patch('fab.parse.x90.X90Analyser.walk_nodes') as mock_x90_walk: with mock.patch('fab.parse.fortran.FortranAnalyser.walk_nodes') as mock_fortran_walk: with mock.patch('fab.steps.psyclone.run_psyclone') as mock_run: - with config: + with config, pytest.warns(UserWarning, match="no transformation script specified"): self.steps(config) mock_x90_walk.assert_not_called() diff --git a/tests/system_tests/svn_fcm/test_svn_fcm_system_test.py b/tests/system_tests/svn_fcm/test_svn_fcm_system_test.py index 532c5cac..da2de348 100644 --- a/tests/system_tests/svn_fcm/test_svn_fcm_system_test.py +++ b/tests/system_tests/svn_fcm/test_svn_fcm_system_test.py @@ -110,23 +110,34 @@ class TestExport(object): # Run the test twice, once with SvnExport and once with FcmExport - depending on which tools are available. @pytest.mark.parametrize('export_func', export_funcs) + @pytest.mark.filterwarnings("ignore: Python 3.14 will, " + "by default, filter extracted tar archives " + "and reject files or modify their metadata. " + "Use the filter argument to control this behavior.") def test_export(self, file2_experiment, config, export_func): # Export the "file 2 experiment" branch, which has different sentence from trunk in r1 and r2 - export_func(config, src=file2_experiment, dst_label='proj', revision=7) - assert confirm_file2_experiment_r7(config) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + export_func(config, src=file2_experiment, dst_label='proj', revision=7) + assert confirm_file2_experiment_r7(config) # Make sure we can export twice into the same folder. # Todo: should the export step wipe the destination first? To remove residual, orphaned files? - export_func(config, src=file2_experiment, dst_label='proj', revision=8) - assert confirm_file2_experiment_r8(config) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + export_func(config, src=file2_experiment, dst_label='proj', revision=8) + assert confirm_file2_experiment_r8(config) +@pytest.mark.filterwarnings("ignore: Python 3.14 will, " + "by default, filter extracted tar archives " + "and reject files or modify their metadata. " + "Use the filter argument to control this behavior.") class TestCheckout(object): @pytest.mark.parametrize('checkout_func', checkout_funcs) def test_new_folder(self, trunk, config, checkout_func): - checkout_func(config, src=trunk, dst_label='proj') - assert confirm_trunk(config) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + checkout_func(config, src=trunk, dst_label='proj') + assert confirm_trunk(config) @pytest.mark.parametrize('checkout_func', checkout_funcs) def test_working_copy(self, file2_experiment, config, checkout_func): @@ -143,7 +154,8 @@ def test_working_copy(self, file2_experiment, config, checkout_func): else: assert False - with mock.patch('fab.steps.grab.svn.run_command', wraps=fab.steps.grab.svn.run_command) as wrap: + with mock.patch('fab.steps.grab.svn.run_command', wraps=fab.steps.grab.svn.run_command) as wrap, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): checkout_func(config, src=file2_experiment, dst_label='proj', revision='7') assert confirm_file2_experiment_r7(config) @@ -160,38 +172,46 @@ def test_working_copy(self, file2_experiment, config, checkout_func): @pytest.mark.parametrize('export_func,checkout_func', zip(export_funcs, checkout_funcs)) def test_not_working_copy(self, trunk, config, export_func, checkout_func): # the export command just makes files, not a working copy - export_func(config, src=trunk, dst_label='proj') + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + export_func(config, src=trunk, dst_label='proj') # if we try to checkout into that folder, it should fail with pytest.raises(ValueError): checkout_func(config, src=trunk, dst_label='proj') +@pytest.mark.filterwarnings("ignore: Python 3.14 will, " + "by default, filter extracted tar archives " + "and reject files or modify their metadata. " + "Use the filter argument to control this behavior.") class TestMerge(object): @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs)) def test_vanilla(self, trunk, file2_experiment, config, checkout_func, merge_func): - # something to merge into; checkout trunk - checkout_func(config, src=trunk, dst_label='proj') - confirm_trunk(config) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + # something to merge into; checkout trunk + checkout_func(config, src=trunk, dst_label='proj') + confirm_trunk(config) - # merge another branch in - merge_func(config, src=file2_experiment, dst_label='proj') - confirm_file2_experiment_r8(config) + # merge another branch in + merge_func(config, src=file2_experiment, dst_label='proj') + confirm_file2_experiment_r8(config) @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs)) def test_revision(self, trunk, file2_experiment, config, checkout_func, merge_func): - # something to merge into; checkout trunk - checkout_func(config, src=trunk, dst_label='proj') - confirm_trunk(config) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + # something to merge into; checkout trunk + checkout_func(config, src=trunk, dst_label='proj') + confirm_trunk(config) - # merge another branch in - merge_func(config, src=file2_experiment, dst_label='proj', revision=7) - confirm_file2_experiment_r7(config) + # merge another branch in + merge_func(config, src=file2_experiment, dst_label='proj', revision=7) + confirm_file2_experiment_r7(config) @pytest.mark.parametrize('export_func,merge_func', zip(export_funcs, merge_funcs)) def test_not_working_copy(self, trunk, file2_experiment, config, export_func, merge_func): - export_func(config, src=trunk, dst_label='proj') + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + export_func(config, src=trunk, dst_label='proj') # try to merge into an export with pytest.raises(ValueError): @@ -199,8 +219,9 @@ def test_not_working_copy(self, trunk, file2_experiment, config, export_func, me @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs)) def test_conflict(self, file1_experiment_a, file1_experiment_b, config, checkout_func, merge_func): - checkout_func(config, src=file1_experiment_a, dst_label='proj') - confirm_file1_experiment_a(config) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + checkout_func(config, src=file1_experiment_a, dst_label='proj') + confirm_file1_experiment_a(config) # this branch modifies the same line of text with pytest.raises(RuntimeError): @@ -208,11 +229,12 @@ def test_conflict(self, file1_experiment_a, file1_experiment_b, config, checkout @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs)) def test_multiple_merges(self, trunk, file1_experiment_a, file2_experiment, config, checkout_func, merge_func): - checkout_func(config, src=trunk, dst_label='proj') - confirm_trunk(config) + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + checkout_func(config, src=trunk, dst_label='proj') + confirm_trunk(config) - merge_func(config, src=file1_experiment_a, dst_label='proj') - confirm_file1_experiment_a(config) + merge_func(config, src=file1_experiment_a, dst_label='proj') + confirm_file1_experiment_a(config) - merge_func(config, src=file2_experiment, dst_label='proj', revision=7) - confirm_file2_experiment_r7(config) + merge_func(config, src=file2_experiment, dst_label='proj', revision=7) + confirm_file2_experiment_r7(config) diff --git a/tests/system_tests/zero_config/test_zero_config.py b/tests/system_tests/zero_config/test_zero_config.py index 704c0b93..5ae56b3d 100644 --- a/tests/system_tests/zero_config/test_zero_config.py +++ b/tests/system_tests/zero_config/test_zero_config.py @@ -5,29 +5,33 @@ import os from unittest import mock +import pytest + class TestZeroConfig(object): def test_fortran_dependencies(self, tmp_path): # test the sample project in the fortran dependencies system test - kwargs = {'project_label': 'fortran deps test', 'fab_workspace': tmp_path, 'multiprocessing': False} + with pytest.warns(DeprecationWarning, match="RootIncFiles is deprecated as .inc files are due to be removed."): + kwargs = {'project_label': 'fortran deps test', 'fab_workspace': tmp_path, 'multiprocessing': False} - config = cli_fab( - folder=Path(__file__).parent.parent / 'FortranDependencies', - kwargs=kwargs) + config = cli_fab( + folder=Path(__file__).parent.parent / 'FortranDependencies', + kwargs=kwargs) - assert (config.project_workspace / 'first').exists() - assert (config.project_workspace / 'second').exists() + assert (config.project_workspace / 'first').exists() + assert (config.project_workspace / 'second').exists() def test_c_fortran_interop(self, tmp_path): # test the sample project in the fortran dependencies system test - kwargs = {'project_label': 'CFInterop test', 'fab_workspace': tmp_path, 'multiprocessing': 'False'} + with pytest.warns(DeprecationWarning, match="RootIncFiles is deprecated as .inc files are due to be removed."): + kwargs = {'project_label': 'CFInterop test', 'fab_workspace': tmp_path, 'multiprocessing': 'False'} - config = cli_fab( - folder=Path(__file__).parent.parent / 'CFortranInterop', - kwargs=kwargs) + config = cli_fab( + folder=Path(__file__).parent.parent / 'CFortranInterop', + kwargs=kwargs) - assert (config.project_workspace / 'main').exists() + assert (config.project_workspace / 'main').exists() def test_fortran_explicit_gfortran(self, tmp_path): # test the sample project in the fortran dependencies system test @@ -36,7 +40,8 @@ def test_fortran_explicit_gfortran(self, tmp_path): cc = shutil.which('gcc') fc = shutil.which('gfortran') - with mock.patch.dict(os.environ, CC=cc, FC=fc, LD=fc): + with mock.patch.dict(os.environ, CC=cc, FC=fc, LD=fc), \ + pytest.warns(DeprecationWarning, match="RootIncFiles is deprecated as .inc files are due to be removed."): config = cli_fab( folder=Path(__file__).parent.parent / 'CFortranInterop', kwargs=kwargs) diff --git a/tests/unit_tests/steps/test_analyse.py b/tests/unit_tests/steps/test_analyse.py index 7405939c..0e1db71b 100644 --- a/tests/unit_tests/steps/test_analyse.py +++ b/tests/unit_tests/steps/test_analyse.py @@ -115,7 +115,10 @@ class Test_parse_files(object): def test_exceptions(self, tmp_path): # make sure parse exceptions do not stop the build - with mock.patch('fab.steps.run_mp', return_value=[(Exception('foo'), None)]): + with mock.patch('fab.steps.run_mp', return_value=[(Exception('foo'), None)]), \ + pytest.warns(UserWarning, match="deprecated 'DEPENDS ON:'"): + # The warning "deprecated 'DEPENDS ON:' comment found in fortran code" + # is in "def _parse_files" in "source/steps/analyse.py" config = BuildConfig('proj', fab_workspace=tmp_path) # the exception should be suppressed (and logged) and this step should run to completion @@ -130,7 +133,10 @@ def test_vanilla(self): workaround = FortranParserWorkaround(fpath=Path('foo.f'), symbol_defs={'foo', }) analysed_files = set() - with mock.patch('fab.parse.fortran.file_checksum', return_value=HashedFile(None, 123)): + with mock.patch('fab.parse.fortran.file_checksum', return_value=HashedFile(None, 123)), \ + pytest.warns(UserWarning, match="SPECIAL MEASURE: injecting user-defined analysis results"): + # This warning "UserWarning: SPECIAL MEASURE: injecting user-defined analysis results" + # is in "def _add_manual_results" in "source/steps/analyse.py" _add_manual_results(special_measure_analysis_results=[workaround], analysed_files=analysed_files) assert analysed_files == {AnalysedFortran(fpath=Path('foo.f'), file_hash=123, symbol_defs={'foo', })} diff --git a/tests/unit_tests/steps/test_archive_objects.py b/tests/unit_tests/steps/test_archive_objects.py index 2d7ab1bb..0600d85c 100644 --- a/tests/unit_tests/steps/test_archive_objects.py +++ b/tests/unit_tests/steps/test_archive_objects.py @@ -5,6 +5,8 @@ from fab.constants import OBJECT_FILES, OBJECT_ARCHIVES from fab.steps.archive_objects import archive_objects +import pytest + class Test_archive_objects(object): @@ -15,7 +17,8 @@ def test_for_exes(self): config = BuildConfig('proj') config._artefact_store = {OBJECT_FILES: {target: [f'{target}.o', 'util.o'] for target in targets}} - with mock.patch('fab.steps.archive_objects.run_command') as mock_run_command: + with mock.patch('fab.steps.archive_objects.run_command') as mock_run_command, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): archive_objects(config=config) # ensure the correct command line calls were made @@ -36,7 +39,8 @@ def test_for_library(self): config = BuildConfig('proj') config._artefact_store = {OBJECT_FILES: {None: ['util1.o', 'util2.o']}} - with mock.patch('fab.steps.archive_objects.run_command') as mock_run_command: + with mock.patch('fab.steps.archive_objects.run_command') as mock_run_command, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): archive_objects(config=config, output_fpath=config.build_output / 'mylib.a') # ensure the correct command line calls were made diff --git a/tests/unit_tests/steps/test_cleanup_prebuilds.py b/tests/unit_tests/steps/test_cleanup_prebuilds.py index 21cddb63..ec15acc7 100644 --- a/tests/unit_tests/steps/test_cleanup_prebuilds.py +++ b/tests/unit_tests/steps/test_cleanup_prebuilds.py @@ -18,7 +18,8 @@ class TestCleanupPrebuilds(object): def test_init_no_args(self): - with mock.patch('fab.steps.cleanup_prebuilds.file_walk', return_value=[Path('foo.o')]): + with mock.patch('fab.steps.cleanup_prebuilds.file_walk', return_value=[Path('foo.o')]), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): with mock.patch('fab.steps.cleanup_prebuilds.remove_all_unused') as mock_remove_all_unused: cleanup_prebuilds(config=mock.Mock(_artefact_store={CURRENT_PREBUILDS: [Path('bar.o')]})) mock_remove_all_unused.assert_called_once_with(found_files=[Path('foo.o')], current_files=[Path('bar.o')]) diff --git a/tests/unit_tests/steps/test_compile_c.py b/tests/unit_tests/steps/test_compile_c.py index 9855f3d7..13f20223 100644 --- a/tests/unit_tests/steps/test_compile_c.py +++ b/tests/unit_tests/steps/test_compile_c.py @@ -36,7 +36,8 @@ def test_vanilla(self, content): send_metric=DEFAULT, get_compiler_version=mock.Mock(return_value='1.2.3')) as values: with mock.patch('pathlib.Path.mkdir'): - with mock.patch.dict(os.environ, {'CC': 'foo_cc', 'CFLAGS': '-Denv_flag'}): + with mock.patch.dict(os.environ, {'CC': 'foo_cc', 'CFLAGS': '-Denv_flag'}), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): compile_c( config=config, path_flags=[AddFlags(match='$source/*', flags=['-I', 'foo/include', '-Dhello'])]) diff --git a/tests/unit_tests/steps/test_compile_fortran.py b/tests/unit_tests/steps/test_compile_fortran.py index a2a0c3cd..7f42662a 100644 --- a/tests/unit_tests/steps/test_compile_fortran.py +++ b/tests/unit_tests/steps/test_compile_fortran.py @@ -182,7 +182,8 @@ def test_without_prebuild(self): with mock.patch('pathlib.Path.exists', return_value=False): # no output files exist with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) # check we got the expected compilation result @@ -210,7 +211,8 @@ def test_with_prebuild(self): with mock.patch('pathlib.Path.exists', return_value=True): # mod def files and obj file all exist with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -238,7 +240,8 @@ def test_file_hash(self): with mock.patch('pathlib.Path.exists', side_effect=[True, True, False]): # mod files exist, obj file doesn't with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -262,7 +265,8 @@ def test_flags_hash(self): with mock.patch('pathlib.Path.exists', side_effect=[True, True, False]): # mod files exist, obj file doesn't with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -290,7 +294,8 @@ def test_deps_hash(self): with mock.patch('pathlib.Path.exists', side_effect=[True, True, False]): # mod files exist, obj file doesn't with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -317,7 +322,8 @@ def test_compiler_hash(self): with mock.patch('pathlib.Path.exists', side_effect=[True, True, False]): # mod files exist, obj file doesn't with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -344,7 +350,8 @@ def test_compiler_version_hash(self): with mock.patch('pathlib.Path.exists', side_effect=[True, True, False]): # mod files exist, obj file doesn't with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -367,7 +374,8 @@ def test_mod_missing(self): with mock.patch('pathlib.Path.exists', side_effect=[False, True, True]): # one mod file missing with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -390,7 +398,8 @@ def test_obj_missing(self): with mock.patch('pathlib.Path.exists', side_effect=[True, True, False]): # object file missing with mock.patch('fab.steps.compile_fortran.compile_file') as mock_compile_file: - with mock.patch('shutil.copy2') as mock_copy: + with mock.patch('shutil.copy2') as mock_copy, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): res, artefacts = process_file((analysed_file, mp_common_args)) expect_object_fpath = Path(f'/fab/proj/build_output/_prebuild/foofile.{obj_combo_hash}.o') @@ -426,14 +435,16 @@ def test_with_flags(self): def test_gfortran_managed_flags(self): with mock.patch.dict(os.environ, FC='gfortran -c', FFLAGS='-J /mods'): - with mock.patch('fab.steps.compile_fortran.get_compiler_version'): + with mock.patch('fab.steps.compile_fortran.get_compiler_version'), \ + pytest.warns(UserWarning, match="removing managed flag"): compiler, compiler_version, flags = handle_compiler_args() assert compiler == 'gfortran' assert flags.common_flags == [] def test_ifort_managed_flags(self): with mock.patch.dict(os.environ, FC='ifort -c', FFLAGS='-module /mods'): - with mock.patch('fab.steps.compile_fortran.get_compiler_version'): + with mock.patch('fab.steps.compile_fortran.get_compiler_version'), \ + pytest.warns(UserWarning, match="removing managed flag"): compiler, compiler_version, flags = handle_compiler_args() assert compiler == 'ifort' assert flags.common_flags == [] diff --git a/tests/unit_tests/steps/test_grab.py b/tests/unit_tests/steps/test_grab.py index 409b1fa9..57878b22 100644 --- a/tests/unit_tests/steps/test_grab.py +++ b/tests/unit_tests/steps/test_grab.py @@ -10,14 +10,18 @@ from fab.steps.grab.fcm import fcm_export from fab.steps.grab.folder import grab_folder +import pytest + class TestGrabFolder(object): def test_trailing_slash(self): - self._common(grab_src='/grab/source/', expect_grab_src='/grab/source/') + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + self._common(grab_src='/grab/source/', expect_grab_src='/grab/source/') def test_no_trailing_slash(self): - self._common(grab_src='/grab/source', expect_grab_src='/grab/source/') + with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + self._common(grab_src='/grab/source', expect_grab_src='/grab/source/') def _common(self, grab_src, expect_grab_src): source_root = Path('/workspace/source') @@ -41,7 +45,8 @@ def test_no_revision(self): mock_config = SimpleNamespace(source_root=source_root) with mock.patch('pathlib.Path.mkdir'): - with mock.patch('fab.steps.grab.svn.run_command') as mock_run: + with mock.patch('fab.steps.grab.svn.run_command') as mock_run, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): fcm_export(config=mock_config, src=source_url, dst_label=dst_label) mock_run.assert_called_once_with(['fcm', 'export', '--force', source_url, str(source_root / dst_label)]) @@ -54,7 +59,8 @@ def test_revision(self): mock_config = SimpleNamespace(source_root=source_root) with mock.patch('pathlib.Path.mkdir'): - with mock.patch('fab.steps.grab.svn.run_command') as mock_run: + with mock.patch('fab.steps.grab.svn.run_command') as mock_run, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): fcm_export(mock_config, src=source_url, dst_label=dst_label, revision=revision) mock_run.assert_called_once_with( diff --git a/tests/unit_tests/steps/test_link.py b/tests/unit_tests/steps/test_link.py index b7e3fd5e..cfee8f9a 100644 --- a/tests/unit_tests/steps/test_link.py +++ b/tests/unit_tests/steps/test_link.py @@ -10,6 +10,8 @@ from fab.constants import OBJECT_FILES from fab.steps.link import link_exe +import pytest + class TestLinkExe(object): def test_run(self): @@ -21,7 +23,8 @@ def test_run(self): ) with mock.patch('os.getenv', return_value='-L/foo1/lib -L/foo2/lib'): - with mock.patch('fab.steps.link.run_command') as mock_run: + with mock.patch('fab.steps.link.run_command') as mock_run, \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): link_exe(config, linker='foolink', flags=['-fooflag', '-barflag']) mock_run.assert_called_with([ diff --git a/tests/unit_tests/steps/test_root_inc_files.py b/tests/unit_tests/steps/test_root_inc_files.py index e3037cce..3bb55cee 100644 --- a/tests/unit_tests/steps/test_root_inc_files.py +++ b/tests/unit_tests/steps/test_root_inc_files.py @@ -17,7 +17,8 @@ def test_vanilla(self): config._artefact_store['all_source'] = inc_files with mock.patch('fab.steps.root_inc_files.shutil') as mock_shutil: - with mock.patch('fab.steps.root_inc_files.Path.mkdir'): + with mock.patch('fab.steps.root_inc_files.Path.mkdir'), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): root_inc_files(config) mock_shutil.copy.assert_called_once_with(inc_files[0], config.build_output) @@ -29,7 +30,8 @@ def test_skip_output_folder(self): config._artefact_store['all_source'] = inc_files with mock.patch('fab.steps.root_inc_files.shutil') as mock_shutil: - with mock.patch('fab.steps.root_inc_files.Path.mkdir'): + with mock.patch('fab.steps.root_inc_files.Path.mkdir'), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): root_inc_files(config) mock_shutil.copy.assert_called_once_with(inc_files[0], config.build_output) @@ -43,5 +45,7 @@ def test_name_clash(self): with pytest.raises(FileExistsError): with mock.patch('fab.steps.root_inc_files.shutil'): - with mock.patch('fab.steps.root_inc_files.Path.mkdir'): + with mock.patch('fab.steps.root_inc_files.Path.mkdir'), \ + pytest.warns(DeprecationWarning, + match="RootIncFiles is deprecated as .inc files are due to be removed."): root_inc_files(config) diff --git a/tests/unit_tests/test_tools.py b/tests/unit_tests/test_tools.py index 8edcb437..1898ff7f 100644 --- a/tests/unit_tests/test_tools.py +++ b/tests/unit_tests/test_tools.py @@ -15,12 +15,14 @@ class Test_remove_managed_flags(object): def test_gfortran(self): flags = ['--foo', '-J', 'nope', '--bar'] - result = remove_managed_flags('gfortran', flags) + with pytest.warns(UserWarning, match="removing managed flag"): + result = remove_managed_flags('gfortran', flags) assert result == ['--foo', '--bar'] def test_ifort(self): flags = ['--foo', '-module', 'nope', '--bar'] - result = remove_managed_flags('ifort', flags) + with pytest.warns(UserWarning, match="removing managed flag"): + result = remove_managed_flags('ifort', flags) assert result == ['--foo', '--bar'] def test_unknown_compiler(self):