summaryrefslogtreecommitdiff
path: root/tests/sources/bzr.py
blob: bf7d1e8440991fb6bcc4ca6680fe91a498333219 (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
import os
import pytest

from buildstream._pipeline import PipelineError
from buildstream import _yaml

from buildstream.plugintestutils import cli
from tests.testutils import create_repo
from tests.testutils.site import HAVE_BZR

DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'bzr'
)


@pytest.mark.skipif(HAVE_BZR is False, reason="bzr is not available")
@pytest.mark.datafiles(os.path.join(DATA_DIR))
def test_fetch_checkout(cli, tmpdir, datafiles):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    checkoutdir = os.path.join(str(tmpdir), 'checkout')

    repo = create_repo('bzr', str(tmpdir))
    ref = repo.create(os.path.join(project, 'basic'))

    # Write out our test target
    element = {
        'kind': 'import',
        'sources': [
            repo.source_config(ref=ref)
        ]
    }
    _yaml.dump(element, os.path.join(project, 'target.bst'))

    # Fetch, build, checkout
    result = cli.run(project=project, args=['source', 'fetch', 'target.bst'])
    assert result.exit_code == 0
    result = cli.run(project=project, args=['build', 'target.bst'])
    assert result.exit_code == 0
    result = cli.run(project=project, args=['artifact', 'checkout', 'target.bst', '--directory', checkoutdir])
    assert result.exit_code == 0

    # Assert we checked out the file as it was commited
    with open(os.path.join(checkoutdir, 'test')) as f:
        text = f.read()

    assert text == 'test\n'