summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-10-09 15:07:04 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-10-10 09:47:50 +0000
commitca3be36afb485e4fd17e8b50e730b2034cd15415 (patch)
tree5a92f5288c830fabcc43081c105d22369301ccd0
parent16cab3ae09a4ddab59e40975bdb656969a43e058 (diff)
downloadbuildstream-ca3be36afb485e4fd17e8b50e730b2034cd15415.tar.gz
tests/sourcecache/fetch.py: Extract element's creation to a function
All tests in this file use the same method for creating an element. It is easier to write new tests to have this factored out.
-rw-r--r--tests/sourcecache/fetch.py47
1 files changed, 17 insertions, 30 deletions
diff --git a/tests/sourcecache/fetch.py b/tests/sourcecache/fetch.py
index 35a222925..ad1fc3594 100644
--- a/tests/sourcecache/fetch.py
+++ b/tests/sourcecache/fetch.py
@@ -42,9 +42,24 @@ def move_local_cas_to_remote_source_share(local, remote):
shutil.rmtree(os.path.join(local, 'artifacts'))
+def create_test_element(tmpdir, project_dir):
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project_dir, 'files'))
+ element_path = os.path.join(project_dir, 'elements')
+ element_name = 'fetch.bst'
+ element = {
+ 'kind': 'import',
+ 'sources': [repo.source_config(ref=ref)]
+ }
+ _yaml.roundtrip_dump(element, os.path.join(element_path, element_name))
+
+ return element_name, repo, ref
+
+
@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)
# use artifact cache for sources for now, they should work the same
with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share:
@@ -63,16 +78,6 @@ def test_source_fetch(cli, tmpdir, datafiles):
_yaml.roundtrip_dump(user_config, file=user_config_file)
cli.configure(user_config)
- repo = create_repo('git', str(tmpdir))
- ref = repo.create(os.path.join(project_dir, 'files'))
- element_path = os.path.join(project_dir, 'elements')
- element_name = 'fetch.bst'
- element = {
- 'kind': 'import',
- 'sources': [repo.source_config(ref=ref)]
- }
- _yaml.roundtrip_dump(element, os.path.join(element_path, element_name))
-
with dummy_context(config=user_config_file) as context:
project = Project(project_dir, context)
project.ensure_fully_loaded()
@@ -115,6 +120,7 @@ def test_source_fetch(cli, tmpdir, datafiles):
@pytest.mark.datafiles(DATA_DIR)
def test_fetch_fallback(cli, tmpdir, datafiles):
project_dir = str(datafiles)
+ element_name, repo, ref = create_test_element(tmpdir, project_dir)
# use artifact cache for sources for now, they should work the same
with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share:
@@ -133,16 +139,6 @@ def test_fetch_fallback(cli, tmpdir, datafiles):
_yaml.roundtrip_dump(user_config, file=user_config_file)
cli.configure(user_config)
- repo = create_repo('git', str(tmpdir))
- ref = repo.create(os.path.join(project_dir, 'files'))
- element_path = os.path.join(project_dir, 'elements')
- element_name = 'fetch.bst'
- element = {
- 'kind': 'import',
- 'sources': [repo.source_config(ref=ref)]
- }
- _yaml.roundtrip_dump(element, os.path.join(element_path, element_name))
-
with dummy_context(config=user_config_file) as context:
project = Project(project_dir, context)
project.ensure_fully_loaded()
@@ -171,6 +167,7 @@ def test_fetch_fallback(cli, tmpdir, datafiles):
@pytest.mark.datafiles(DATA_DIR)
def test_pull_fail(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')
with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share:
@@ -187,16 +184,6 @@ def test_pull_fail(cli, tmpdir, datafiles):
_yaml.roundtrip_dump(user_config, file=user_config_file)
cli.configure(user_config)
- repo = create_repo('git', str(tmpdir))
- ref = repo.create(os.path.join(project_dir, 'files'))
- element_path = os.path.join(project_dir, 'elements')
- element_name = 'push.bst'
- element = {
- 'kind': 'import',
- 'sources': [repo.source_config(ref=ref)]
- }
- _yaml.roundtrip_dump(element, os.path.join(element_path, element_name))
-
# get the source object
with dummy_context(config=user_config_file) as context:
project = Project(project_dir, context)