summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <chandan@chandansingh.net>2019-11-12 00:47:14 +0000
committerChandan Singh <chandan@chandansingh.net>2019-12-05 13:46:40 +0000
commit23423f6bd1572003fbb1af571bf9a9758abdd79c (patch)
treec8be208544ec12ff78f5cc696861cfd3406406a8
parentb0375014d5c97c484b6704b87140355de3d7701a (diff)
downloadbuildstream-23423f6bd1572003fbb1af571bf9a9758abdd79c.tar.gz
Add tests for interactive `bst init`
Add tests for interactive `bst init` command using [pexpect](https://pexpect.readthedocs.io).
-rw-r--r--tests/frontend/interactive_init.py34
-rw-r--r--tests/testutils/constants.py15
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/frontend/interactive_init.py b/tests/frontend/interactive_init.py
new file mode 100644
index 000000000..c8f169000
--- /dev/null
+++ b/tests/frontend/interactive_init.py
@@ -0,0 +1,34 @@
+import os
+
+import pexpect
+from ruamel import yaml
+
+from buildstream._versions import BST_FORMAT_VERSION
+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"
+ format_version = 24
+ element_path = "my-elements"
+
+ session.expect_exact("Project name:")
+ session.sendline(name)
+
+ session.expect_exact("Format version [{}]:".format(BST_FORMAT_VERSION))
+ session.sendline(str(format_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
+ with open(os.path.join(str(tmpdir), "project.conf")) as f:
+ project_conf = yaml.safe_load(f)
+
+ assert project_conf["name"] == name
+ assert project_conf["format-version"] == format_version
+ assert project_conf["element-path"] == element_path
diff --git a/tests/testutils/constants.py b/tests/testutils/constants.py
new file mode 100644
index 000000000..e14624143
--- /dev/null
+++ b/tests/testutils/constants.py
@@ -0,0 +1,15 @@
+# Constants used during BuildStream tests.
+
+
+# Timeout for short interactive operations (in seconds).
+#
+# Use this for operations that are expected to finish within a short amount of
+# time. Like `bst init`, `bst show` on a small project.
+PEXPECT_TIMEOUT_SHORT = 5
+
+
+# Timeout for longer interactive operations (in seconds).
+#
+# Use this for operations that are expected to take longer amounts of time,
+# like `bst build` on a small project.
+PEXPECT_TIMEOUT_LONG = 60