diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-07-03 10:28:50 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:03 +0000 |
commit | 07afbf771f42db1d1c389f156127ce1edce0d550 (patch) | |
tree | f5d82e5e5c677f7d2c09cddea8a084f0ca64809e | |
parent | 673f8f7fa761d61d7792d91fa2ef9d2595ad9f05 (diff) | |
download | buildstream-07afbf771f42db1d1c389f156127ce1edce0d550.tar.gz |
_yaml: Add a 'from_dict' on Node to create new nodes from dicts
This new methods is here to replace the previous 'new_node_from_dict'
that will be moved to a private method.
Adapt all call sites to use the new 'from_dict' method.
-rw-r--r-- | src/buildstream/_yaml.pyx | 4 | ||||
-rw-r--r-- | src/buildstream/element.py | 2 | ||||
-rw-r--r-- | tests/internals/pluginfactory.py | 32 | ||||
-rw-r--r-- | tests/sources/git.py | 2 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index 3347c216d..a1aff84c2 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -69,6 +69,10 @@ cdef class Node: self.line = line self.column = column + @classmethod + def from_dict(cls, dict value): + return new_node_from_dict(value) + cdef bint _walk_find(self, Node target, list path) except *: raise NotImplementedError() diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 7815246d3..7fb883cf4 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -2628,7 +2628,7 @@ class Element(Plugin): @classmethod def __extract_sandbox_config(cls, project, meta): if meta.is_junction: - sandbox_config = _yaml.new_node_from_dict({ + sandbox_config = _yaml.Node.from_dict({ 'build-uid': 0, 'build-gid': 0 }) diff --git a/tests/internals/pluginfactory.py b/tests/internals/pluginfactory.py index e9e63672f..4f907151d 100644 --- a/tests/internals/pluginfactory.py +++ b/tests/internals/pluginfactory.py @@ -47,7 +47,7 @@ def test_element_factory(plugin_fixture): ############################################################## @pytest.mark.datafiles(os.path.join(DATA_DIR, 'customsource')) def test_custom_source(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -62,7 +62,7 @@ def test_custom_source(plugin_fixture, datafiles): @pytest.mark.datafiles(os.path.join(DATA_DIR, 'customelement')) def test_custom_element(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -99,7 +99,7 @@ def test_missing_element(plugin_fixture): # Load a factory with a plugin that returns a value instead of Source subclass @pytest.mark.datafiles(os.path.join(DATA_DIR, 'notatype')) def test_source_notatype(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -113,7 +113,7 @@ def test_source_notatype(plugin_fixture, datafiles): # Load a factory with a plugin that returns a value instead of Element subclass @pytest.mark.datafiles(os.path.join(DATA_DIR, 'notatype')) def test_element_notatype(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -128,7 +128,7 @@ def test_element_notatype(plugin_fixture, datafiles): # which is not a Source subclass @pytest.mark.datafiles(os.path.join(DATA_DIR, 'wrongtype')) def test_source_wrongtype(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -143,7 +143,7 @@ def test_source_wrongtype(plugin_fixture, datafiles): # which is not a Element subclass @pytest.mark.datafiles(os.path.join(DATA_DIR, 'wrongtype')) def test_element_wrongtype(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -157,7 +157,7 @@ def test_element_wrongtype(plugin_fixture, datafiles): # Load a factory with a plugin which fails to provide a setup() function @pytest.mark.datafiles(os.path.join(DATA_DIR, 'nosetup')) def test_source_missing_setup(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -171,7 +171,7 @@ def test_source_missing_setup(plugin_fixture, datafiles): # Load a factory with a plugin which fails to provide a setup() function @pytest.mark.datafiles(os.path.join(DATA_DIR, 'nosetup')) def test_element_missing_setup(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -186,7 +186,7 @@ def test_element_missing_setup(plugin_fixture, datafiles): # that is not a function @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badsetup')) def test_source_bad_setup(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -201,7 +201,7 @@ def test_source_bad_setup(plugin_fixture, datafiles): # that is not a function @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badsetup')) def test_element_bad_setup(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -216,7 +216,7 @@ def test_element_bad_setup(plugin_fixture, datafiles): # high version of buildstream @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionsource')) def test_source_badversion(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -231,7 +231,7 @@ def test_source_badversion(plugin_fixture, datafiles): # high version of buildstream @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionelement')) def test_element_badversion(plugin_fixture, datafiles): - plugins = [_yaml.new_node_from_dict({ + plugins = [_yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename), @@ -249,14 +249,14 @@ def test_element_badversion(plugin_fixture, datafiles): # Load two factories, both of which define a different 'foo' plugin @pytest.mark.datafiles(DATA_DIR) def test_source_multicontext(plugin_fixture, datafiles): - plugins1 = _yaml.new_node_from_dict({ + plugins1 = _yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename, 'customsource'), 'plugins': ['foo'] }) - plugins2 = _yaml.new_node_from_dict({ + plugins2 = _yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename, @@ -278,14 +278,14 @@ def test_source_multicontext(plugin_fixture, datafiles): # Load two factories, both of which define a different 'foo' plugin @pytest.mark.datafiles(DATA_DIR) def test_element_multicontext(plugin_fixture, datafiles): - plugins1 = _yaml.new_node_from_dict({ + plugins1 = _yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename, 'customelement'), 'plugins': ['foo'] }) - plugins2 = _yaml.new_node_from_dict({ + plugins2 = _yaml.Node.from_dict({ 'origin': 'local', 'path': os.path.join(datafiles.dirname, datafiles.basename, diff --git a/tests/sources/git.py b/tests/sources/git.py index c280b5a5a..9cbf98d26 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -1151,7 +1151,7 @@ def test_overwrite_rogue_tag_multiple_remotes(cli, tmpdir, datafiles): repodir, reponame = os.path.split(repo.repo) project_config = _yaml.load(os.path.join(project, 'project.conf')) - project_config['aliases'] = _yaml.new_node_from_dict({ + project_config['aliases'] = _yaml.Node.from_dict({ 'repo': 'http://example.com/' }) project_config['mirrors'] = [ |