summaryrefslogtreecommitdiff
path: root/tests/frontend/init.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/frontend/init.py')
-rw-r--r--tests/frontend/init.py51
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/frontend/init.py b/tests/frontend/init.py
index 0eac5d528..12cb39013 100644
--- a/tests/frontend/init.py
+++ b/tests/frontend/init.py
@@ -10,7 +10,6 @@ from buildstream._frontend.app import App
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream._versions import BST_FORMAT_VERSION
-
def test_defaults(cli, tmpdir):
project = str(tmpdir)
project_path = os.path.join(project, 'project.conf')
@@ -73,6 +72,56 @@ def test_force_overwrite_project(cli, tmpdir):
assert _yaml.node_get(project_conf, str, 'name') == 'foo'
assert _yaml.node_get(project_conf, str, 'format-version') == str(BST_FORMAT_VERSION)
+def test_empty_directory_as_argument(cli, tmpdir):
+ project = os.path.join(str(tmpdir), "empty-directory")
+ os.mkdir(project)
+ project_path = os.path.join(project, 'project.conf')
+
+ result = cli.run(project=project, args=['init', '--project-name', 'foo',
+ project])
+ result.assert_success()
+
+ project_conf = _yaml.load(project_path)
+ assert _yaml.node_get(project_conf, str, 'name') == 'foo'
+ assert _yaml.node_get(project_conf, str, 'format-version') == str(BST_FORMAT_VERSION)
+ assert _yaml.node_get(project_conf, str, 'element-path') == 'elements'
+
+def test_non_empty_directory_as_argument(cli, tmpdir):
+ project = str(tmpdir)
+ project_path = os.path.join(project, 'project.conf')
+
+ # This should fail because the tmpdir contains a 'cache' directory.
+ result = cli.run(project=project, args=['init', '--project-name', 'foo',
+ tmpdir])
+ result.assert_main_error(ErrorDomain.APP, 'directory-not-empty')
+
+def test_non_existing_directory_as_argument(cli, tmpdir):
+ project = str(os.path.join(str(tmpdir), "missing-directory"))
+ project_path = os.path.join(project, 'project.conf')
+
+ result = cli.run(project=project, args=['init', '--project-name', 'foo',
+ project])
+ result.assert_success()
+
+ project_conf = _yaml.load(project_path)
+ assert _yaml.node_get(project_conf, str, 'name') == 'foo'
+ assert _yaml.node_get(project_conf, str, 'format-version') == str(BST_FORMAT_VERSION)
+ assert _yaml.node_get(project_conf, str, 'element-path') == 'elements'
+
+def test_relative_path_directory_as_argument(cli, tmpdir):
+ project = os.path.join(str(tmpdir), 'child-directory')
+ os.mkdir(project)
+ project_path = os.path.join(project, 'project.conf')
+ relative_path = os.path.relpath(project)
+
+ result = cli.run(project=project, args=['init', '--project-name', 'foo',
+ relative_path])
+ result.assert_success()
+
+ project_conf = _yaml.load(project_path)
+ assert _yaml.node_get(project_conf, str, 'name') == 'foo'
+ assert _yaml.node_get(project_conf, str, 'format-version') == str(BST_FORMAT_VERSION)
+ assert _yaml.node_get(project_conf, str, 'element-path') == 'elements'
@pytest.mark.parametrize("project_name", [('Micheal Jackson'), ('one+one')])
def test_bad_project_name(cli, tmpdir, project_name):