Skip to content

Commit

Permalink
Fix test warning (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonjunweilyu authored Mar 27, 2024
1 parent 728889d commit e51cbfb
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 93 deletions.
4 changes: 3 additions & 1 deletion tests/system_tests/CFortranInterop/test_CFortranInterop.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
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'


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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion tests/system_tests/MinimalFortran/test_MinimalFortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
41 changes: 26 additions & 15 deletions tests/system_tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
9 changes: 6 additions & 3 deletions tests/system_tests/grab_archive/test_grab_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions tests/system_tests/psyclone/test_psyclone_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
80 changes: 51 additions & 29 deletions tests/system_tests/svn_fcm/test_svn_fcm_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -160,59 +172,69 @@ 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):
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):
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)
29 changes: 17 additions & 12 deletions tests/system_tests/zero_config/test_zero_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading

0 comments on commit e51cbfb

Please sign in to comment.