Loading tests/format/variables.py +89 −3 Original line number Original line Diff line number Diff line Loading @@ -12,6 +12,14 @@ DATA_DIR = os.path.join( "variables" "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 # # Test proper loading of some default commands from plugins # Loading Loading @@ -87,6 +95,84 @@ def test_cyclic_variables(cli, datafiles): result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.RECURSIVE_VARIABLE) result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.RECURSIVE_VARIABLE) def print_warning(msg): @pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) RED, END = "\033[91m", "\033[0m" @pytest.mark.datafiles(os.path.join(DATA_DIR, 'protected-vars')) print(("\n{}{}{}").format(RED, msg, END), file=sys.stderr) 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) tests/loader/variables/simple/foo.txt→tests/format/variables/protected-vars/foo.txt +0 −0 File moved. View file tests/loader/variables/simple/project.conf→tests/format/variables/protected-vars/project.conf +0 −0 File moved. View file tests/loader/variables.pydeleted 100644 → 0 +0 −99 Original line number Original line Diff line number Diff line 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) Loading
tests/format/variables.py +89 −3 Original line number Original line Diff line number Diff line Loading @@ -12,6 +12,14 @@ DATA_DIR = os.path.join( "variables" "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 # # Test proper loading of some default commands from plugins # Loading Loading @@ -87,6 +95,84 @@ def test_cyclic_variables(cli, datafiles): result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.RECURSIVE_VARIABLE) result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.RECURSIVE_VARIABLE) def print_warning(msg): @pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES) RED, END = "\033[91m", "\033[0m" @pytest.mark.datafiles(os.path.join(DATA_DIR, 'protected-vars')) print(("\n{}{}{}").format(RED, msg, END), file=sys.stderr) 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)
tests/loader/variables/simple/foo.txt→tests/format/variables/protected-vars/foo.txt +0 −0 File moved. View file
tests/loader/variables/simple/project.conf→tests/format/variables/protected-vars/project.conf +0 −0 File moved. View file
tests/loader/variables.pydeleted 100644 → 0 +0 −99 Original line number Original line Diff line number Diff line 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)