summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-05 21:29:29 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-10 19:29:59 +0900
commit110396429bd972536217fa5b1a8603db1a950b22 (patch)
tree7dcac1349497237533fc730893f5c03dbe77601e
parentfaa8b765ede18c4872e181e8252db3f67988944a (diff)
downloadbuildstream-110396429bd972536217fa5b1a8603db1a950b22.tar.gz
tests/format/optionbool.py: Added boolean option specific test cases
-rw-r--r--tests/format/option-bool/element-equals.bst6
-rw-r--r--tests/format/option-bool/element-not-equals.bst6
-rw-r--r--tests/format/option-bool/element-not.bst6
-rw-r--r--tests/format/option-bool/element.bst6
-rw-r--r--tests/format/option-bool/project.conf7
-rw-r--r--tests/format/optionbool.py115
6 files changed, 146 insertions, 0 deletions
diff --git a/tests/format/option-bool/element-equals.bst b/tests/format/option-bool/element-equals.bst
new file mode 100644
index 000000000..78e02c105
--- /dev/null
+++ b/tests/format/option-bool/element-equals.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ thepony: "not pony"
+ (?):
+ - pony == True:
+ thepony: "a pony"
diff --git a/tests/format/option-bool/element-not-equals.bst b/tests/format/option-bool/element-not-equals.bst
new file mode 100644
index 000000000..8d35a3c4b
--- /dev/null
+++ b/tests/format/option-bool/element-not-equals.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ thepony: "a pony"
+ (?):
+ - pony != True:
+ thepony: "not pony"
diff --git a/tests/format/option-bool/element-not.bst b/tests/format/option-bool/element-not.bst
new file mode 100644
index 000000000..e0ff03b8c
--- /dev/null
+++ b/tests/format/option-bool/element-not.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ thepony: "a pony"
+ (?):
+ - not pony:
+ thepony: "not pony"
diff --git a/tests/format/option-bool/element.bst b/tests/format/option-bool/element.bst
new file mode 100644
index 000000000..24ad102c6
--- /dev/null
+++ b/tests/format/option-bool/element.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ thepony: "not pony"
+ (?):
+ - pony:
+ thepony: "a pony"
diff --git a/tests/format/option-bool/project.conf b/tests/format/option-bool/project.conf
new file mode 100644
index 000000000..a51c4fcbe
--- /dev/null
+++ b/tests/format/option-bool/project.conf
@@ -0,0 +1,7 @@
+name: test
+
+options:
+ pony:
+ type: bool
+ description: Whether a pony or not
+ default: False
diff --git a/tests/format/optionbool.py b/tests/format/optionbool.py
new file mode 100644
index 000000000..a02ec742e
--- /dev/null
+++ b/tests/format/optionbool.py
@@ -0,0 +1,115 @@
+import os
+import pytest
+from buildstream import _yaml
+from buildstream import LoadError, LoadErrorReason
+from tests.testutils.runcli import cli
+
+# Project directory
+DATA_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("target,option,expected", [
+ # Test 'foo' syntax, and valid values of 'True' / 'False'
+ ('element.bst', 'True', 'a pony'),
+ ('element.bst', 'true', 'a pony'),
+ ('element.bst', 'False', 'not pony'),
+ ('element.bst', 'false', 'not pony'),
+
+ # Test 'not foo' syntax
+ ('element-not.bst', 'False', 'not pony'),
+ ('element-not.bst', 'True', 'a pony'),
+
+ # Test 'foo == True' syntax
+ ('element-equals.bst', 'False', 'not pony'),
+ ('element-equals.bst', 'True', 'a pony'),
+
+ # Test 'foo != True' syntax
+ ('element-not-equals.bst', 'False', 'not pony'),
+ ('element-not-equals.bst', 'True', 'a pony'),
+])
+def test_conditional_cli(cli, datafiles, target, option, expected):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-bool')
+ result = cli.run(project=project, silent=True, args=[
+ '--option', 'pony', option,
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ target])
+
+ assert result.exit_code == 0
+ loaded = _yaml.load_data(result.output)
+ assert loaded['thepony'] == expected
+
+
+# Test configuration of boolean option in the config file
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("target,option,expected", [
+ ('element.bst', True, 'a pony'),
+ ('element.bst', False, 'not pony'),
+])
+def test_conditional_config(cli, datafiles, target, option, expected):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-bool')
+ cli.configure({
+ 'projects': {
+ 'test': {
+ 'options': {
+ 'pony': option
+ }
+ }
+ }
+ })
+ result = cli.run(project=project, silent=True, args=[
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ target])
+
+ assert result.exit_code == 0
+ loaded = _yaml.load_data(result.output)
+ assert loaded['thepony'] == expected
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("cli_option", [
+ ('falsey'), ('pony'), ('trUE')
+])
+def test_invalid_value_cli(cli, datafiles, cli_option):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-bool')
+ result = cli.run(project=project, silent=True, args=[
+ '--option', 'pony', cli_option,
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ 'element.bst'])
+ assert result.exit_code != 0
+ assert result.exception
+ assert isinstance(result.exception, LoadError)
+ assert result.exception.reason == LoadErrorReason.INVALID_DATA
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("config_option", [
+ ('pony'), (['its', 'a', 'list']), ({'dic': 'tionary'})
+])
+def test_invalid_value_config(cli, datafiles, config_option):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-bool')
+ cli.configure({
+ 'projects': {
+ 'test': {
+ 'options': {
+ 'pony': config_option
+ }
+ }
+ }
+ })
+ result = cli.run(project=project, silent=True, args=[
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ 'element.bst'])
+ assert result.exit_code != 0
+ assert result.exception
+ assert isinstance(result.exception, LoadError)
+ assert result.exception.reason == LoadErrorReason.INVALID_DATA