From 378b47f4b2867a56a17c492400ab153982636f5c Mon Sep 17 00:00:00 2001 From: Junwei Lyu Date: Fri, 1 Mar 2024 17:01:01 +1100 Subject: [PATCH 1/6] Fixed errors in the psyclone system tests - Issue #4 --- .../psyclone/skeleton/algorithm/algorithm_mod.x90 | 2 +- tests/system_tests/psyclone/test_psyclone.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/system_tests/psyclone/skeleton/algorithm/algorithm_mod.x90 b/tests/system_tests/psyclone/skeleton/algorithm/algorithm_mod.x90 index 62b412bf..be898fb0 100644 --- a/tests/system_tests/psyclone/skeleton/algorithm/algorithm_mod.x90 +++ b/tests/system_tests/psyclone/skeleton/algorithm/algorithm_mod.x90 @@ -46,7 +46,7 @@ contains ! Set the new field to a constant value and compute the divergence of it divergence => get_div() s = 2.0_r_def - call invoke( name = "Compute divergence", & + call invoke( name = "Compute_divergence", & setval_c(field_2, s ), & setval_c(field_1, 0.0_r_def), & my_kernel_type(field_1, field_2, divergence) ) diff --git a/tests/system_tests/psyclone/test_psyclone.py b/tests/system_tests/psyclone/test_psyclone.py index 4a06502a..c5eb525b 100644 --- a/tests/system_tests/psyclone/test_psyclone.py +++ b/tests/system_tests/psyclone/test_psyclone.py @@ -5,6 +5,7 @@ # ############################################################################## import filecmp import shutil +import glob from os import unlink from pathlib import Path from unittest import mock @@ -160,17 +161,17 @@ def test_run(self, config): config.build_output / 'algorithm/algorithm_mod_psy.f90', # Expect these prebuild files - # todo: the kernal hash differs between fpp and cpp, perhaps just use wildcards. - config.prebuild_folder / 'algorithm_mod.1602753696.an', # x90 analysis result - config.prebuild_folder / 'my_kernel_mod.4187107526.an', # kernel analysis results - config.prebuild_folder / 'algorithm_mod.5088673431.f90', # prebuild - config.prebuild_folder / 'algorithm_mod_psy.5088673431.f90', # prebuild + # The kernel hash differs between fpp and cpp, so just use wildcards. + config.prebuild_folder / 'algorithm_mod.*.an', # x90 analysis result + config.prebuild_folder / 'my_kernel_mod.*.an', # kernel analysis results + config.prebuild_folder / 'algorithm_mod.*.f90', # prebuild + config.prebuild_folder / 'algorithm_mod_psy.*.f90', # prebuild ] - assert all(not f.exists() for f in expect_files) + assert all(not any(glob.glob(str(f))) for f in expect_files) with config: self.steps(config) - assert all(f.exists() for f in expect_files) + assert all(any(glob.glob(str(f))) for f in expect_files) def test_prebuild(self, tmp_path, config): with config: From c7dc9d395791df268c6814b1f3ad697cf7ff12bd Mon Sep 17 00:00:00 2001 From: Junwei Lyu Date: Mon, 11 Mar 2024 15:43:38 +1100 Subject: [PATCH 2/6] hiker#5 Test warnings are either filtered or changed to be alerted when not issued. --- .../CFortranInterop/test_CFortranInterop.py | 3 +- .../test_FortranDependencies.py | 3 +- .../test_FortranPreProcess.py | 3 +- .../MinimalFortran/test_MinimalFortran.py | 4 +- tests/system_tests/git/test_git.py | 40 ++++++---- .../grab_archive/test_grab_archive.py | 8 +- tests/system_tests/psyclone/test_psyclone.py | 6 +- tests/system_tests/svn_fcm/test_svn_fcm.py | 78 +++++++++++-------- .../zero_config/test_zero_config.py | 27 ++++--- tests/unit_tests/steps/test_analyse.py | 6 +- .../unit_tests/steps/test_archive_objects.py | 5 +- .../steps/test_cleanup_prebuilds.py | 2 +- tests/unit_tests/steps/test_compile_c.py | 2 +- .../unit_tests/steps/test_compile_fortran.py | 22 +++--- tests/unit_tests/steps/test_grab.py | 11 ++- tests/unit_tests/steps/test_link.py | 3 +- tests/unit_tests/steps/test_root_inc_files.py | 6 +- tests/unit_tests/test_tools.py | 6 +- 18 files changed, 136 insertions(+), 99 deletions(-) diff --git a/tests/system_tests/CFortranInterop/test_CFortranInterop.py b/tests/system_tests/CFortranInterop/test_CFortranInterop.py index 5e7b9067..0cb09bb1 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,7 @@ 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..7e026add 100644 --- a/tests/system_tests/FortranDependencies/test_FortranDependencies.py +++ b/tests/system_tests/FortranDependencies/test_FortranDependencies.py @@ -17,11 +17,12 @@ 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..817c157c 100644 --- a/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py +++ b/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py @@ -15,9 +15,10 @@ 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..c655768a 100644 --- a/tests/system_tests/MinimalFortran/test_MinimalFortran.py +++ b/tests/system_tests/MinimalFortran/test_MinimalFortran.py @@ -15,13 +15,15 @@ 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..855d58ab 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,22 @@ 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): + with pytest.raises(RuntimeError), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): 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..9255d61a 100644 --- a/tests/system_tests/grab_archive/test_grab_archive.py +++ b/tests/system_tests/grab_archive/test_grab_archive.py @@ -8,11 +8,13 @@ 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.py b/tests/system_tests/psyclone/test_psyclone.py index 4a06502a..52111a77 100644 --- a/tests/system_tests/psyclone/test_psyclone.py +++ b/tests/system_tests/psyclone/test_psyclone.py @@ -168,19 +168,19 @@ def test_run(self, config): ] assert all(not f.exists() for f in expect_files) - with config: + with config, pytest.warns(UserWarning, match="no transformation script specified"): self.steps(config) assert all(f.exists() for f in expect_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.py b/tests/system_tests/svn_fcm/test_svn_fcm.py index 532c5cac..92aff8c9 100644 --- a/tests/system_tests/svn_fcm/test_svn_fcm.py +++ b/tests/system_tests/svn_fcm/test_svn_fcm.py @@ -110,23 +110,27 @@ 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 +147,7 @@ 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,59 +164,65 @@ 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): + with pytest.raises(ValueError), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): 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): + with pytest.raises(ValueError), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): merge_func(config, src=file2_experiment, dst_label='proj', revision=7) @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): + with pytest.raises(RuntimeError), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): merge_func(config, src=file1_experiment_b, dst_label='proj') @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..4845e135 100644 --- a/tests/system_tests/zero_config/test_zero_config.py +++ b/tests/system_tests/zero_config/test_zero_config.py @@ -5,29 +5,32 @@ 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 +39,7 @@ 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..48f3ce73 100644 --- a/tests/unit_tests/steps/test_analyse.py +++ b/tests/unit_tests/steps/test_analyse.py @@ -115,7 +115,8 @@ 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 +131,8 @@ 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..0ded369a 100644 --- a/tests/unit_tests/steps/test_archive_objects.py +++ b/tests/unit_tests/steps/test_archive_objects.py @@ -5,6 +5,7 @@ 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 +16,7 @@ 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 +37,7 @@ 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..f0907d83 100644 --- a/tests/unit_tests/steps/test_cleanup_prebuilds.py +++ b/tests/unit_tests/steps/test_cleanup_prebuilds.py @@ -18,7 +18,7 @@ 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..117d0afe 100644 --- a/tests/unit_tests/steps/test_compile_c.py +++ b/tests/unit_tests/steps/test_compile_c.py @@ -36,7 +36,7 @@ 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..ceaaef2d 100644 --- a/tests/unit_tests/steps/test_compile_fortran.py +++ b/tests/unit_tests/steps/test_compile_fortran.py @@ -182,7 +182,7 @@ 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 +210,7 @@ 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 +238,7 @@ 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 +262,7 @@ 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 +290,7 @@ 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 +317,7 @@ 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 +344,7 @@ 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 +367,7 @@ 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 +390,7 @@ 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 +426,14 @@ 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..4a349f7f 100644 --- a/tests/unit_tests/steps/test_grab.py +++ b/tests/unit_tests/steps/test_grab.py @@ -10,14 +10,17 @@ 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 +44,7 @@ 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 +57,7 @@ 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..63f46d10 100644 --- a/tests/unit_tests/steps/test_link.py +++ b/tests/unit_tests/steps/test_link.py @@ -10,6 +10,7 @@ from fab.constants import OBJECT_FILES from fab.steps.link import link_exe +import pytest class TestLinkExe(object): def test_run(self): @@ -21,7 +22,7 @@ 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..92b6a566 100644 --- a/tests/unit_tests/steps/test_root_inc_files.py +++ b/tests/unit_tests/steps/test_root_inc_files.py @@ -17,7 +17,7 @@ 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 +29,7 @@ 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 +43,5 @@ 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): From 34853c4e886c67249d8eb6b4a98b960940484238 Mon Sep 17 00:00:00 2001 From: Junwei Lyu Date: Mon, 11 Mar 2024 16:04:50 +1100 Subject: [PATCH 3/6] hiker#5, hiker#4: Renamed duplicated filenames in test subdirectories to allow `pytest tests` at source directory --- .../psyclone/{test_psyclone.py => test_psyclone_system_test.py} | 0 .../svn_fcm/{test_svn_fcm.py => test_svn_fcm_system_test.py} | 0 .../steps/grab/{test_svn_fcm.py => test_svn_fcm_unit_test.py} | 0 .../steps/{test_psyclone.py => test_psyclone_unit_test.py} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/system_tests/psyclone/{test_psyclone.py => test_psyclone_system_test.py} (100%) rename tests/system_tests/svn_fcm/{test_svn_fcm.py => test_svn_fcm_system_test.py} (100%) rename tests/unit_tests/steps/grab/{test_svn_fcm.py => test_svn_fcm_unit_test.py} (100%) rename tests/unit_tests/steps/{test_psyclone.py => test_psyclone_unit_test.py} (100%) diff --git a/tests/system_tests/psyclone/test_psyclone.py b/tests/system_tests/psyclone/test_psyclone_system_test.py similarity index 100% rename from tests/system_tests/psyclone/test_psyclone.py rename to tests/system_tests/psyclone/test_psyclone_system_test.py diff --git a/tests/system_tests/svn_fcm/test_svn_fcm.py b/tests/system_tests/svn_fcm/test_svn_fcm_system_test.py similarity index 100% rename from tests/system_tests/svn_fcm/test_svn_fcm.py rename to tests/system_tests/svn_fcm/test_svn_fcm_system_test.py diff --git a/tests/unit_tests/steps/grab/test_svn_fcm.py b/tests/unit_tests/steps/grab/test_svn_fcm_unit_test.py similarity index 100% rename from tests/unit_tests/steps/grab/test_svn_fcm.py rename to tests/unit_tests/steps/grab/test_svn_fcm_unit_test.py diff --git a/tests/unit_tests/steps/test_psyclone.py b/tests/unit_tests/steps/test_psyclone_unit_test.py similarity index 100% rename from tests/unit_tests/steps/test_psyclone.py rename to tests/unit_tests/steps/test_psyclone_unit_test.py From 77917331b2168b2ac0ce6f398bf047f70a1fb379 Mon Sep 17 00:00:00 2001 From: Junwei Lyu Date: Tue, 12 Mar 2024 17:04:19 +1100 Subject: [PATCH 4/6] hiker#4: Improved the test error fix to be easier to understand --- tests/system_tests/psyclone/test_psyclone_system_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system_tests/psyclone/test_psyclone_system_test.py b/tests/system_tests/psyclone/test_psyclone_system_test.py index c5eb525b..fe0dae79 100644 --- a/tests/system_tests/psyclone/test_psyclone_system_test.py +++ b/tests/system_tests/psyclone/test_psyclone_system_test.py @@ -168,10 +168,10 @@ def test_run(self, config): config.prebuild_folder / 'algorithm_mod_psy.*.f90', # prebuild ] - assert all(not any(glob.glob(str(f))) for f in expect_files) + assert all((glob.glob(str(f)) == []) for f in expect_files) with config: self.steps(config) - assert all(any(glob.glob(str(f))) for f in expect_files) + assert all((glob.glob(str(f)) != []) for f in expect_files) def test_prebuild(self, tmp_path, config): with config: From 22681916bbc811d404ea9463433f2fbc2fa98249 Mon Sep 17 00:00:00 2001 From: Junwei Lyu Date: Wed, 13 Mar 2024 13:29:59 +1100 Subject: [PATCH 5/6] Fix styling problems reported by Flake8 --- .../CFortranInterop/test_CFortranInterop.py | 3 +- .../test_FortranDependencies.py | 4 ++- .../test_FortranPreProcess.py | 4 ++- .../MinimalFortran/test_MinimalFortran.py | 3 +- tests/system_tests/git/test_git.py | 8 +++-- .../grab_archive/test_grab_archive.py | 1 + .../svn_fcm/test_svn_fcm_system_test.py | 29 ++++++++++++---- .../zero_config/test_zero_config.py | 4 ++- tests/unit_tests/steps/test_analyse.py | 12 ++++--- .../unit_tests/steps/test_archive_objects.py | 7 ++-- .../steps/test_cleanup_prebuilds.py | 3 +- tests/unit_tests/steps/test_compile_c.py | 3 +- .../unit_tests/steps/test_compile_fortran.py | 33 ++++++++++++------- tests/unit_tests/steps/test_grab.py | 7 ++-- tests/unit_tests/steps/test_link.py | 4 ++- tests/unit_tests/steps/test_root_inc_files.py | 10 ++++-- 16 files changed, 96 insertions(+), 39 deletions(-) diff --git a/tests/system_tests/CFortranInterop/test_CFortranInterop.py b/tests/system_tests/CFortranInterop/test_CFortranInterop.py index 0cb09bb1..483b6968 100644 --- a/tests/system_tests/CFortranInterop/test_CFortranInterop.py +++ b/tests/system_tests/CFortranInterop/test_CFortranInterop.py @@ -25,7 +25,8 @@ def test_CFortranInterop(tmp_path): # build - with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config, pytest.warns(UserWarning, match="removing managed flag"): + 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 7e026add..6971bf83 100644 --- a/tests/system_tests/FortranDependencies/test_FortranDependencies.py +++ b/tests/system_tests/FortranDependencies/test_FortranDependencies.py @@ -19,10 +19,12 @@ import pytest + def test_FortranDependencies(tmp_path): # build - with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config, pytest.warns(UserWarning, match="removing managed flag"): + 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 817c157c..f45ea74c 100644 --- a/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py +++ b/tests/system_tests/FortranPreProcess/test_FortranPreProcess.py @@ -17,8 +17,10 @@ import pytest + def build(fab_workspace, fpp_flags=None): - with BuildConfig(fab_workspace=fab_workspace, project_label='foo', multiprocessing=False) as config, pytest.warns(UserWarning, match="removing managed flag"): + 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 c655768a..6dd7615f 100644 --- a/tests/system_tests/MinimalFortran/test_MinimalFortran.py +++ b/tests/system_tests/MinimalFortran/test_MinimalFortran.py @@ -23,7 +23,8 @@ def test_MinimalFortran(tmp_path): # build - with BuildConfig(fab_workspace=tmp_path, project_label='foo', multiprocessing=False) as config, pytest.warns(UserWarning, match="removing managed flag"): + 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 855d58ab..3e23b628 100644 --- a/tests/system_tests/git/test_git.py +++ b/tests/system_tests/git/test_git.py @@ -69,7 +69,10 @@ 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.") + @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 @@ -82,7 +85,8 @@ def test_vanilla(self, repo_url, config): 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), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + with pytest.raises(RuntimeError), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): 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 diff --git a/tests/system_tests/grab_archive/test_grab_archive.py b/tests/system_tests/grab_archive/test_grab_archive.py index 9255d61a..aa4251ea 100644 --- a/tests/system_tests/grab_archive/test_grab_archive.py +++ b/tests/system_tests/grab_archive/test_grab_archive.py @@ -10,6 +10,7 @@ import pytest + class TestGrabArchive(object): def test(self, tmp_path): 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 92aff8c9..ff7853c6 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,7 +110,10 @@ 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.") + @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 with pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): @@ -123,7 +126,11 @@ def test_export(self, file2_experiment, config, export_func): 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.") + +@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) @@ -147,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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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) @@ -168,10 +176,15 @@ def test_not_working_copy(self, trunk, config, export_func, checkout_func): export_func(config, src=trunk, dst_label='proj') # if we try to checkout into that folder, it should fail - with pytest.raises(ValueError), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + with pytest.raises(ValueError), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): 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.") + +@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)) @@ -202,7 +215,8 @@ def test_not_working_copy(self, trunk, file2_experiment, config, export_func, me export_func(config, src=trunk, dst_label='proj') # try to merge into an export - with pytest.raises(ValueError), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + with pytest.raises(ValueError), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): merge_func(config, src=file2_experiment, dst_label='proj', revision=7) @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs)) @@ -212,7 +226,8 @@ def test_conflict(self, file1_experiment_a, file1_experiment_b, config, checkout confirm_file1_experiment_a(config) # this branch modifies the same line of text - with pytest.raises(RuntimeError), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + with pytest.raises(RuntimeError), \ + pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): merge_func(config, src=file1_experiment_b, dst_label='proj') @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs)) diff --git a/tests/system_tests/zero_config/test_zero_config.py b/tests/system_tests/zero_config/test_zero_config.py index 4845e135..5ae56b3d 100644 --- a/tests/system_tests/zero_config/test_zero_config.py +++ b/tests/system_tests/zero_config/test_zero_config.py @@ -7,6 +7,7 @@ import pytest + class TestZeroConfig(object): def test_fortran_dependencies(self, tmp_path): @@ -39,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), pytest.warns(DeprecationWarning, match="RootIncFiles is deprecated as .inc files are due to be removed."): + 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 48f3ce73..0e1db71b 100644 --- a/tests/unit_tests/steps/test_analyse.py +++ b/tests/unit_tests/steps/test_analyse.py @@ -115,8 +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)]), 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" + 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 @@ -131,8 +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)), 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" + 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 0ded369a..0600d85c 100644 --- a/tests/unit_tests/steps/test_archive_objects.py +++ b/tests/unit_tests/steps/test_archive_objects.py @@ -7,6 +7,7 @@ import pytest + class Test_archive_objects(object): def test_for_exes(self): @@ -16,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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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 @@ -37,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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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 f0907d83..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')]), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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 117d0afe..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'}), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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 ceaaef2d..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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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'), pytest.warns(UserWarning, match="removing managed flag"): + 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'), pytest.warns(UserWarning, match="removing managed flag"): + 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 4a349f7f..57878b22 100644 --- a/tests/unit_tests/steps/test_grab.py +++ b/tests/unit_tests/steps/test_grab.py @@ -12,6 +12,7 @@ import pytest + class TestGrabFolder(object): def test_trailing_slash(self): @@ -44,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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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)]) @@ -57,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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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 63f46d10..cfee8f9a 100644 --- a/tests/unit_tests/steps/test_link.py +++ b/tests/unit_tests/steps/test_link.py @@ -12,6 +12,7 @@ import pytest + class TestLinkExe(object): def test_run(self): # ensure the command is formed correctly, with the flags at the end (why?!) @@ -22,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, pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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 92b6a566..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'), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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'), pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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'), pytest.warns(DeprecationWarning, match="RootIncFiles is deprecated as .inc files are due to be removed."): + 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) From 2cfcb1ad991024f073c975012d9b175375b09178 Mon Sep 17 00:00:00 2001 From: Junwei Lyu Date: Wed, 13 Mar 2024 14:52:51 +1100 Subject: [PATCH 6/6] Fix "_metric_send_conn not set, cannot send metrics" warning not issued, as reported by CI pipeline on Github --- tests/system_tests/git/test_git.py | 3 +-- tests/system_tests/svn_fcm/test_svn_fcm_system_test.py | 9 +++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/system_tests/git/test_git.py b/tests/system_tests/git/test_git.py index 3e23b628..32895dfe 100644 --- a/tests/system_tests/git/test_git.py +++ b/tests/system_tests/git/test_git.py @@ -85,8 +85,7 @@ def test_vanilla(self, repo_url, config): 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), \ - pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + 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 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 ff7853c6..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 @@ -176,8 +176,7 @@ def test_not_working_copy(self, trunk, config, export_func, checkout_func): export_func(config, src=trunk, dst_label='proj') # if we try to checkout into that folder, it should fail - with pytest.raises(ValueError), \ - pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + with pytest.raises(ValueError): checkout_func(config, src=trunk, dst_label='proj') @@ -215,8 +214,7 @@ def test_not_working_copy(self, trunk, file2_experiment, config, export_func, me export_func(config, src=trunk, dst_label='proj') # try to merge into an export - with pytest.raises(ValueError), \ - pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + with pytest.raises(ValueError): merge_func(config, src=file2_experiment, dst_label='proj', revision=7) @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs)) @@ -226,8 +224,7 @@ def test_conflict(self, file1_experiment_a, file1_experiment_b, config, checkout confirm_file1_experiment_a(config) # this branch modifies the same line of text - with pytest.raises(RuntimeError), \ - pytest.warns(UserWarning, match="_metric_send_conn not set, cannot send metrics"): + with pytest.raises(RuntimeError): merge_func(config, src=file1_experiment_b, dst_label='proj') @pytest.mark.parametrize('checkout_func,merge_func', zip(checkout_funcs, merge_funcs))