summaryrefslogtreecommitdiff
path: root/tests/format
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-01-01 18:30:46 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-01-01 19:44:53 +0900
commitc1b3a483d17337b45c9118ba2580437a89db2271 (patch)
treea17e94b198ec0946cb655e0a76b149d1ac854100 /tests/format
parent6989b44392ed34d0a910e276ebdc9084cbd3fa09 (diff)
downloadbuildstream-c1b3a483d17337b45c9118ba2580437a89db2271.tar.gz
tests/format: Use new error assertions all around
Diffstat (limited to 'tests/format')
-rw-r--r--tests/format/assertion.py8
-rw-r--r--tests/format/listdirectiveerrors.py17
-rw-r--r--tests/format/optionarch.py9
-rw-r--r--tests/format/optionbool.py16
-rw-r--r--tests/format/optioneltmask.py16
-rw-r--r--tests/format/optionenum.py21
-rw-r--r--tests/format/optionexports.py2
-rw-r--r--tests/format/optionflags.py21
-rw-r--r--tests/format/options.py45
-rw-r--r--tests/format/project.py13
-rw-r--r--tests/format/projectoverrides.py2
11 files changed, 50 insertions, 120 deletions
diff --git a/tests/format/assertion.py b/tests/format/assertion.py
index e2c4d7d23..42f69b759 100644
--- a/tests/format/assertion.py
+++ b/tests/format/assertion.py
@@ -1,6 +1,6 @@
import os
import pytest
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -28,11 +28,7 @@ def test_assertion_cli(cli, datafiles, target, opt_pony, opt_horsy, assertion):
'--deps', 'none',
'--format', '%{vars}',
target])
-
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.USER_ASSERTION
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.USER_ASSERTION)
# Assert that the assertion text provided by the user
# is found in the exception text
diff --git a/tests/format/listdirectiveerrors.py b/tests/format/listdirectiveerrors.py
index c069f3764..4a2de86fc 100644
--- a/tests/format/listdirectiveerrors.py
+++ b/tests/format/listdirectiveerrors.py
@@ -1,6 +1,6 @@
import os
import pytest
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -16,10 +16,7 @@ def test_project_error(cli, datafiles):
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.TRAILING_LIST_DIRECTIVE
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.TRAILING_LIST_DIRECTIVE)
@pytest.mark.datafiles(DATA_DIR)
@@ -34,10 +31,7 @@ def test_element_error(cli, datafiles, target):
'--format', '%{vars}',
target])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.TRAILING_LIST_DIRECTIVE
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.TRAILING_LIST_DIRECTIVE)
@pytest.mark.datafiles(DATA_DIR)
@@ -49,7 +43,4 @@ def test_project_error(cli, datafiles):
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.ILLEGAL_COMPOSITE
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.ILLEGAL_COMPOSITE)
diff --git a/tests/format/optionarch.py b/tests/format/optionarch.py
index 5d28b83f2..4c126aa87 100644
--- a/tests/format/optionarch.py
+++ b/tests/format/optionarch.py
@@ -2,7 +2,7 @@ import os
import pytest
from contextlib import contextmanager
from buildstream import _yaml
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -56,8 +56,8 @@ def test_conditional(cli, datafiles, uname, value, expected):
'element.bst'
]
result = cli.run(project=project, silent=True, args=bst_args)
+ result.assert_success()
- assert result.exit_code == 0
loaded = _yaml.load_data(result.output)
assert loaded['result'] == expected
@@ -74,7 +74,4 @@ def test_unsupported_arch(cli, datafiles):
'element.bst'
])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.INVALID_DATA
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
diff --git a/tests/format/optionbool.py b/tests/format/optionbool.py
index 3c33a8713..f02f0eee3 100644
--- a/tests/format/optionbool.py
+++ b/tests/format/optionbool.py
@@ -1,7 +1,7 @@
import os
import pytest
from buildstream import _yaml
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -36,8 +36,8 @@ def test_conditional_cli(cli, datafiles, target, option, expected):
'--deps', 'none',
'--format', '%{vars}',
target])
+ result.assert_success()
- assert result.exit_code == 0
loaded = _yaml.load_data(result.output)
assert loaded['thepony'] == expected
@@ -65,8 +65,8 @@ def test_conditional_config(cli, datafiles, target, option, expected):
'--deps', 'none',
'--format', '%{vars}',
target])
+ result.assert_success()
- assert result.exit_code == 0
loaded = _yaml.load_data(result.output)
assert loaded['thepony'] == expected
@@ -83,10 +83,7 @@ def test_invalid_value_cli(cli, datafiles, cli_option):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -109,7 +106,4 @@ def test_invalid_value_config(cli, datafiles, config_option):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
diff --git a/tests/format/optioneltmask.py b/tests/format/optioneltmask.py
index 84c594772..b49eee88a 100644
--- a/tests/format/optioneltmask.py
+++ b/tests/format/optioneltmask.py
@@ -1,7 +1,7 @@
import os
import pytest
from buildstream import _yaml
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -23,7 +23,7 @@ def test_conditional_cli(cli, datafiles, target, value, expected):
'--format', '%{vars}',
target])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['debug'] == expected
@@ -51,7 +51,7 @@ def test_conditional_config(cli, datafiles, target, value, expected):
'--format', '%{vars}',
target])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['debug'] == expected
@@ -65,10 +65,7 @@ def test_invalid_declaration(cli, datafiles):
'--format', '%{vars}',
'pony.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.INVALID_DATA
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -81,7 +78,4 @@ def test_invalid_value(cli, datafiles):
'--format', '%{vars}',
'pony.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.INVALID_DATA
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
diff --git a/tests/format/optionenum.py b/tests/format/optionenum.py
index 19dd3d4af..6990ad915 100644
--- a/tests/format/optionenum.py
+++ b/tests/format/optionenum.py
@@ -1,7 +1,7 @@
import os
import pytest
from buildstream import _yaml
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -28,7 +28,7 @@ def test_conditional_cli(cli, datafiles, target, option, value, expected):
'--format', '%{vars}',
target])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['result'] == expected
@@ -61,7 +61,7 @@ def test_conditional_config(cli, datafiles, target, option, value, expected):
'--format', '%{vars}',
target])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['result'] == expected
@@ -75,10 +75,7 @@ def test_invalid_value_cli(cli, datafiles):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -101,10 +98,7 @@ def test_invalid_value_config(cli, datafiles, config_option):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -115,7 +109,4 @@ def test_missing_values(cli, datafiles):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
diff --git a/tests/format/optionexports.py b/tests/format/optionexports.py
index 9b009774d..26eadc677 100644
--- a/tests/format/optionexports.py
+++ b/tests/format/optionexports.py
@@ -31,6 +31,6 @@ def test_export(cli, datafiles, option_name, option_value, var_name, var_value):
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded[var_name] == var_value
diff --git a/tests/format/optionflags.py b/tests/format/optionflags.py
index de48ab9d1..3585f5ea5 100644
--- a/tests/format/optionflags.py
+++ b/tests/format/optionflags.py
@@ -1,7 +1,7 @@
import os
import pytest
from buildstream import _yaml
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -34,7 +34,7 @@ def test_conditional_cli(cli, datafiles, target, option, value, expected):
'--format', '%{vars}',
target])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['result'] == expected
@@ -64,7 +64,7 @@ def test_conditional_config(cli, datafiles, target, option, value, expected):
'--format', '%{vars}',
target])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['result'] == expected
@@ -82,10 +82,7 @@ def test_invalid_value_cli(cli, datafiles, cli_option):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -110,10 +107,7 @@ def test_invalid_value_config(cli, datafiles, config_option):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -124,7 +118,4 @@ def test_missing_values(cli, datafiles):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
diff --git a/tests/format/options.py b/tests/format/options.py
index 1cfea7c71..9408ae5cc 100644
--- a/tests/format/options.py
+++ b/tests/format/options.py
@@ -1,7 +1,7 @@
import os
import pytest
from buildstream import _yaml
-from buildstream._exceptions import LoadError, LoadErrorReason
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
# Project directory
@@ -22,10 +22,7 @@ def test_invalid_option_type(cli, datafiles):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -39,10 +36,7 @@ def test_invalid_option_cli(cli, datafiles):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -62,10 +56,7 @@ def test_invalid_option_config(cli, datafiles):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -76,10 +67,7 @@ def test_invalid_expression(cli, datafiles):
'--deps', 'none',
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.EXPRESSION_FAILED
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.EXPRESSION_FAILED)
@pytest.mark.datafiles(DATA_DIR)
@@ -90,11 +78,7 @@ def test_undefined(cli, datafiles):
'--deps', 'none',
'--format', '%{vars}',
'element.bst'])
-
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.EXPRESSION_FAILED
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.EXPRESSION_FAILED)
@pytest.mark.datafiles(DATA_DIR)
@@ -105,10 +89,7 @@ def test_invalid_condition(cli, datafiles):
'--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
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -126,7 +107,7 @@ def test_simple_conditional(cli, datafiles, opt_option, expected_prefix):
'--deps', 'none',
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['prefix'] == expected_prefix
@@ -149,7 +130,7 @@ def test_nested_conditional(cli, datafiles, debug, logging, expected):
'--deps', 'none',
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['debug'] == expected
@@ -172,7 +153,7 @@ def test_compound_and_conditional(cli, datafiles, debug, logging, expected):
'--deps', 'none',
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['debug'] == expected
@@ -195,7 +176,7 @@ def test_compound_or_conditional(cli, datafiles, debug, logging, expected):
'--deps', 'none',
'--format', '%{vars}',
'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
assert loaded['logging'] == expected
@@ -213,7 +194,7 @@ def test_deep_nesting_level1(cli, datafiles, option, expected):
'--deps', 'none',
'--format', '%{public}',
'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
shallow_list = loaded['shallow-nest']
first_dict = shallow_list[0]
@@ -234,7 +215,7 @@ def test_deep_nesting_level2(cli, datafiles, option, expected):
'--deps', 'none',
'--format', '%{public}',
'element-deeper.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
shallow_list = loaded['deep-nest']
deeper_list = shallow_list[0]
diff --git a/tests/format/project.py b/tests/format/project.py
index e06e842e5..eab67bcdd 100644
--- a/tests/format/project.py
+++ b/tests/format/project.py
@@ -1,7 +1,7 @@
import os
import pytest
from buildstream import _yaml
-from buildstream._exceptions import LoadError, LoadErrorReason, PluginError
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils.runcli import cli
@@ -17,7 +17,7 @@ def test_project_plugin_load_allowed(cli, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename, 'plugin-allowed')
result = cli.run(project=project, silent=True, args=[
'show', 'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
@@ -25,9 +25,7 @@ def test_project_plugin_load_forbidden(cli, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename, 'plugin-forbidden')
result = cli.run(project=project, silent=True, args=[
'show', 'element.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, PluginError)
+ result.assert_main_error(ErrorDomain.PLUGIN, None)
@pytest.mark.datafiles(DATA_DIR)
@@ -35,7 +33,4 @@ def test_project_conf_duplicate_plugins(cli, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename, 'duplicate-plugins')
result = cli.run(project=project, silent=True, args=[
'show', 'element.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.INVALID_YAML
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_YAML)
diff --git a/tests/format/projectoverrides.py b/tests/format/projectoverrides.py
index 13bce6373..d63b0a23d 100644
--- a/tests/format/projectoverrides.py
+++ b/tests/format/projectoverrides.py
@@ -20,7 +20,7 @@ def test_prepend_configure_commands(cli, datafiles):
'--format', '%{config}',
'element.bst'])
- assert result.exit_code == 0
+ result.assert_success()
loaded = _yaml.load_data(result.output)
config_commands = loaded['configure-commands']
assert len(config_commands) == 3