summaryrefslogtreecommitdiff
path: root/tests/sources/no_fetch_cached.py
blob: 69d28615a9cb4de65df33a3b224ac3a7ef39fa85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name

import os
import pytest

from buildstream import _yaml

from buildstream.testing import cli  # pylint: disable=unused-import
from buildstream.testing import create_repo
from tests.testutils.site import HAVE_GIT

DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'no-fetch-cached'
)


##################################################################
#                              Tests                             #
##################################################################
# Test that fetch() is not called for cached sources
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(DATA_DIR)
def test_no_fetch_cached(cli, tmpdir, datafiles):
    project = str(datafiles)

    # Create the repo from 'files' subdir
    repo = create_repo('git', str(tmpdir))
    ref = repo.create(os.path.join(project, 'files'))

    # Write out test target with a cached and a non-cached source
    element = {
        'kind': 'import',
        'sources': [
            repo.source_config(ref=ref),
            {
                'kind': 'always_cached'
            }
        ]
    }
    _yaml.dump(element, os.path.join(project, 'target.bst'))

    # Test fetch of target with a cached and a non-cached source
    result = cli.run(project=project, args=[
        'source', 'fetch', 'target.bst'
    ])
    result.assert_success()