diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-02-28 18:47:20 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-02-28 18:47:20 +0000 |
commit | 6d4a4e9928bb718d2da446a7d6a11708301625f2 (patch) | |
tree | c4b25b736e26409a5d3eb3222d54fb1c7e445f0a | |
parent | 348f04e7a80338de1b9cc911e48263d8cd31be65 (diff) | |
download | buildstream-bschubert/fix-test-paths.tar.gz |
store full host tools command in sites.py variables check.bschubert/fix-test-paths
This allows tests importing them to have access to the commands
directly and removes the need from calling this multiple times
This also fixes multiple bugs where the paths of the tests runners
might not be canonical and tools would not get found correctly
-rw-r--r-- | tests/cachekey/cachekey.py | 6 | ||||
-rw-r--r-- | tests/examples/autotools.py | 6 | ||||
-rw-r--r-- | tests/examples/developing.py | 8 | ||||
-rw-r--r-- | tests/examples/integration-commands.py | 6 | ||||
-rw-r--r-- | tests/examples/junctions.py | 6 | ||||
-rw-r--r-- | tests/examples/running-commands.py | 6 | ||||
-rw-r--r-- | tests/format/junctions.py | 6 | ||||
-rw-r--r-- | tests/integration/build-uid.py | 6 | ||||
-rw-r--r-- | tests/integration/cachedfail.py | 4 | ||||
-rw-r--r-- | tests/integration/sandbox-bwrap.py | 8 | ||||
-rw-r--r-- | tests/sources/bzr.py | 4 | ||||
-rw-r--r-- | tests/sources/git.py | 46 | ||||
-rw-r--r-- | tests/sources/no_fetch_cached.py | 4 | ||||
-rw-r--r-- | tests/sources/tar.py | 4 | ||||
-rw-r--r-- | tests/testutils/repo/bzr.py | 6 | ||||
-rw-r--r-- | tests/testutils/repo/git.py | 8 | ||||
-rw-r--r-- | tests/testutils/repo/ostree.py | 10 | ||||
-rw-r--r-- | tests/testutils/site.py | 27 |
18 files changed, 83 insertions, 88 deletions
diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py index 4a6896888..661a53e66 100644 --- a/tests/cachekey/cachekey.py +++ b/tests/cachekey/cachekey.py @@ -36,7 +36,7 @@ # the result. # from buildstream.plugintestutils.runcli import cli -from tests.testutils.site import HAVE_BZR, HAVE_GIT, HAVE_OSTREE, IS_LINUX, MACHINE_ARCH +from tests.testutils.site import BZR, GIT, HAVE_OSTREE, IS_LINUX, MACHINE_ARCH from buildstream.plugin import CoreWarnings from buildstream import _yaml import os @@ -147,8 +147,8 @@ DATA_DIR = os.path.join( @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Cache keys depend on architecture') @pytest.mark.skipif(not IS_LINUX, reason='Only available on linux') -@pytest.mark.skipif(HAVE_BZR is False, reason="bzr is not available") -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(BZR is None, reason="bzr is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.skipif(HAVE_OSTREE is False, reason="ostree is not available") @pytest.mark.datafiles(DATA_DIR) def test_cache_key(datafiles, cli): diff --git a/tests/examples/autotools.py b/tests/examples/autotools.py index 96827ff4c..f7733c7b1 100644 --- a/tests/examples/autotools.py +++ b/tests/examples/autotools.py @@ -3,7 +3,7 @@ import pytest from buildstream.plugintestutils import cli_integration as cli from buildstream.plugintestutils.integration import assert_contains -from tests.testutils.site import HAVE_BWRAP, IS_LINUX, MACHINE_ARCH +from tests.testutils.site import BWRAP, IS_LINUX, MACHINE_ARCH pytestmark = pytest.mark.integration @@ -15,7 +15,7 @@ DATA_DIR = os.path.join( # Tests a build of the autotools amhello project on a alpine-linux base runtime @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_autotools_build(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -38,7 +38,7 @@ def test_autotools_build(cli, tmpdir, datafiles): # Test running an executable built with autotools. @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_autotools_run(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/examples/developing.py b/tests/examples/developing.py index 3ef78fd36..d45077418 100644 --- a/tests/examples/developing.py +++ b/tests/examples/developing.py @@ -4,7 +4,7 @@ import pytest import tests.testutils.patch as patch from buildstream.plugintestutils import cli_integration as cli from buildstream.plugintestutils.integration import assert_contains -from tests.testutils.site import HAVE_BWRAP, IS_LINUX, MACHINE_ARCH +from tests.testutils.site import BWRAP, IS_LINUX, MACHINE_ARCH pytestmark = pytest.mark.integration @@ -16,7 +16,7 @@ DATA_DIR = os.path.join( # Test that the project builds successfully @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_autotools_build(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -37,7 +37,7 @@ def test_autotools_build(cli, tmpdir, datafiles): # Test the unmodified hello command works as expected. @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_run_unmodified_hello(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -70,7 +70,7 @@ def test_open_workspace(cli, tmpdir, datafiles): # Test making a change using the workspace @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_make_change_in_workspace(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/examples/integration-commands.py b/tests/examples/integration-commands.py index abc64d951..f27e5e0c2 100644 --- a/tests/examples/integration-commands.py +++ b/tests/examples/integration-commands.py @@ -3,7 +3,7 @@ import pytest from buildstream.plugintestutils import cli_integration as cli from buildstream.plugintestutils.integration import assert_contains -from tests.testutils.site import HAVE_BWRAP, IS_LINUX, MACHINE_ARCH +from tests.testutils.site import BWRAP, IS_LINUX, MACHINE_ARCH pytestmark = pytest.mark.integration @@ -14,7 +14,7 @@ DATA_DIR = os.path.join( @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_integration_commands_build(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -27,7 +27,7 @@ def test_integration_commands_build(cli, tmpdir, datafiles): # Test running the executable @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_integration_commands_run(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/examples/junctions.py b/tests/examples/junctions.py index 3992b1520..6e76a1920 100644 --- a/tests/examples/junctions.py +++ b/tests/examples/junctions.py @@ -3,7 +3,7 @@ import pytest from buildstream.plugintestutils import cli_integration as cli from buildstream.plugintestutils.integration import assert_contains -from tests.testutils.site import IS_LINUX, HAVE_BWRAP, MACHINE_ARCH +from tests.testutils.site import IS_LINUX, BWRAP, MACHINE_ARCH pytestmark = pytest.mark.integration @@ -15,7 +15,7 @@ DATA_DIR = os.path.join( # Test that the project builds successfully @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_build(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -27,7 +27,7 @@ def test_build(cli, tmpdir, datafiles): # Test the callHello script works as expected. @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_shell_call_hello(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/examples/running-commands.py b/tests/examples/running-commands.py index 6290204a9..491a4fbe9 100644 --- a/tests/examples/running-commands.py +++ b/tests/examples/running-commands.py @@ -3,7 +3,7 @@ import pytest from buildstream.plugintestutils import cli_integration as cli from buildstream.plugintestutils.integration import assert_contains -from tests.testutils.site import IS_LINUX, HAVE_BWRAP, MACHINE_ARCH +from tests.testutils.site import IS_LINUX, BWRAP, MACHINE_ARCH pytestmark = pytest.mark.integration @@ -14,7 +14,7 @@ DATA_DIR = os.path.join( @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_running_commands_build(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -27,7 +27,7 @@ def test_running_commands_build(cli, tmpdir, datafiles): # Test running the executable @pytest.mark.skipif(MACHINE_ARCH != 'x86-64', reason='Examples are writtent for x86-64') -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_running_commands_run(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/format/junctions.py b/tests/format/junctions.py index 7f27b5982..2bc159e7f 100644 --- a/tests/format/junctions.py +++ b/tests/format/junctions.py @@ -6,7 +6,7 @@ from buildstream import _yaml, ElementError from buildstream._exceptions import ErrorDomain, LoadErrorReason from buildstream.plugintestutils import cli from tests.testutils import create_repo -from tests.testutils.site import HAVE_GIT +from tests.testutils.site import GIT DATA_DIR = os.path.join( @@ -209,7 +209,7 @@ def test_options_inherit(cli, tmpdir, datafiles): assert(os.path.exists(os.path.join(checkoutdir, 'horsy.txt'))) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(DATA_DIR) def test_git_show(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), 'foo') @@ -241,7 +241,7 @@ def test_git_show(cli, tmpdir, datafiles): assert 'base.bst:target.bst' in element_list -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(DATA_DIR) def test_git_build(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), 'foo') diff --git a/tests/integration/build-uid.py b/tests/integration/build-uid.py index 88b887b5e..d5350f79f 100644 --- a/tests/integration/build-uid.py +++ b/tests/integration/build-uid.py @@ -5,7 +5,7 @@ from buildstream import _yaml from buildstream.plugintestutils import cli_integration as cli from buildstream.plugintestutils.integration import assert_contains -from tests.testutils.site import HAVE_BWRAP, IS_LINUX, HAVE_SANDBOX +from tests.testutils.site import BWRAP, IS_LINUX, HAVE_SANDBOX pytestmark = pytest.mark.integration @@ -16,7 +16,7 @@ DATA_DIR = os.path.join( ) -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubblewrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_build_uid_overridden(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -35,7 +35,7 @@ def test_build_uid_overridden(cli, tmpdir, datafiles): assert result.exit_code == 0 -@pytest.mark.skipif(not IS_LINUX or not HAVE_BWRAP, reason='Only available on linux with bubbelwrap') +@pytest.mark.skipif(not IS_LINUX or BWRAP is None, reason='Only available on linux with bubbelwrap') @pytest.mark.datafiles(DATA_DIR) def test_build_uid_in_project(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/integration/cachedfail.py b/tests/integration/cachedfail.py index ad91ea978..ed9fe6b26 100644 --- a/tests/integration/cachedfail.py +++ b/tests/integration/cachedfail.py @@ -7,7 +7,7 @@ from buildstream.plugintestutils import cli_integration as cli from conftest import clean_platform_cache from tests.testutils import create_artifact_share -from tests.testutils.site import HAVE_BWRAP, IS_LINUX, HAVE_SANDBOX +from tests.testutils.site import BWRAP, IS_LINUX, HAVE_SANDBOX pytestmark = pytest.mark.integration @@ -167,7 +167,7 @@ def test_push_cached_fail(cli, tmpdir, datafiles, on_error): assert share.has_artifact('test', 'element.bst', cli.get_element_key(project, 'element.bst')) -@pytest.mark.skipif(not (IS_LINUX and HAVE_BWRAP), reason='Only available with bubblewrap on Linux') +@pytest.mark.skipif(not (IS_LINUX and BWRAP is not None), reason='Only available with bubblewrap on Linux') @pytest.mark.datafiles(DATA_DIR) def test_host_tools_errors_are_not_cached(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/integration/sandbox-bwrap.py b/tests/integration/sandbox-bwrap.py index 2c939e9be..bc7c81164 100644 --- a/tests/integration/sandbox-bwrap.py +++ b/tests/integration/sandbox-bwrap.py @@ -5,7 +5,7 @@ from buildstream._exceptions import ErrorDomain from buildstream.plugintestutils import cli_integration as cli from buildstream.plugintestutils.integration import assert_contains -from tests.testutils.site import HAVE_BWRAP, HAVE_BWRAP_JSON_STATUS +from tests.testutils.site import BWRAP, HAVE_BWRAP_JSON_STATUS pytestmark = pytest.mark.integration @@ -21,7 +21,7 @@ DATA_DIR = os.path.join( # so BuildStream tries to remove them to do good. BuildStream should be extra # careful when those folders already exist and should not touch them, though. @pytest.mark.integration -@pytest.mark.skipif(not HAVE_BWRAP, reason='Only available with bubblewrap') +@pytest.mark.skipif(BWRAP is None, reason='Only available with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_sandbox_bwrap_cleanup_build(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -33,7 +33,7 @@ def test_sandbox_bwrap_cleanup_build(cli, tmpdir, datafiles): assert result.exit_code == 0 -@pytest.mark.skipif(not HAVE_BWRAP, reason='Only available with bubblewrap') +@pytest.mark.skipif(BWRAP is None, reason='Only available with bubblewrap') @pytest.mark.skipif(not HAVE_BWRAP_JSON_STATUS, reason='Only available with bubblewrap supporting --json-status-fd') @pytest.mark.datafiles(DATA_DIR) def test_sandbox_bwrap_distinguish_setup_error(cli, tmpdir, datafiles): @@ -45,7 +45,7 @@ def test_sandbox_bwrap_distinguish_setup_error(cli, tmpdir, datafiles): @pytest.mark.integration -@pytest.mark.skipif(not HAVE_BWRAP, reason='Only available with bubblewrap') +@pytest.mark.skipif(BWRAP is None, reason='Only available with bubblewrap') @pytest.mark.datafiles(DATA_DIR) def test_sandbox_bwrap_return_subprocess(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/sources/bzr.py b/tests/sources/bzr.py index bf7d1e844..f1f68ce05 100644 --- a/tests/sources/bzr.py +++ b/tests/sources/bzr.py @@ -6,7 +6,7 @@ from buildstream import _yaml from buildstream.plugintestutils import cli from tests.testutils import create_repo -from tests.testutils.site import HAVE_BZR +from tests.testutils.site import BZR DATA_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), @@ -14,7 +14,7 @@ DATA_DIR = os.path.join( ) -@pytest.mark.skipif(HAVE_BZR is False, reason="bzr is not available") +@pytest.mark.skipif(BZR is None, reason="bzr is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR)) def test_fetch_checkout(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/sources/git.py b/tests/sources/git.py index f3d2e2809..e18db387b 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -30,9 +30,9 @@ from buildstream import _yaml from buildstream.plugin import CoreWarnings from buildstream.plugintestutils import cli -from tests.testutils.site import HAVE_GIT, HAVE_OLD_GIT +from tests.testutils.site import GIT, HAVE_OLD_GIT from tests.testutils import create_repo -from tests.testutils.site import HAVE_GIT, HAVE_OLD_GIT +from tests.testutils.site import GIT, HAVE_OLD_GIT DATA_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), @@ -40,7 +40,7 @@ DATA_DIR = os.path.join( ) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_fetch_bad_ref(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -66,7 +66,7 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles): result.assert_task_error(ErrorDomain.SOURCE, None) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_fetch_checkout(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -105,7 +105,7 @@ def test_submodule_fetch_checkout(cli, tmpdir, datafiles): assert os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt')) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_fetch_source_enable_explicit(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -144,7 +144,7 @@ def test_submodule_fetch_source_enable_explicit(cli, tmpdir, datafiles): assert os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt')) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_fetch_source_disable(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -183,7 +183,7 @@ def test_submodule_fetch_source_disable(cli, tmpdir, datafiles): assert not os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt')) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_fetch_submodule_does_override(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -222,7 +222,7 @@ def test_submodule_fetch_submodule_does_override(cli, tmpdir, datafiles): assert os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt')) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_fetch_submodule_individual_checkout(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -267,7 +267,7 @@ def test_submodule_fetch_submodule_individual_checkout(cli, tmpdir, datafiles): assert os.path.exists(os.path.join(checkoutdir, 'othersubdir', 'unicornfile.txt')) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_fetch_submodule_individual_checkout_explicit(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -312,7 +312,7 @@ def test_submodule_fetch_submodule_individual_checkout_explicit(cli, tmpdir, dat assert os.path.exists(os.path.join(checkoutdir, 'othersubdir', 'unicornfile.txt')) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'project-override')) def test_submodule_fetch_project_override(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -351,7 +351,7 @@ def test_submodule_fetch_project_override(cli, tmpdir, datafiles): assert not os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt')) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_track_ignore_inconsistent(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -388,7 +388,7 @@ def test_submodule_track_ignore_inconsistent(cli, tmpdir, datafiles): assert "Ignoring inconsistent submodule" in result.stderr -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) @@ -415,7 +415,7 @@ def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): result.assert_task_error(None, None) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("fail", ['warn', 'error']) def test_ref_not_in_track(cli, tmpdir, datafiles, fail): @@ -458,7 +458,7 @@ def test_ref_not_in_track(cli, tmpdir, datafiles, fail): assert "ref-not-in-track" in result.stderr -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("fail", ['warn', 'error']) def test_unlisted_submodule(cli, tmpdir, datafiles, fail): @@ -531,7 +531,7 @@ def test_unlisted_submodule(cli, tmpdir, datafiles, fail): assert "git:unlisted-submodule" in result.stderr -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("fail", ['warn', 'error']) def test_track_unlisted_submodule(cli, tmpdir, datafiles, fail): @@ -594,7 +594,7 @@ def test_track_unlisted_submodule(cli, tmpdir, datafiles, fail): assert "git:unlisted-submodule" in result.stderr -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("fail", ['warn', 'error']) def test_invalid_submodule(cli, tmpdir, datafiles, fail): @@ -665,7 +665,7 @@ def test_invalid_submodule(cli, tmpdir, datafiles, fail): assert "git:invalid-submodule" in result.stderr -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.skipif(HAVE_OLD_GIT, reason="old git rm does not update .gitmodules") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("fail", ['warn', 'error']) @@ -727,7 +727,7 @@ def test_track_invalid_submodule(cli, tmpdir, datafiles, fail): assert "git:invalid-submodule" in result.stderr -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("ref_format", ['sha1', 'git-describe']) @pytest.mark.parametrize("tag,extra_commit", [(False, False), (True, False), (True, True)]) @@ -774,7 +774,7 @@ def test_track_fetch(cli, tmpdir, datafiles, ref_format, tag, extra_commit): result.assert_success() -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.skipif(HAVE_OLD_GIT, reason="old git describe lacks --first-parent") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')]) @@ -887,7 +887,7 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type): assert p.returncode != 0 -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')]) @pytest.mark.parametrize("tag_type", [('annotated'), ('lightweight')]) @@ -998,7 +998,7 @@ def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_ty assert p.returncode != 0 -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_git_describe_relevant_history(cli, tmpdir, datafiles): project = str(datafiles) @@ -1076,7 +1076,7 @@ def test_git_describe_relevant_history(cli, tmpdir, datafiles): assert set(rev_list.splitlines()) == set([head, tagged_ref, branch_boundary]) -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_default_do_not_track_tags(cli, tmpdir, datafiles): project = str(datafiles) @@ -1116,7 +1116,7 @@ def test_default_do_not_track_tags(cli, tmpdir, datafiles): assert 'tags' not in element['sources'][0] -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_overwrite_rogue_tag_multiple_remotes(cli, tmpdir, datafiles): """When using multiple remotes in cache (i.e. when using aliases), we diff --git a/tests/sources/no_fetch_cached.py b/tests/sources/no_fetch_cached.py index 9ef838cf4..4d34521a1 100644 --- a/tests/sources/no_fetch_cached.py +++ b/tests/sources/no_fetch_cached.py @@ -5,7 +5,7 @@ from buildstream import _yaml from buildstream.plugintestutils import cli from tests.testutils import create_repo -from tests.testutils.site import HAVE_GIT +from tests.testutils.site import GIT DATA_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), @@ -17,7 +17,7 @@ DATA_DIR = os.path.join( # Tests # ################################################################## # Test that fetch() is not called for cached sources -@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.skipif(GIT is None, reason="git is not available") @pytest.mark.datafiles(DATA_DIR) def test_no_fetch_cached(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) diff --git a/tests/sources/tar.py b/tests/sources/tar.py index 959ff890c..633a5c759 100644 --- a/tests/sources/tar.py +++ b/tests/sources/tar.py @@ -10,7 +10,7 @@ from buildstream._exceptions import ErrorDomain from buildstream import _yaml from buildstream.plugintestutils import cli from tests.testutils.file_server import create_file_server -from tests.testutils.site import HAVE_LZIP +from tests.testutils.site import LZIP from . import list_dir_contents DATA_DIR = os.path.join( @@ -243,7 +243,7 @@ def test_stage_contains_links(cli, tmpdir, datafiles): assert(checkout_contents == original_contents) -@pytest.mark.skipif(not HAVE_LZIP, reason='lzip is not available') +@pytest.mark.skipif(LZIP is None, reason='lzip is not available') @pytest.mark.datafiles(os.path.join(DATA_DIR, 'fetch')) @pytest.mark.parametrize("srcdir", ["a", "./a"]) def test_stage_default_basedir_lzip(cli, tmpdir, datafiles, srcdir): diff --git a/tests/testutils/repo/bzr.py b/tests/testutils/repo/bzr.py index e8abdfee0..12abc47b5 100644 --- a/tests/testutils/repo/bzr.py +++ b/tests/testutils/repo/bzr.py @@ -4,7 +4,7 @@ import pytest from buildstream import utils from .repo import Repo -from ..site import HAVE_BZR +from ..site import BZR BZR_ENV = { "BZR_EMAIL": "Testy McTesterson <testy.mctesterson@example.com>" @@ -14,10 +14,10 @@ BZR_ENV = { class Bzr(Repo): def __init__(self, directory, subdir): - if not HAVE_BZR: + if not BZR: pytest.skip("bzr is not available") super(Bzr, self).__init__(directory, subdir) - self.bzr = utils.get_host_tool('bzr') + self.bzr = BZR def create(self, directory): branch_dir = os.path.join(self.repo, 'trunk') diff --git a/tests/testutils/repo/git.py b/tests/testutils/repo/git.py index 3eb8c6577..a12ffaba3 100644 --- a/tests/testutils/repo/git.py +++ b/tests/testutils/repo/git.py @@ -4,7 +4,7 @@ import shutil import subprocess from .repo import Repo -from ..site import HAVE_GIT +from ..site import GIT GIT_ENV = { 'GIT_AUTHOR_DATE': '1320966000 +0200', @@ -19,7 +19,7 @@ GIT_ENV = { class Git(Repo): def __init__(self, directory, subdir): - if not HAVE_GIT: + if not GIT: pytest.skip("git is not available") self.submodules = {} @@ -27,8 +27,8 @@ class Git(Repo): super(Git, self).__init__(directory, subdir) def _run_git(self, *args, **kwargs): - argv = ['git'] - argv.extend(args) + argv = [GIT, *args] + if 'env' not in kwargs: kwargs['env'] = dict(GIT_ENV, PWD=self.repo) kwargs.setdefault('cwd', self.repo) diff --git a/tests/testutils/repo/ostree.py b/tests/testutils/repo/ostree.py index e240de113..d52bf12f2 100644 --- a/tests/testutils/repo/ostree.py +++ b/tests/testutils/repo/ostree.py @@ -2,22 +2,22 @@ import pytest import subprocess from .repo import Repo -from ..site import HAVE_OSTREE_CLI, HAVE_OSTREE +from ..site import OSTREE_CLI, HAVE_OSTREE class OSTree(Repo): def __init__(self, directory, subdir): - if not HAVE_OSTREE_CLI or not HAVE_OSTREE: + if not OSTREE_CLI or not HAVE_OSTREE: pytest.skip("ostree cli is not available") super(OSTree, self).__init__(directory, subdir) def create(self, directory): - subprocess.call(['ostree', 'init', + subprocess.call([OSTREE_CLI, 'init', '--repo', self.repo, '--mode', 'archive-z2']) - subprocess.call(['ostree', 'commit', + subprocess.call([OSTREE_CLI, 'commit', '--repo', self.repo, '--branch', 'master', '--subject', 'Initial commit', @@ -40,7 +40,7 @@ class OSTree(Repo): def latest_commit(self): output = subprocess.check_output([ - 'ostree', 'rev-parse', + OSTREE_CLI, 'rev-parse', '--repo', self.repo, 'master' ]) diff --git a/tests/testutils/site.py b/tests/testutils/site.py index 952b2618c..9a9aca200 100644 --- a/tests/testutils/site.py +++ b/tests/testutils/site.py @@ -10,26 +10,23 @@ from buildstream import _site, utils, ProgramNotFoundError from buildstream._platform import Platform try: - utils.get_host_tool('bzr') - HAVE_BZR = True + BZR = utils.get_host_tool('bzr') except ProgramNotFoundError: - HAVE_BZR = False + BZR = None try: - utils.get_host_tool('git') - HAVE_GIT = True + GIT = utils.get_host_tool('git') out = str(subprocess.check_output(['git', '--version']), "utf-8") version = tuple(int(x) for x in out.split(' ')[2].split('.')) HAVE_OLD_GIT = version < (1, 8, 5) except ProgramNotFoundError: - HAVE_GIT = False + GIT = None HAVE_OLD_GIT = False try: - utils.get_host_tool('ostree') - HAVE_OSTREE_CLI = True + OSTREE_CLI = utils.get_host_tool('ostree') except ProgramNotFoundError: - HAVE_OSTREE_CLI = False + OSTREE_CLI = None try: from buildstream import _ostree @@ -38,18 +35,16 @@ except (ImportError, ValueError): HAVE_OSTREE = False try: - utils.get_host_tool('bwrap') - HAVE_BWRAP = True + BWRAP = utils.get_host_tool('bwrap') HAVE_BWRAP_JSON_STATUS = _site.get_bwrap_version() >= (0, 3, 2) except ProgramNotFoundError: - HAVE_BWRAP = False + BWRAP = None HAVE_BWRAP_JSON_STATUS = False try: - utils.get_host_tool('lzip') - HAVE_LZIP = True + LZIP = utils.get_host_tool('lzip') except ProgramNotFoundError: - HAVE_LZIP = False + LZIP = False try: import arpy @@ -65,7 +60,7 @@ if not IS_LINUX: HAVE_SANDBOX = True # fallback to a chroot sandbox on unix elif IS_WSL: HAVE_SANDBOX = False # Sandboxes are inoperable under WSL due to lack of FUSE -elif IS_LINUX and HAVE_BWRAP: +elif IS_LINUX and BWRAP: HAVE_SANDBOX = True else: HAVE_SANDBOX = False |