diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-11 14:37:39 -0500 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-16 18:35:21 -0500 |
commit | 561eddf11138ad8dee95f72ee78e92ae792a3ebe (patch) | |
tree | aa9e8d0e22377da135a7e240b7857aad6dd89a09 | |
parent | aa997450e889ddfba4a1768ecd9c00e16c6e0f10 (diff) | |
download | buildstream-561eddf11138ad8dee95f72ee78e92ae792a3ebe.tar.gz |
tests: Migrate protected variable handling tests to tests/format/variables.py
-rw-r--r-- | tests/format/variables.py | 92 | ||||
-rw-r--r-- | tests/format/variables/protected-vars/foo.txt (renamed from tests/loader/variables/simple/foo.txt) | 0 | ||||
-rw-r--r-- | tests/format/variables/protected-vars/project.conf (renamed from tests/loader/variables/simple/project.conf) | 0 | ||||
-rw-r--r-- | tests/loader/variables.py | 99 |
4 files changed, 89 insertions, 102 deletions
diff --git a/tests/format/variables.py b/tests/format/variables.py index 46e22d0e6..be7faefc5 100644 --- a/tests/format/variables.py +++ b/tests/format/variables.py @@ -12,6 +12,14 @@ DATA_DIR = os.path.join( "variables" ) +# List of BuildStream protected variables +PROTECTED_VARIABLES = [('project-name'), ('element-name'), ('max-jobs')] + + +def print_warning(msg): + RED, END = "\033[91m", "\033[0m" + print(("\n{}{}{}").format(RED, msg, END), file=sys.stderr) + ############################################################### # Test proper loading of some default commands from plugins # @@ -87,6 +95,84 @@ def test_cyclic_variables(cli, datafiles): result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.RECURSIVE_VARIABLE) -def print_warning(msg): - RED, END = "\033[91m", "\033[0m" - print(("\n{}{}{}").format(RED, msg, END), file=sys.stderr) +@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'protected-vars')) +def test_use_of_protected_var_project_conf(cli, tmpdir, datafiles, protected_var): + project = str(datafiles) + conf = { + 'name': 'test', + 'variables': { + protected_var: 'some-value' + } + } + _yaml.dump(conf, os.path.join(project, 'project.conf')) + + element = { + 'kind': 'import', + 'sources': [ + { + 'kind': 'local', + 'path': 'foo.txt' + } + ], + } + _yaml.dump(element, os.path.join(project, 'target.bst')) + + result = cli.run(project=project, args=['build', 'target.bst']) + result.assert_main_error(ErrorDomain.LOAD, + LoadErrorReason.PROTECTED_VARIABLE_REDEFINED) + + +@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'protected-vars')) +def test_use_of_protected_var_element_overrides(cli, tmpdir, datafiles, protected_var): + project = str(datafiles) + conf = { + 'name': 'test', + 'elements': { + 'manual': { + 'variables': { + protected_var: 'some-value' + } + } + } + } + _yaml.dump(conf, os.path.join(project, 'project.conf')) + + element = { + 'kind': 'manual', + 'sources': [ + { + 'kind': 'local', + 'path': 'foo.txt' + } + ], + } + _yaml.dump(element, os.path.join(project, 'target.bst')) + + result = cli.run(project=project, args=['build', 'target.bst']) + result.assert_main_error(ErrorDomain.LOAD, + LoadErrorReason.PROTECTED_VARIABLE_REDEFINED) + + +@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'protected-vars')) +def test_use_of_protected_var_in_element(cli, tmpdir, datafiles, protected_var): + project = str(datafiles) + element = { + 'kind': 'import', + 'sources': [ + { + 'kind': 'local', + 'path': 'foo.txt' + } + ], + 'variables': { + protected_var: 'some-value' + } + } + _yaml.dump(element, os.path.join(project, 'target.bst')) + + result = cli.run(project=project, args=['build', 'target.bst']) + result.assert_main_error(ErrorDomain.LOAD, + LoadErrorReason.PROTECTED_VARIABLE_REDEFINED) diff --git a/tests/loader/variables/simple/foo.txt b/tests/format/variables/protected-vars/foo.txt index 257cc5642..257cc5642 100644 --- a/tests/loader/variables/simple/foo.txt +++ b/tests/format/variables/protected-vars/foo.txt diff --git a/tests/loader/variables/simple/project.conf b/tests/format/variables/protected-vars/project.conf index 5a240e3ed..5a240e3ed 100644 --- a/tests/loader/variables/simple/project.conf +++ b/tests/format/variables/protected-vars/project.conf diff --git a/tests/loader/variables.py b/tests/loader/variables.py deleted file mode 100644 index 9871d63c6..000000000 --- a/tests/loader/variables.py +++ /dev/null @@ -1,99 +0,0 @@ -import os -import pytest - -from buildstream import _yaml -from buildstream._exceptions import ErrorDomain, LoadErrorReason -from tests.testutils import cli - -DATA_DIR = os.path.join( - os.path.dirname(os.path.realpath(__file__)), - 'variables', -) - -PROTECTED_VARIABLES = [('project-name'), ('element-name'), ('max-jobs')] - - -@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) -@pytest.mark.datafiles(DATA_DIR) -def test_use_of_protected_var_project_conf(cli, tmpdir, datafiles, protected_var): - project = os.path.join(str(datafiles), 'simple') - - conf = { - 'name': 'test', - 'variables': { - protected_var: 'some-value' - } - } - _yaml.dump(conf, os.path.join(project, 'project.conf')) - - element = { - 'kind': 'import', - 'sources': [ - { - 'kind': 'local', - 'path': 'foo.txt' - } - ], - } - _yaml.dump(element, os.path.join(project, 'target.bst')) - - result = cli.run(project=project, args=['build', 'target.bst']) - result.assert_main_error(ErrorDomain.LOAD, - LoadErrorReason.PROTECTED_VARIABLE_REDEFINED) - - -@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) -@pytest.mark.datafiles(DATA_DIR) -def test_use_of_protected_var_element_overrides(cli, tmpdir, datafiles, protected_var): - project = os.path.join(str(datafiles), 'simple') - - conf = { - 'name': 'test', - 'elements': { - 'manual': { - 'variables': { - protected_var: 'some-value' - } - } - } - } - _yaml.dump(conf, os.path.join(project, 'project.conf')) - - element = { - 'kind': 'manual', - 'sources': [ - { - 'kind': 'local', - 'path': 'foo.txt' - } - ], - } - _yaml.dump(element, os.path.join(project, 'target.bst')) - - result = cli.run(project=project, args=['build', 'target.bst']) - result.assert_main_error(ErrorDomain.LOAD, - LoadErrorReason.PROTECTED_VARIABLE_REDEFINED) - - -@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) -@pytest.mark.datafiles(DATA_DIR) -def test_use_of_protected_var_in_element(cli, tmpdir, datafiles, protected_var): - project = os.path.join(str(datafiles), 'simple') - - element = { - 'kind': 'import', - 'sources': [ - { - 'kind': 'local', - 'path': 'foo.txt' - } - ], - 'variables': { - protected_var: 'some-value' - } - } - _yaml.dump(element, os.path.join(project, 'target.bst')) - - result = cli.run(project=project, args=['build', 'target.bst']) - result.assert_main_error(ErrorDomain.LOAD, - LoadErrorReason.PROTECTED_VARIABLE_REDEFINED) |