summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorctolentino8 <ctolentino8@bloomberg.net>2018-10-26 11:29:06 +0100
committerchiaratolentino <ctolentino8@bloomberg.net>2018-10-31 11:36:46 +0000
commit516e990e94a29dbd0f250f6219937af15fccd1d1 (patch)
tree881b3eae1534339d9cb01b7e896d30862813cedf
parentc7ac7e7d70e9a0a266c935505696c23f8c23f244 (diff)
downloadbuildstream-chiaratolentino/bst-init-interactive-elementpath.tar.gz
_frontend/app.py: Set correct element-path in interactive bst-initchiaratolentino/bst-init-interactive-elementpath
-rw-r--r--buildstream/_frontend/app.py2
-rw-r--r--tests/frontend/init.py32
2 files changed, 33 insertions, 1 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index 87db8076a..6b292a44a 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -305,7 +305,6 @@ class App():
directory = self._main_options['directory']
directory = os.path.abspath(directory)
project_path = os.path.join(directory, 'project.conf')
- elements_path = os.path.join(directory, element_path)
try:
# Abort if the project.conf already exists, unless `--force` was specified in `bst init`
@@ -335,6 +334,7 @@ class App():
raise AppError("Error creating project directory {}: {}".format(directory, e)) from e
# Create the elements sub-directory if it doesnt exist
+ elements_path = os.path.join(directory, element_path)
try:
os.makedirs(elements_path, exist_ok=True)
except IOError as e:
diff --git a/tests/frontend/init.py b/tests/frontend/init.py
index 8955ae395..f6e7dd68a 100644
--- a/tests/frontend/init.py
+++ b/tests/frontend/init.py
@@ -3,6 +3,7 @@ import pytest
from tests.testutils import cli
from buildstream import _yaml
+from buildstream._frontend.app import App
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream._versions import BST_FORMAT_VERSION
@@ -98,3 +99,34 @@ def test_bad_element_path(cli, tmpdir, element_path):
'init', '--project-name', 'foo', '--element-path', element_path
])
result.assert_main_error(ErrorDomain.APP, 'invalid-element-path')
+
+
+@pytest.mark.parametrize("element_path", [('foo'), ('foo/bar')])
+def test_element_path_interactive(cli, tmp_path, monkeypatch, element_path):
+ project = tmp_path
+ project_conf_path = project.joinpath('project.conf')
+
+ class DummyInteractiveApp(App):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.interactive = True
+
+ @classmethod
+ def create(cls, *args, **kwargs):
+ return DummyInteractiveApp(*args, **kwargs)
+
+ def _init_project_interactive(self, *args, **kwargs):
+ return ('project_name', '0', element_path)
+
+ monkeypatch.setattr(App, 'create', DummyInteractiveApp.create)
+
+ result = cli.run(project=str(project), args=['init'])
+ result.assert_success()
+
+ full_element_path = project.joinpath(element_path)
+ assert full_element_path.exists()
+
+ project_conf = _yaml.load(str(project_conf_path))
+ assert project_conf['name'] == 'project_name'
+ assert project_conf['format-version'] == '0'
+ assert project_conf['element-path'] == element_path