Commit 5f21693a authored by Daniel Silverstone's avatar Daniel Silverstone

_yaml.py: Remove node_contains

Now that we permit `key in somenode` remove the no longer needed function
to check if a node contains a key.
Signed-off-by: Daniel Silverstone's avatarDaniel Silverstone <daniel.silverstone@codethink.co.uk>
parent 9cb7b88e
Pipeline #55221410 passed with stages
in 77 minutes and 46 seconds
......@@ -202,11 +202,11 @@ class Context():
_yaml.composite(defaults, user_config)
# Give obsoletion warnings
if _yaml.node_contains(defaults, 'builddir'):
if 'builddir' in defaults:
raise LoadError(LoadErrorReason.INVALID_DATA,
"builddir is obsolete, use cachedir")
if _yaml.node_contains(defaults, 'artifactdir'):
if 'artifactdir' in defaults:
raise LoadError(LoadErrorReason.INVALID_DATA,
"artifactdir is obsolete")
......
......@@ -421,7 +421,7 @@ class Project():
else:
config = self.config
if not alias or not _yaml.node_contains(config._aliases, alias):
if not alias or alias not in config._aliases:
return [None]
mirror_list = []
......@@ -950,7 +950,7 @@ class Project():
plugins = _yaml.node_get(origin, Mapping, plugin_group, default_value={})
_yaml.node_set(origin_node, 'plugins', [k for k in _yaml.node_keys(plugins)])
for group in expected_groups:
if _yaml.node_contains(origin_node, group):
if group in origin_node:
_yaml.node_del(origin_node, group)
if _yaml.node_get(origin_node, str, 'origin') == 'local':
......
......@@ -86,7 +86,7 @@ class ProjectRefs():
# Ensure we create our toplevel entry point on the fly here
for node in [self._toplevel_node, self._toplevel_save]:
if not _yaml.node_contains(node, 'projects'):
if 'projects' not in node:
_yaml.node_set(node, 'projects', _yaml.new_empty_node(ref_node=node))
# lookup_ref()
......
......@@ -774,20 +774,6 @@ def __new_node_from_list(inlist):
return Node(ret, None, 0, next(_SYNTHETIC_COUNTER))
# node_contains()
#
# Args:
# node (Node): The mapping node to query the contents of
# entry (str): The key to look for in the mapping node
#
# Returns:
# (bool): Whether entry is in the mapping in node.
#
def node_contains(node, entry):
assert type(node) is Node
return entry in node[0]
# _is_composite_list
#
# Checks if the given node is a Mapping with array composition
......
......@@ -753,7 +753,7 @@ class Element(Plugin):
if workspace and old_dep_keys:
dep.__assert_cached()
if _yaml.node_contains(old_dep_keys, dep.name):
if dep.name in old_dep_keys:
key_new = dep._get_cache_key()
key_old = _yaml.node_get(old_dep_keys, str, dep.name)
......
......@@ -136,8 +136,8 @@ class SandboxRemote(Sandbox):
# Maintain some backwards compatibility with older configs, in which
# 'url' was the only valid key for remote-execution:
if _yaml.node_contains(remote_config, 'url'):
if not _yaml.node_contains(remote_config, 'execution-service'):
if 'url' in remote_config:
if 'execution-service' not in remote_config:
exec_config = _yaml.new_node_from_dict({'url': remote_config['url']})
else:
provenance = _yaml.node_get_provenance(remote_config, key='url')
......@@ -157,7 +157,7 @@ class SandboxRemote(Sandbox):
for config_key, config in zip(service_keys, service_configs):
# Either both or none of the TLS client key/cert pair must be specified:
if _yaml.node_contains(config, 'client-key') != _yaml.node_contains(config, 'client-cert'):
if ('client-key' in config) != ('client-cert' in config):
provenance = _yaml.node_get_provenance(remote_config, key=config_key)
raise _yaml.LoadError(_yaml.LoadErrorReason.INVALID_DATA,
"{}: TLS client key/cert pair is incomplete. "
......@@ -166,7 +166,7 @@ class SandboxRemote(Sandbox):
.format(str(provenance)))
for tls_key in tls_keys:
if _yaml.node_contains(config, tls_key):
if tls_key in config:
_yaml.node_set(config, tls_key, resolve_path(_yaml.node_get(config, str, tls_key)))
return RemoteExecutionSpec(*[_yaml.node_sanitize(conf) for conf in service_configs])
......
......@@ -295,7 +295,7 @@ def test_filter_track_excepted(datafiles, cli, tmpdir):
# Now check that a ref field exists
new_input = _yaml.load(input_file)
source_node = _yaml.node_get(new_input, dict, 'sources', indices=[0])
assert not _yaml.node_contains(source_node, 'ref')
assert 'ref' not in source_node
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
......@@ -483,7 +483,7 @@ def test_filter_track_multi_exclude(datafiles, cli, tmpdir):
# Now check that a ref field exists
new_input = _yaml.load(input_file)
source_node = _yaml.node_get(new_input, dict, 'sources', indices=[0])
assert not _yaml.node_contains(source_node, 'ref')
assert 'ref' not in source_node
new_input2 = _yaml.load(input2_file)
source_node2 = _yaml.node_get(new_input2, dict, 'sources', indices=[0])
......
......@@ -214,7 +214,7 @@ def test_list_overide_does_not_fail_upon_first_composition(cli, datafiles):
# Assert that the explicitly overwritten public data is present
bst = _yaml.node_get(loaded, dict, 'bst')
assert _yaml.node_contains(bst, 'foo-commands')
assert 'foo-commands' in bst
assert _yaml.node_get(bst, list, 'foo-commands') == ['need', 'this']
......
......@@ -79,7 +79,7 @@ def test_list_cross_junction(cli, tmpdir):
assert isinstance(_yaml.node_get(loaded, None, 'workspaces'), list)
workspaces = _yaml.node_get(loaded, list, 'workspaces')
assert len(workspaces) == 1
assert _yaml.node_contains(workspaces[0], 'element')
assert 'element' in workspaces[0]
assert _yaml.node_get(workspaces[0], str, 'element') == element
......
......@@ -1141,7 +1141,7 @@ def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
# Element is tracked now
element_contents = _yaml.load(element_file)
assert _yaml.node_contains(_yaml.node_get(element_contents, dict, 'sources', [0]), 'ref')
assert 'ref' in _yaml.node_get(element_contents, dict, 'sources', [0])
@pytest.mark.datafiles(DATA_DIR)
......
......@@ -127,7 +127,7 @@ def test_node_set(datafiles):
base = _yaml.load(filename)
assert not _yaml.node_contains(base, 'mother')
assert 'mother' not in base
_yaml.node_set(base, 'mother', 'snow white')
assert _yaml.node_get(base, str, 'mother') == 'snow white'
......@@ -283,7 +283,7 @@ def test_nonexistent_list_extension(datafiles):
base = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
base = _yaml.load(base, shortname='basics.yaml')
assert not _yaml.node_contains(base, 'todo')
assert 'todo' not in base
_yaml.node_extend_list(base, 'todo', 3, 'empty')
......
......@@ -358,7 +358,7 @@ def test_mirror_track_upstream_present(cli, tmpdir, datafiles, kind):
# Tracking tries upstream first. Check the ref is from upstream.
new_element = _yaml.load(element_path)
source = _yaml.node_get(new_element, dict, 'sources', [0])
if _yaml.node_contains(source, 'ref'):
if 'ref' in source:
assert _yaml.node_get(source, str, 'ref') == upstream_ref
......@@ -423,5 +423,5 @@ def test_mirror_track_upstream_absent(cli, tmpdir, datafiles, kind):
# Check that tracking fell back to the mirror
new_element = _yaml.load(element_path)
source = _yaml.node_get(new_element, dict, 'sources', [0])
if _yaml.node_contains(source, 'ref'):
if 'ref' in source:
assert _yaml.node_get(source, str, 'ref') == mirror_ref
......@@ -322,13 +322,13 @@ def test_track_include(cli, tmpdir, datafiles, ref_storage, kind):
new_sources = _yaml.load(os.path.join(element_path, 'sources.yml'))
# Get all of the sources
assert _yaml.node_contains(new_sources, 'sources')
assert 'sources' in new_sources
sources_list = _yaml.node_get(new_sources, list, 'sources')
assert len(sources_list) == 1
# Get the first source from the sources list
new_source = _yaml.node_get(new_sources, dict, 'sources', indices=[0])
assert _yaml.node_contains(new_source, 'ref')
assert 'ref' in new_source
assert ref == _yaml.node_get(new_source, str, 'ref')
......
......@@ -853,9 +853,9 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type):
tags = _yaml.node_get(_yaml.node_get(element, dict, 'sources', [0]), list, 'tags')
assert len(tags) == 2
for tag in tags:
assert _yaml.node_contains(tag, 'tag')
assert _yaml.node_contains(tag, 'commit')
assert _yaml.node_contains(tag, 'annotated')
assert 'tag' in tag
assert 'commit' in tag
assert 'annotated' in tag
assert _yaml.node_get(tag, bool, 'annotated') == (tag_type == 'annotated')
assert {(_yaml.node_get(tag, str, 'tag'),
......@@ -968,9 +968,9 @@ def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_ty
assert len(tags) == 1
tag = _yaml.node_get(source, dict, 'tags', indices=[0])
assert _yaml.node_contains(tag, 'tag')
assert _yaml.node_contains(tag, 'commit')
assert _yaml.node_contains(tag, 'annotated')
assert 'tag' in tag
assert 'commit' in tag
assert 'annotated' in tag
assert _yaml.node_get(tag, bool, 'annotated') == (tag_type == 'annotated')
tag_name = _yaml.node_get(tag, str, 'tag')
......@@ -1127,7 +1127,7 @@ def test_default_do_not_track_tags(cli, tmpdir, datafiles):
element = _yaml.load(element_path)
source = _yaml.node_get(element, dict, 'sources', indices=[0])
assert not _yaml.node_contains(source, 'tags')
assert 'tags' not in source
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment