summaryrefslogtreecommitdiff
path: root/tests/frontend/interactive_init.py
blob: b8cbe522fb89c902f4928f7f3856887840e7a84b (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
import os

import pexpect

from buildstream import _yaml
from buildstream import utils
from tests.testutils.constants import PEXPECT_TIMEOUT_SHORT


def test_init(tmpdir):
    session = pexpect.spawn("bst", ["--no-colors", "init", str(tmpdir)], timeout=PEXPECT_TIMEOUT_SHORT)
    name = "test-project"
    min_version = "2.0"
    element_path = "my-elements"
    bst_major, bst_minor = utils.get_bst_version()

    # For the version check, artificially set the version to at least
    # version 2.0
    #
    # TODO: Remove this code block after releasing 2.0
    #
    if bst_major < 2:
        bst_major = 2
        bst_minor = 0

    session.expect_exact("Project name:")
    session.sendline(name)

    session.expect_exact("Minimum version [{}.{}]:".format(bst_major, bst_minor))
    session.sendline(str(min_version))

    session.expect_exact("Element path [elements]:")
    session.sendline(element_path)

    session.expect_exact("Created project.conf")
    session.close()

    # Now assert that a project.conf got created with expected values
    project_conf = _yaml.load(os.path.join(str(tmpdir), "project.conf"))
    assert project_conf.get_str("name") == name
    assert project_conf.get_str("min-version") == min_version
    assert project_conf.get_str("element-path") == element_path