summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-06-17 14:12:27 +0100
committerJames Ennis <james.ennis@codethink.com>2019-06-26 08:36:20 +0000
commit1c0bf810c6e5c8e01e9213acafb7079c8ce814a1 (patch)
tree07953d65d5073637c9974a7b710379cc210cc222 /tests
parent956cd6d4485e30a9f39c7a1e44bf9fdc47392e3e (diff)
downloadbuildstream-1c0bf810c6e5c8e01e9213acafb7079c8ce814a1.tar.gz
testutils: Move assert_shared and assert_not_shared to testutils
Diffstat (limited to 'tests')
-rw-r--r--tests/artifactcache/junctions.py17
-rw-r--r--tests/frontend/pull.py24
-rw-r--r--tests/frontend/push.py25
-rw-r--r--tests/testutils/__init__.py2
-rw-r--r--tests/testutils/artifactshare.py16
5 files changed, 23 insertions, 61 deletions
diff --git a/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py
index f677a2bd6..cb4698659 100644
--- a/tests/artifactcache/junctions.py
+++ b/tests/artifactcache/junctions.py
@@ -8,7 +8,7 @@ import pytest
from buildstream import _yaml
from buildstream.testing import cli # pylint: disable=unused-import
-from tests.testutils import create_artifact_share
+from tests.testutils import create_artifact_share, assert_shared
DATA_DIR = os.path.join(
@@ -17,17 +17,6 @@ DATA_DIR = os.path.join(
)
-# Assert that a given artifact is in the share
-#
-def assert_shared(cli, share, project_name, project, element_name):
- # NOTE: 'test' here is the name of the project
- # specified in the project.conf we are testing with.
- #
- if not share.has_artifact(cli.get_artifact_name(project, project_name, element_name)):
- raise AssertionError("Artifact share at {} does not contain the expected element {}"
- .format(share.repo, element_name))
-
-
def project_set_artifacts(project, url):
project_conf_file = os.path.join(project, 'project.conf')
project_config = _yaml.load(project_conf_file)
@@ -64,8 +53,8 @@ def test_push_pull(cli, tmpdir, datafiles):
assert result.exit_code == 0
# And finally assert that the artifacts are in the right shares
- assert_shared(cli, share, 'parent', project, 'target.bst')
- assert_shared(cli, base_share, 'base', base_project, 'base-element.bst')
+ assert_shared(cli, share, project, 'target.bst', project_name='parent')
+ assert_shared(cli, base_share, base_project, 'base-element.bst', project_name='base')
# Now we've pushed, delete the user's local artifact cache
# directory and try to redownload it from the share
diff --git a/tests/frontend/pull.py b/tests/frontend/pull.py
index 25ff265b1..a87a311d2 100644
--- a/tests/frontend/pull.py
+++ b/tests/frontend/pull.py
@@ -7,7 +7,7 @@ import stat
import pytest
from buildstream import utils
from buildstream.testing import cli # pylint: disable=unused-import
-from tests.testutils import create_artifact_share, generate_junction
+from tests.testutils import create_artifact_share, generate_junction, assert_shared, assert_not_shared
# Project directory
@@ -17,28 +17,6 @@ DATA_DIR = os.path.join(
)
-# Assert that a given artifact is in the share
-#
-def assert_shared(cli, share, project, element_name):
- # NOTE: 'test' here is the name of the project
- # specified in the project.conf we are testing with.
- #
- if not share.has_artifact(cli.get_artifact_name(project, 'test', element_name)):
- raise AssertionError("Artifact share at {} does not contain the expected element {}"
- .format(share.repo, element_name))
-
-
-# Assert that a given artifact is NOT in the share
-#
-def assert_not_shared(cli, share, project, element_name):
- # NOTE: 'test' here is the name of the project
- # specified in the project.conf we are testing with.
- #
- if share.has_artifact(cli.get_artifact_name(project, 'test', element_name)):
- raise AssertionError("Artifact share at {} unexpectedly contains the element {}"
- .format(share.repo, element_name))
-
-
# Tests that:
#
# * `bst build` pushes all build elements to configured 'push' cache
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index a9b072cf7..93b7425b2 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -28,7 +28,8 @@ import pytest
from buildstream._exceptions import ErrorDomain
from buildstream.testing import cli # pylint: disable=unused-import
-from tests.testutils import create_artifact_share, create_element_size, generate_junction, wait_for_cache_granularity
+from tests.testutils import create_artifact_share, create_element_size, generate_junction, \
+ wait_for_cache_granularity, assert_shared, assert_not_shared
# Project directory
@@ -38,28 +39,6 @@ DATA_DIR = os.path.join(
)
-# Assert that a given artifact is in the share
-#
-def assert_shared(cli, share, project, element_name):
- # NOTE: 'test' here is the name of the project
- # specified in the project.conf we are testing with.
- #
- if not share.has_artifact(cli.get_artifact_name(project, 'test', element_name)):
- raise AssertionError("Artifact share at {} does not contain the expected element {}"
- .format(share.repo, element_name))
-
-
-# Assert that a given artifact is NOT in the share
-#
-def assert_not_shared(cli, share, project, element_name):
- # NOTE: 'test' here is the name of the project
- # specified in the project.conf we are testing with.
- #
- if share.has_artifact(cli.get_artifact_name(project, 'test', element_name)):
- raise AssertionError("Artifact share at {} unexpectedly contains the element {}"
- .format(share.repo, element_name))
-
-
# Tests that:
#
# * `bst artifact push` fails if there are no remotes configured for pushing
diff --git a/tests/testutils/__init__.py b/tests/testutils/__init__.py
index 2e1f72138..9a904f007 100644
--- a/tests/testutils/__init__.py
+++ b/tests/testutils/__init__.py
@@ -23,7 +23,7 @@
# William Salmon <will.salmon@codethink.co.uk>
#
-from .artifactshare import create_artifact_share
+from .artifactshare import create_artifact_share, assert_shared, assert_not_shared
from .element_generators import create_element_size, update_element_size
from .junction import generate_junction
from .runner_integration import wait_for_cache_granularity
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index bc69a87d8..a5522c8eb 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -207,3 +207,19 @@ def create_artifact_share(directory, *, total_space=None, free_space=None,
statvfs_result = namedtuple('statvfs_result', 'f_blocks f_bfree f_bsize f_bavail')
+
+
+# Assert that a given artifact is in the share
+#
+def assert_shared(cli, share, project, element_name, *, project_name='test'):
+ if not share.has_artifact(cli.get_artifact_name(project, project_name, element_name)):
+ raise AssertionError("Artifact share at {} does not contain the expected element {}"
+ .format(share.repo, element_name))
+
+
+# Assert that a given artifact is not in the share
+#
+def assert_not_shared(cli, share, project, element_name, *, project_name='test'):
+ if share.has_artifact(cli.get_artifact_name(project, project_name, element_name)):
+ raise AssertionError("Artifact share at {} unexpectedly contains the element {}"
+ .format(share.repo, element_name))