diff options
Diffstat (limited to 'tests/sourcecache/fetch.py')
-rw-r--r-- | tests/sourcecache/fetch.py | 47 |
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) |