summaryrefslogtreecommitdiff
path: root/tests/sources
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sources')
-rw-r--r--tests/sources/generic/mirror.py12
-rw-r--r--tests/sources/generic/track.py15
-rw-r--r--tests/sources/git.py55
3 files changed, 48 insertions, 34 deletions
diff --git a/tests/sources/generic/mirror.py b/tests/sources/generic/mirror.py
index f5a11d2d7..b011872b1 100644
--- a/tests/sources/generic/mirror.py
+++ b/tests/sources/generic/mirror.py
@@ -357,9 +357,9 @@ 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 = new_element['sources'][0]
- if 'ref' in source:
- assert source['ref'] == upstream_ref
+ source = _yaml.node_get(new_element, dict, 'sources', [0])
+ if _yaml.node_contains(source, 'ref'):
+ assert _yaml.node_get(source, str, 'ref') == upstream_ref
@pytest.mark.datafiles(DATA_DIR)
@@ -422,6 +422,6 @@ 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 = new_element['sources'][0]
- if 'ref' in source:
- assert source['ref'] == mirror_ref
+ source = _yaml.node_get(new_element, dict, 'sources', [0])
+ if _yaml.node_contains(source, 'ref'):
+ assert _yaml.node_get(source, str, 'ref') == mirror_ref
diff --git a/tests/sources/generic/track.py b/tests/sources/generic/track.py
index 4726a453e..05519719b 100644
--- a/tests/sources/generic/track.py
+++ b/tests/sources/generic/track.py
@@ -318,11 +318,18 @@ def test_track_include(cli, tmpdir, datafiles, ref_storage, kind):
assert os.path.exists(os.path.join(project, 'project.refs'))
else:
assert not os.path.exists(os.path.join(project, 'project.refs'))
+
new_sources = _yaml.load(os.path.join(element_path, 'sources.yml'))
- assert 'sources' in new_sources
- assert len(new_sources['sources']) == 1
- assert 'ref' in new_sources['sources'][0]
- assert ref == new_sources['sources'][0]['ref']
+
+ # Get all of the sources
+ assert _yaml.node_contains(new_sources, '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 == _yaml.node_get(new_source, str, 'ref')
@pytest.mark.datafiles(DATA_DIR)
diff --git a/tests/sources/git.py b/tests/sources/git.py
index 8922a47d7..c11b90c06 100644
--- a/tests/sources/git.py
+++ b/tests/sources/git.py
@@ -761,7 +761,7 @@ def test_track_fetch(cli, tmpdir, datafiles, ref_format, tag, extra_commit):
result.assert_success()
element = _yaml.load(element_path)
- new_ref = element['sources'][0]['ref']
+ new_ref = _yaml.node_get(_yaml.node_get(element, dict, 'sources', [0]), str, 'ref')
if ref_format == 'git-describe' and tag:
# Check and strip prefix
@@ -786,7 +786,7 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type):
project = str(datafiles)
project_config = _yaml.load(os.path.join(project, 'project.conf'))
- project_config['ref-storage'] = ref_storage
+ _yaml.node_set(project_config, 'ref-storage', ref_storage)
_yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
repofiles = os.path.join(str(tmpdir), 'repofiles')
@@ -850,16 +850,18 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type):
if ref_storage == 'inline':
element = _yaml.load(element_path)
- tags = _yaml.node_sanitize(element['sources'][0]['tags'])
+ tags = _yaml.node_get(_yaml.node_get(element, dict, 'sources', [0]), list, 'tags')
assert len(tags) == 2
for tag in tags:
- assert 'tag' in tag
- assert 'commit' in tag
- assert 'annotated' in tag
- assert tag['annotated'] == (tag_type == 'annotated')
+ assert _yaml.node_contains(tag, 'tag')
+ assert _yaml.node_contains(tag, 'commit')
+ assert _yaml.node_contains(tag, 'annotated')
+ assert _yaml.node_get(tag, bool, 'annotated') == (tag_type == 'annotated')
- assert {(tag['tag'], tag['commit']) for tag in tags} == {('tag1', repo.rev_parse('tag1^{commit}')),
- ('tag2', repo.rev_parse('tag2^{commit}'))}
+ assert {(_yaml.node_get(tag, str, 'tag'),
+ _yaml.node_get(tag, str, 'commit'))
+ for tag in tags} == {('tag1', repo.rev_parse('tag1^{commit}')),
+ ('tag2', repo.rev_parse('tag2^{commit}'))}
checkout = os.path.join(str(tmpdir), 'checkout')
@@ -898,7 +900,7 @@ def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_ty
project = str(datafiles)
project_config = _yaml.load(os.path.join(project, 'project.conf'))
- project_config['ref-storage'] = ref_storage
+ _yaml.node_set(project_config, 'ref-storage', ref_storage)
_yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
repofiles = os.path.join(str(tmpdir), 'repofiles')
@@ -961,15 +963,19 @@ def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_ty
if ref_storage == 'inline':
element = _yaml.load(element_path)
- tags = _yaml.node_sanitize(element['sources'][0]['tags'])
+ source = _yaml.node_get(element, dict, 'sources', indices=[0])
+ tags = _yaml.node_get(source, list, 'tags')
assert len(tags) == 1
- for tag in tags:
- assert 'tag' in tag
- assert 'commit' in tag
- assert 'annotated' in tag
- assert tag['annotated'] == (tag_type == 'annotated')
- assert {(tag['tag'], tag['commit']) for tag in tags} == {('tag', repo.rev_parse('tag^{commit}'))}
+ 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 _yaml.node_get(tag, bool, 'annotated') == (tag_type == 'annotated')
+
+ tag_name = _yaml.node_get(tag, str, 'tag')
+ commit = _yaml.node_get(tag, str, 'commit')
+ assert (tag_name, commit) == ('tag', repo.rev_parse('tag^{commit}'))
checkout = os.path.join(str(tmpdir), 'checkout')
@@ -1009,7 +1015,7 @@ def test_git_describe_relevant_history(cli, tmpdir, datafiles):
project = str(datafiles)
project_config = _yaml.load(os.path.join(project, 'project.conf'))
- project_config['ref-storage'] = 'project.refs'
+ _yaml.node_set(project_config, 'ref-storage', 'project.refs')
_yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
repofiles = os.path.join(str(tmpdir), 'repofiles')
@@ -1089,7 +1095,7 @@ def test_default_do_not_track_tags(cli, tmpdir, datafiles):
project = str(datafiles)
project_config = _yaml.load(os.path.join(project, 'project.conf'))
- project_config['ref-storage'] = 'inline'
+ _yaml.node_set(project_config, 'ref-storage', 'inline')
_yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
repofiles = os.path.join(str(tmpdir), 'repofiles')
@@ -1120,7 +1126,8 @@ def test_default_do_not_track_tags(cli, tmpdir, datafiles):
result.assert_success()
element = _yaml.load(element_path)
- assert 'tags' not in element['sources'][0]
+ source = _yaml.node_get(element, dict, 'sources', indices=[0])
+ assert not _yaml.node_contains(source, 'tags')
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@@ -1145,17 +1152,17 @@ 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.node_set(project_config, 'aliases', _yaml.new_node_from_dict({
'repo': 'http://example.com/'
- }
- project_config['mirrors'] = [
+ }))
+ _yaml.node_set(project_config, 'mirrors', [
{
'name': 'middle-earth',
'aliases': {
'repo': ['file://{}/'.format(repodir)]
}
}
- ]
+ ])
_yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
repo.add_annotated_tag('tag', 'tag')