summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-08 21:31:02 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-08 21:57:01 +0900
commit337b7a31c244241f722a5ff709d23df75a021eb9 (patch)
tree7947e947384c77a33dccd1cdd639bc7cad98be89
parent5de991914fa4ae573e1648eccd8c8e76c3c5a141 (diff)
downloadbuildstream-337b7a31c244241f722a5ff709d23df75a021eb9.tar.gz
tests/frontend/init.py: New test to test edge cases for new `bst init` command.
-rw-r--r--tests/frontend/init.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/frontend/init.py b/tests/frontend/init.py
new file mode 100644
index 000000000..be7415cf0
--- /dev/null
+++ b/tests/frontend/init.py
@@ -0,0 +1,97 @@
+import os
+import pytest
+from tests.testutils import cli
+
+from buildstream import _yaml
+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')
+
+ result = cli.run(project=project, args=['init', '--project-name', 'foo'])
+ result.assert_success()
+
+ project_conf = _yaml.load(project_path)
+ assert project_conf['name'] == 'foo'
+ assert project_conf['format-version'] == str(BST_FORMAT_VERSION)
+ assert project_conf['element-path'] == 'elements'
+
+
+def test_all_options(cli, tmpdir):
+ project = str(tmpdir)
+ project_path = os.path.join(project, 'project.conf')
+
+ result = cli.run(project=project, args=[
+ 'init',
+ '--project-name', 'foo',
+ '--format-version', '2',
+ '--element-path', 'ponies',
+ ])
+ result.assert_success()
+
+ project_conf = _yaml.load(project_path)
+ assert project_conf['name'] == 'foo'
+ assert project_conf['format-version'] == str(2)
+ assert project_conf['element-path'] == 'ponies'
+
+
+def test_no_project_name(cli, tmpdir):
+ result = cli.run(project=str(tmpdir), args=['init'])
+ result.assert_main_error(ErrorDomain.APP, 'unspecified-project-name')
+
+
+def test_project_exists(cli, tmpdir):
+ project = str(tmpdir)
+ project_path = os.path.join(project, 'project.conf')
+ with open(project_path, 'w') as f:
+ f.write('name: pony\n')
+
+ result = cli.run(project=project, args=['init', '--project-name', 'foo'])
+ result.assert_main_error(ErrorDomain.APP, 'project-exists')
+
+
+def test_force_overwrite_project(cli, tmpdir):
+ project = str(tmpdir)
+ project_path = os.path.join(project, 'project.conf')
+ with open(project_path, 'w') as f:
+ f.write('name: pony\n')
+
+ result = cli.run(project=project, args=['init', '--project-name', 'foo', '--force'])
+ result.assert_success()
+
+ project_conf = _yaml.load(project_path)
+ assert project_conf['name'] == 'foo'
+ assert project_conf['format-version'] == str(BST_FORMAT_VERSION)
+
+
+@pytest.mark.parametrize("project_name", [('Micheal Jackson'), ('one+one')])
+def test_bad_project_name(cli, tmpdir, project_name):
+ result = cli.run(project=str(tmpdir), args=['init', '--project-name', project_name])
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_SYMBOL_NAME)
+
+
+@pytest.mark.parametrize("format_version", [(str(-1)), (str(BST_FORMAT_VERSION + 1))])
+def test_bad_format_version(cli, tmpdir, format_version):
+ result = cli.run(project=str(tmpdir), args=[
+ 'init', '--project-name', 'foo', '--format-version', format_version
+ ])
+ result.assert_main_error(ErrorDomain.APP, 'invalid-format-version')
+
+
+@pytest.mark.parametrize("element_path", [('/absolute/path'), ('../outside/of/project')])
+def test_bad_element_path(cli, tmpdir, element_path):
+ result = cli.run(project=str(tmpdir), args=[
+ 'init', '--project-name', 'foo', '--element-path', element_path
+ ])
+ result.assert_main_error(ErrorDomain.APP, 'invalid-element-path')
+
+
+@pytest.mark.parametrize("element_path", [('/absolute/path'), ('../outside/of/project')])
+def test_bad_element_path(cli, tmpdir, element_path):
+ result = cli.run(project=str(tmpdir), args=[
+ 'init', '--project-name', 'foo', '--element-path', element_path
+ ])
+ result.assert_main_error(ErrorDomain.APP, 'invalid-element-path')