summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-10-09 15:16:18 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-10-10 09:47:50 +0000
commitd71b8080ab009d7428cf99601f2e1aec50c76772 (patch)
tree48a6dd4accca3e4fe6bd681fd879615749d4b948
parentca3be36afb485e4fd17e8b50e730b2034cd15415 (diff)
downloadbuildstream-d71b8080ab009d7428cf99601f2e1aec50c76772.tar.gz
tests/sourcecache/fetch.py: Extract configuration of bst
Extract the configuration of the BuildStream cli as it is every time the same into a separate function. This helps seeing what is setup of the tests and what is the actual test itself.
-rw-r--r--tests/sourcecache/fetch.py74
1 files changed, 26 insertions, 48 deletions
diff --git a/tests/sourcecache/fetch.py b/tests/sourcecache/fetch.py
index ad1fc3594..8d6d5dcf4 100644
--- a/tests/sourcecache/fetch.py
+++ b/tests/sourcecache/fetch.py
@@ -19,6 +19,7 @@
#
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name
+from contextlib import contextmanager
import os
import shutil
import pytest
@@ -56,29 +57,34 @@ def create_test_element(tmpdir, project_dir):
return element_name, repo, ref
+@contextmanager
+def context_with_source_cache(cli, cache, share, tmpdir):
+ user_config_file = str(tmpdir.join('buildstream.conf'))
+ user_config = {
+ 'scheduler': {
+ 'pushers': 1
+ },
+ 'source-caches': {
+ 'url': share.repo,
+ },
+ 'cachedir': cache,
+ }
+ _yaml.roundtrip_dump(user_config, file=user_config_file)
+ cli.configure(user_config)
+
+ with dummy_context(config=user_config_file) as context:
+ yield context
+
+
@pytest.mark.datafiles(DATA_DIR)
def test_source_fetch(cli, tmpdir, datafiles):
project_dir = str(datafiles)
element_name, _repo, _ref = create_test_element(tmpdir, project_dir)
+ cache_dir = os.path.join(str(tmpdir), 'cache')
# use artifact cache for sources for now, they should work the same
with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share:
- # configure using this share
- cache_dir = os.path.join(str(tmpdir), 'cache')
- user_config_file = str(tmpdir.join('buildstream.conf'))
- user_config = {
- 'scheduler': {
- 'pushers': 1
- },
- 'source-caches': {
- 'url': share.repo,
- },
- 'cachedir': cache_dir,
- }
- _yaml.roundtrip_dump(user_config, file=user_config_file)
- cli.configure(user_config)
-
- with dummy_context(config=user_config_file) as context:
+ with context_with_source_cache(cli, cache_dir, share, tmpdir) as context:
project = Project(project_dir, context)
project.ensure_fully_loaded()
@@ -121,25 +127,11 @@ def test_source_fetch(cli, tmpdir, datafiles):
def test_fetch_fallback(cli, tmpdir, datafiles):
project_dir = str(datafiles)
element_name, repo, ref = create_test_element(tmpdir, project_dir)
+ cache_dir = os.path.join(str(tmpdir), 'cache')
# use artifact cache for sources for now, they should work the same
with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share:
- # configure using this share
- cache_dir = os.path.join(str(tmpdir), 'cache')
- user_config_file = str(tmpdir.join('buildstream.conf'))
- user_config = {
- 'scheduler': {
- 'pushers': 1
- },
- 'source-caches': {
- 'url': share.repo,
- },
- 'cachedir': cache_dir,
- }
- _yaml.roundtrip_dump(user_config, file=user_config_file)
- cli.configure(user_config)
-
- with dummy_context(config=user_config_file) as context:
+ with context_with_source_cache(cli, cache_dir, share, tmpdir) as context:
project = Project(project_dir, context)
project.ensure_fully_loaded()
@@ -171,21 +163,7 @@ def test_pull_fail(cli, tmpdir, datafiles):
cache_dir = os.path.join(str(tmpdir), 'cache')
with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share:
- user_config_file = str(tmpdir.join('buildstream.conf'))
- user_config = {
- 'scheduler': {
- 'pushers': 1
- },
- 'source-caches': {
- 'url': share.repo,
- },
- 'cachedir': cache_dir,
- }
- _yaml.roundtrip_dump(user_config, file=user_config_file)
- cli.configure(user_config)
-
- # get the source object
- with dummy_context(config=user_config_file) as context:
+ with context_with_source_cache(cli, cache_dir, share, tmpdir) as context:
project = Project(project_dir, context)
project.ensure_fully_loaded()
@@ -197,7 +175,7 @@ def test_pull_fail(cli, tmpdir, datafiles):
shutil.rmtree(repo.repo)
# Should fail in stream, with a plugin task causing the error
- res = cli.run(project=project_dir, args=['build', 'push.bst'])
+ res = cli.run(project=project_dir, args=['build', element_name])
res.assert_main_error(ErrorDomain.STREAM, None)
res.assert_task_error(ErrorDomain.PLUGIN, None)
assert "Remote source service ({}) does not have source {} cached".format(