summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Fazakas <alexandru.fazakas@codethink.co.uk>2019-06-25 17:42:38 +0100
committerAlexandru Fazakas <alexandru.fazakas@codethink.co.uk>2019-06-26 17:11:09 +0100
commitb4049f3426468c66a196db4c76119e72a2cd853f (patch)
tree5d216d55b5c8cb323ae3c32102badd9ea3069e83
parent52b418c2a872e05d992136d8500ba10aadebd579 (diff)
downloadbuildstream-AlexFazakas/add-directory-argument-bst-init.tar.gz
tests/frontend/init: Add directory argument testAlexFazakas/add-directory-argument-bst-init
Add a test for `bst init` using a directory as its target. Squash this
-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):