Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test warning #292

Merged
merged 8 commits into from
Mar 27, 2024
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to recognise this change from a different PR.

Original file line number Diff line number Diff line change
Expand Up @@ -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) )
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also looks familiar although it has new stuff too. Has there been a branching issue?

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# ##############################################################################
import filecmp
import shutil
import glob
from os import unlink
from pathlib import Path
from unittest import mock
Expand Down Expand Up @@ -160,27 +161,27 @@ 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)
with config:
assert all((glob.glob(str(f)) == []) for f in expect_files)
with config, pytest.warns(UserWarning, match="no transformation script specified"):
self.steps(config)
assert all(f.exists() 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:
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
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)
Loading