Format the coding style across the codebase using "black" and manual tweaks

The main benefit of this commit is that the use of double quotes
is now consistent.
This commit is contained in:
mprahl
2019-04-25 17:58:44 -04:00
parent 559f0dd922
commit 66c3f82160
78 changed files with 9050 additions and 7438 deletions

View File

@@ -30,28 +30,26 @@ from tests import make_module, clean_database
class TestFindModuleKojiTags:
"""Test ursine.find_module_koji_tags"""
@patch.object(conf, 'koji_tag_prefixes', new=['module'])
@patch.object(conf, "koji_tag_prefixes", new=["module"])
def test_find_out_all_module_koji_tags(self):
session = Mock()
session.getFullInheritance.return_value = [
{'name': 'module-tag1-s-v-c'},
{'name': 'module-tag2-s-v-c'},
{'name': 'tag-1'},
{"name": "module-tag1-s-v-c"},
{"name": "module-tag2-s-v-c"},
{"name": "tag-1"},
]
expected_tags = ['module-tag1-s-v-c', 'module-tag2-s-v-c']
expected_tags = ["module-tag1-s-v-c", "module-tag2-s-v-c"]
tags = ursine.find_module_koji_tags(session, 'tag-a-build')
tags = ursine.find_module_koji_tags(session, "tag-a-build")
assert expected_tags == tags
@patch.object(conf, 'koji_tag_prefixes', new=['module'])
@patch.object(conf, "koji_tag_prefixes", new=["module"])
def test_return_empty_if_no_module_koji_tags(self):
session = Mock()
session.getFullInheritance.return_value = [
{'name': 'tag-1'}, {'name': 'tag-2'},
]
session.getFullInheritance.return_value = [{"name": "tag-1"}, {"name": "tag-2"}]
tags = ursine.find_module_koji_tags(session, 'tag-a-build')
tags = ursine.find_module_koji_tags(session, "tag-a-build")
assert [] == tags
@@ -60,56 +58,68 @@ class TestFindUrsineRootTags:
def setup_method(self):
self.koji_session = Mock()
self.koji_session.getTag.side_effect = lambda name: \
None if name == 'X-build' else {'name': name}
self.koji_session.getTag.side_effect = \
lambda name: None if name == "X-build" else {"name": name}
def test_find_build_tags(self):
with patch.object(conf, 'koji_external_repo_url_prefix',
new='http://example.com/brewroot/'):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'http://example.com/brewroot/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'http://example.com/brewroot/repos/tag-2-build/latest/$arch/'
},
])
with patch.object(
conf, "koji_external_repo_url_prefix", new="http://example.com/brewroot/"
):
tags = ursine.find_build_tags_from_external_repos(
self.koji_session,
[
{
"external_repo_name": "tag-1-external-repo",
"url": "http://example.com/brewroot/repos/tag-1-build/latest/$arch/",
},
{
"external_repo_name": "tag-2-external-repo",
"url": "http://example.com/brewroot/repos/tag-2-build/latest/$arch/",
},
],
)
assert ['tag-1-build', 'tag-2-build'] == tags
assert ["tag-1-build", "tag-2-build"] == tags
def test_return_emtpy_if_no_match_external_repo_url(self):
with patch.object(conf, 'koji_external_repo_url_prefix',
new='http://example.com/brewroot/'):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'https://another-site.org/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'https://another-site.org/repos/tag-2-build/latest/$arch/'
},
])
with patch.object(
conf, "koji_external_repo_url_prefix", new="http://example.com/brewroot/"
):
tags = ursine.find_build_tags_from_external_repos(
self.koji_session,
[
{
"external_repo_name": "tag-1-external-repo",
"url": "https://another-site.org/repos/tag-1-build/latest/$arch/",
},
{
"external_repo_name": "tag-2-external-repo",
"url": "https://another-site.org/repos/tag-2-build/latest/$arch/",
},
],
)
assert [] == tags
def test_some_tag_is_not_koji_tag(self):
with patch.object(conf, 'koji_external_repo_url_prefix',
new='http://example.com/brewroot/'):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'http://example.com/brewroot/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'http://example.com/brewroot/repos/X-build/latest/$arch/'
},
])
with patch.object(
conf, "koji_external_repo_url_prefix", new="http://example.com/brewroot/"
):
tags = ursine.find_build_tags_from_external_repos(
self.koji_session,
[
{
"external_repo_name": "tag-1-external-repo",
"url": "http://example.com/brewroot/repos/tag-1-build/latest/$arch/",
},
{
"external_repo_name": "tag-2-external-repo",
"url": "http://example.com/brewroot/repos/X-build/latest/$arch/",
},
],
)
assert ['tag-1-build'] == tags
assert ["tag-1-build"] == tags
class TestGetModulemdsFromUrsineContent:
@@ -121,71 +131,63 @@ class TestGetModulemdsFromUrsineContent:
def teardown_method(self, test_method):
clean_database()
@patch('module_build_service.builder.KojiModuleBuilder.KojiClientSession')
@patch("module_build_service.builder.KojiModuleBuilder.KojiClientSession")
def test_return_empty_if_no_ursine_build_tag_is_found(self, ClientSession):
session = ClientSession.return_value
# No module koji_tag in ursine content yet. This will result in empty
# ursine modulemds is returned.
session.getFullInheritance.return_value = [
{'name': 'tag-1.0-build'},
]
session.getExternalRepoList.return_value = [
{
'external_repo_name': 'tag-1.0-external-repo',
'url': 'http://example.com/repos/tag-4-build/latest/$arch/'
}
]
session.getFullInheritance.return_value = [{"name": "tag-1.0-build"}]
session.getExternalRepoList.return_value = [{
"external_repo_name": "tag-1.0-external-repo",
"url": "http://example.com/repos/tag-4-build/latest/$arch/",
}]
modulemds = ursine.get_modulemds_from_ursine_content('tag')
modulemds = ursine.get_modulemds_from_ursine_content("tag")
assert [] == modulemds
@patch.object(conf, 'koji_tag_prefixes', new=['module'])
@patch('module_build_service.builder.KojiModuleBuilder.KojiClientSession')
@patch.object(conf, "koji_tag_prefixes", new=["module"])
@patch("module_build_service.builder.KojiModuleBuilder.KojiClientSession")
def test_get_modulemds(self, ClientSession):
session = ClientSession.return_value
# Ensure to to get build tag for further query of ursine content.
# For this test, the build tag is tag-4-build
session.getExternalRepoList.return_value = [
{
'external_repo_name': 'tag-1.0-external-repo',
'url': 'http://example.com/repos/tag-4-build/latest/$arch/'
}
]
session.getExternalRepoList.return_value = [{
"external_repo_name": "tag-1.0-external-repo",
"url": "http://example.com/repos/tag-4-build/latest/$arch/",
}]
# Ensure to return module tags from ursine content of fake build tag
# specified in above external repo's url.
def mock_getFullInheritance(tag):
if tag == 'tag-4-build':
if tag == "tag-4-build":
return [
{'name': 'tag-1.0-build'},
{"name": "tag-1.0-build"},
# Below two modules should be returned and whose modulemd
# should be also queried from database.
{'name': 'module-name1-s-2020-c'},
{'name': 'module-name2-s-2021-c'},
{"name": "module-name1-s-2020-c"},
{"name": "module-name2-s-2021-c"},
]
raise ValueError('{} is not handled by test.'.format(tag))
raise ValueError("{} is not handled by test.".format(tag))
session.getFullInheritance.side_effect = mock_getFullInheritance
# Defaults to DB resolver, so create fake module builds and store them
# into database to ensure they can be queried.
mmd_name1s2020c = make_module(
'name1:s:2020:c',
xmd={'mbs': {'koji_tag': 'module-name1-s-2020-c'}})
"name1:s:2020:c", xmd={"mbs": {"koji_tag": "module-name1-s-2020-c"}})
mmd_name2s2021c = make_module(
'name2:s:2021:c',
xmd={'mbs': {'koji_tag': 'module-name2-s-2021-c'}})
"name2:s:2021:c", xmd={"mbs": {"koji_tag": "module-name2-s-2021-c"}})
koji_tag = 'tag' # It's ok to use arbitrary tag name.
with patch.object(conf, 'koji_external_repo_url_prefix', new='http://example.com/'):
koji_tag = "tag" # It's ok to use arbitrary tag name.
with patch.object(conf, "koji_external_repo_url_prefix", new="http://example.com/"):
modulemds = ursine.get_modulemds_from_ursine_content(koji_tag)
test_nsvcs = [item.dup_nsvc() for item in modulemds]
test_nsvcs.sort()
expected_nsvcs = [mmd_name1s2020c.mmd().dup_nsvc(),
mmd_name2s2021c.mmd().dup_nsvc()]
expected_nsvcs = [mmd_name1s2020c.mmd().dup_nsvc(), mmd_name2s2021c.mmd().dup_nsvc()]
expected_nsvcs.sort()
session.getExternalRepoList.assert_called_once_with(koji_tag)
@@ -195,92 +197,85 @@ class TestGetModulemdsFromUrsineContent:
class TestRecordStreamCollisionModules:
"""Test ursine.record_stream_collision_modules"""
@patch.object(conf, 'base_module_names', new=['platform'])
@patch.object(ursine, 'find_stream_collision_modules')
@patch.object(conf, "base_module_names", new=["platform"])
@patch.object(ursine, "find_stream_collision_modules")
def test_nothing_changed_if_no_base_module_is_in_buildrequires(
self, find_stream_collision_modules):
xmd = {
'mbs': {
'buildrequires': {
'modulea': {'stream': 'master'}
}
}
}
fake_mmd = make_module('name1:s:2020:c', xmd=xmd, store_to_db=False)
self, find_stream_collision_modules
):
xmd = {"mbs": {"buildrequires": {"modulea": {"stream": "master"}}}}
fake_mmd = make_module("name1:s:2020:c", xmd=xmd, store_to_db=False)
original_xmd = glib.from_variant_dict(fake_mmd.get_xmd())
with patch.object(ursine, 'log') as log:
with patch.object(ursine, "log") as log:
ursine.handle_stream_collision_modules(fake_mmd)
assert 2 == log.info.call_count
find_stream_collision_modules.assert_not_called()
assert original_xmd == glib.from_variant_dict(fake_mmd.get_xmd())
@patch.object(conf, 'base_module_names', new=['platform'])
@patch('module_build_service.utils.ursine.get_modulemds_from_ursine_content')
@patch.object(conf, "base_module_names", new=["platform"])
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
def test_mark_handled_even_if_no_modules_in_ursine_content(
self, get_modulemds_from_ursine_content):
self, get_modulemds_from_ursine_content
):
xmd = {
'mbs': {
'buildrequires': {
'modulea': {'stream': 'master'},
'platform': {'stream': 'master', 'koji_tag': 'module-rhel-8.0-build'},
"mbs": {
"buildrequires": {
"modulea": {"stream": "master"},
"platform": {"stream": "master", "koji_tag": "module-rhel-8.0-build"},
}
}
}
fake_mmd = make_module('name1:s:2020:c', xmd=xmd, store_to_db=False)
fake_mmd = make_module("name1:s:2020:c", xmd=xmd, store_to_db=False)
original_xmd = glib.from_variant_dict(fake_mmd.get_xmd())
get_modulemds_from_ursine_content.return_value = []
with patch.object(ursine, 'log') as log:
with patch.object(ursine, "log") as log:
ursine.handle_stream_collision_modules(fake_mmd)
assert 2 == log.info.call_count
expected_xmd = copy.deepcopy(original_xmd)
# Ensure stream_collision_modules is set.
expected_xmd['mbs']['buildrequires']['platform']['stream_collision_modules'] = ''
expected_xmd['mbs']['buildrequires']['platform']['ursine_rpms'] = ''
expected_xmd["mbs"]["buildrequires"]["platform"]["stream_collision_modules"] = ""
expected_xmd["mbs"]["buildrequires"]["platform"]["ursine_rpms"] = ""
assert expected_xmd == glib.from_variant_dict(fake_mmd.get_xmd())
@patch.object(conf, 'base_module_names', new=['platform', 'project-platform'])
@patch('module_build_service.utils.ursine.get_modulemds_from_ursine_content')
@patch('module_build_service.resolver.GenericResolver.create')
@patch('module_build_service.builder.KojiModuleBuilder.KojiClientSession')
def test_add_collision_modules(self, ClientSession, resolver_create,
get_modulemds_from_ursine_content):
@patch.object(conf, "base_module_names", new=["platform", "project-platform"])
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
@patch("module_build_service.resolver.GenericResolver.create")
@patch("module_build_service.builder.KojiModuleBuilder.KojiClientSession")
def test_add_collision_modules(
self, ClientSession, resolver_create, get_modulemds_from_ursine_content
):
xmd = {
'mbs': {
'buildrequires': {
'modulea': {'stream': 'master'},
'foo': {'stream': '1'},
'bar': {'stream': '2'},
'platform': {'stream': 'master', 'koji_tag': 'module-rhel-8.0-build'},
'project-platform': {
'stream': 'master', 'koji_tag': 'module-project-1.0-build'
"mbs": {
"buildrequires": {
"modulea": {"stream": "master"},
"foo": {"stream": "1"},
"bar": {"stream": "2"},
"platform": {"stream": "master", "koji_tag": "module-rhel-8.0-build"},
"project-platform": {
"stream": "master",
"koji_tag": "module-project-1.0-build",
},
}
}
}
fake_mmd = make_module('name1:s:2020:c',
xmd=xmd, store_to_db=False)
fake_mmd = make_module("name1:s:2020:c", xmd=xmd, store_to_db=False)
def mock_get_ursine_modulemds(koji_tag):
if koji_tag == 'module-rhel-8.0-build':
if koji_tag == "module-rhel-8.0-build":
return [
# This is the one
make_module('modulea:10:20180813041838:5ea3b708',
store_to_db=False),
make_module('moduleb:1.0:20180113042038:6ea3b105',
store_to_db=False),
make_module("modulea:10:20180813041838:5ea3b708", store_to_db=False),
make_module("moduleb:1.0:20180113042038:6ea3b105", store_to_db=False),
]
if koji_tag == 'module-project-1.0-build':
if koji_tag == "module-project-1.0-build":
return [
# Both of them are the collided modules
make_module('bar:6:20181013041838:817fa3a8',
store_to_db=False),
make_module('foo:2:20180113041838:95f078a1',
store_to_db=False),
make_module("bar:6:20181013041838:817fa3a8", store_to_db=False),
make_module("foo:2:20180113041838:95f078a1", store_to_db=False),
]
get_modulemds_from_ursine_content.side_effect = mock_get_ursine_modulemds
@@ -288,34 +283,31 @@ class TestRecordStreamCollisionModules:
# Mock for finding out built rpms
def mock_get_module(name, stream, version, context, strict=True):
return {
'modulea:10:20180813041838:5ea3b708': {
'koji_tag': 'module-modulea-10-20180813041838-5ea3b708',
"modulea:10:20180813041838:5ea3b708": {
"koji_tag": "module-modulea-10-20180813041838-5ea3b708"
},
'bar:6:20181013041838:817fa3a8': {
'koji_tag': 'module-bar-6-20181013041838-817fa3a8',
"bar:6:20181013041838:817fa3a8": {
"koji_tag": "module-bar-6-20181013041838-817fa3a8"
},
'foo:2:20180113041838:95f078a1': {
'koji_tag': 'module-foo-2-20180113041838-95f078a1',
"foo:2:20180113041838:95f078a1": {
"koji_tag": "module-foo-2-20180113041838-95f078a1"
},
}['{}:{}:{}:{}'.format(name, stream, version, context)]
}["{}:{}:{}:{}".format(name, stream, version, context)]
resolver = resolver_create.return_value
resolver._get_module.side_effect = mock_get_module
def mock_listTaggedRPMS(tag, latest):
return {
'module-modulea-10-20180813041838-5ea3b708': [[
{'name': 'pkg1', 'version': '1.0', 'release': '1.fc28',
'epoch': None},
]],
'module-bar-6-20181013041838-817fa3a8': [[
{'name': 'pkg2', 'version': '2.0', 'release': '1.fc28',
'epoch': None},
]],
'module-foo-2-20180113041838-95f078a1': [[
{'name': 'pkg3', 'version': '3.0', 'release': '1.fc28',
'epoch': None},
]],
"module-modulea-10-20180813041838-5ea3b708": [
[{"name": "pkg1", "version": "1.0", "release": "1.fc28", "epoch": None}]
],
"module-bar-6-20181013041838-817fa3a8": [
[{"name": "pkg2", "version": "2.0", "release": "1.fc28", "epoch": None}]
],
"module-foo-2-20180113041838-95f078a1": [
[{"name": "pkg3", "version": "3.0", "release": "1.fc28", "epoch": None}]
],
}[tag]
koji_session = ClientSession.return_value
@@ -324,59 +316,47 @@ class TestRecordStreamCollisionModules:
ursine.handle_stream_collision_modules(fake_mmd)
xmd = glib.from_variant_dict(fake_mmd.get_xmd())
buildrequires = xmd['mbs']['buildrequires']
buildrequires = xmd["mbs"]["buildrequires"]
assert (['modulea:10:20180813041838:5ea3b708'] ==
buildrequires['platform']['stream_collision_modules'])
assert (['pkg1-0:1.0-1.fc28'] ==
buildrequires['platform']['ursine_rpms'])
modules = buildrequires["platform"]["stream_collision_modules"]
assert ["modulea:10:20180813041838:5ea3b708"] == modules
assert ["pkg1-0:1.0-1.fc28"] == buildrequires["platform"]["ursine_rpms"]
modules = sorted(
buildrequires['project-platform']['stream_collision_modules'])
expected_modules = ['bar:6:20181013041838:817fa3a8',
'foo:2:20180113041838:95f078a1']
modules = sorted(buildrequires["project-platform"]["stream_collision_modules"])
expected_modules = ["bar:6:20181013041838:817fa3a8", "foo:2:20180113041838:95f078a1"]
assert expected_modules == modules
assert (['pkg2-0:2.0-1.fc28', 'pkg3-0:3.0-1.fc28'] ==
sorted(buildrequires['project-platform']['ursine_rpms']))
rpms = sorted(buildrequires["project-platform"]["ursine_rpms"])
assert ["pkg2-0:2.0-1.fc28", "pkg3-0:3.0-1.fc28"] == rpms
class TestFindStreamCollisionModules:
"""Test ursine.find_stream_collision_modules"""
@patch('module_build_service.utils.ursine.get_modulemds_from_ursine_content')
def test_no_modulemds_found_from_ursine_content(
self, get_modulemds_from_ursine_content):
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
def test_no_modulemds_found_from_ursine_content(self, get_modulemds_from_ursine_content):
get_modulemds_from_ursine_content.return_value = []
assert not ursine.find_stream_collision_modules({}, 'koji_tag')
assert not ursine.find_stream_collision_modules({}, "koji_tag")
@patch('module_build_service.utils.ursine.get_modulemds_from_ursine_content')
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
def test_no_collisions_found(self, get_modulemds_from_ursine_content):
xmd_mbs_buildrequires = {
'modulea': {'stream': 'master'},
'moduleb': {'stream': '10'},
}
xmd_mbs_buildrequires = {"modulea": {"stream": "master"}, "moduleb": {"stream": "10"}}
get_modulemds_from_ursine_content.return_value = [
make_module('moduler:1:1:c1', store_to_db=False),
make_module('modules:2:1:c2', store_to_db=False),
make_module('modulet:3:1:c3', store_to_db=False),
make_module("moduler:1:1:c1", store_to_db=False),
make_module("modules:2:1:c2", store_to_db=False),
make_module("modulet:3:1:c3", store_to_db=False),
]
assert [] == ursine.find_stream_collision_modules(
xmd_mbs_buildrequires, 'koji_tag')
assert [] == ursine.find_stream_collision_modules(xmd_mbs_buildrequires, "koji_tag")
@patch('module_build_service.utils.ursine.get_modulemds_from_ursine_content')
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
def test_collision_modules_are_found(self, get_modulemds_from_ursine_content):
xmd_mbs_buildrequires = {
'modulea': {'stream': 'master'},
'moduleb': {'stream': '10'},
}
xmd_mbs_buildrequires = {"modulea": {"stream": "master"}, "moduleb": {"stream": "10"}}
fake_modules = [
make_module('moduler:1:1:c1', store_to_db=False),
make_module('moduleb:6:1:c2', store_to_db=False),
make_module('modulet:3:1:c3', store_to_db=False),
make_module("moduler:1:1:c1", store_to_db=False),
make_module("moduleb:6:1:c2", store_to_db=False),
make_module("modulet:3:1:c3", store_to_db=False),
]
get_modulemds_from_ursine_content.return_value = fake_modules
assert [fake_modules[1].dup_nsvc()] == \
ursine.find_stream_collision_modules(
xmd_mbs_buildrequires, 'koji_tag')
modules = ursine.find_stream_collision_modules(xmd_mbs_buildrequires, "koji_tag")
assert [fake_modules[1].dup_nsvc()] == modules

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,6 @@ from tests import db, clean_database, make_module, init_data, base_dir
class TestUtilsModuleStreamExpansion:
def setup_method(self, test_method):
clean_database(False)
@@ -45,8 +44,10 @@ class TestUtilsModuleStreamExpansion:
mmd = module_build.mmd()
module_build_service.utils.expand_mse_streams(db.session, mmd)
modules = module_build_service.utils.get_mmds_required_by_module_recursively(mmd)
nsvcs = [":".join([m.get_name(), m.get_stream(), str(m.get_version()), m.get_context()])
for m in modules]
nsvcs = [
":".join([m.get_name(), m.get_stream(), str(m.get_version()), m.get_context()])
for m in modules
]
return nsvcs
def _generate_default_modules(self):
@@ -70,99 +71,96 @@ class TestUtilsModuleStreamExpansion:
self._generate_default_modules()
module_build = make_module(
"app:1:0:c1", {"gtk": ["1", "2"]}, {"platform": ["f28"], "gtk": ["1", "2"]})
mmds = module_build_service.utils.generate_expanded_mmds(
db.session, module_build.mmd())
mmds = module_build_service.utils.generate_expanded_mmds(db.session, module_build.mmd())
contexts = set([mmd.get_context() for mmd in mmds])
assert set(['e1e005fb', 'ce132a1e']) == contexts
assert set(["e1e005fb", "ce132a1e"]) == contexts
@pytest.mark.parametrize(
'requires,build_requires,stream_ambigous,expected_xmd,expected_buildrequires', [
({"gtk": ["1", "2"]},
{"platform": ["f28"], "gtk": ["1", "2"]}, True,
set([
frozenset(['platform:f28:0:c10', 'gtk:2:0:c4']),
frozenset(['platform:f28:0:c10', 'gtk:1:0:c2'])
]),
set([
frozenset(['gtk:1', 'platform:f28']),
frozenset(['gtk:2', 'platform:f28']),
])),
({"foo": ["1"]},
{"platform": ["f28"], "foo": ["1"], "gtk": ["1", "2"]}, True,
set([
frozenset(['foo:1:0:c2', 'gtk:1:0:c2', 'platform:f28:0:c10']),
frozenset(['foo:1:0:c2', 'gtk:2:0:c4', 'platform:f28:0:c10'])
]),
set([
frozenset(['foo:1', 'gtk:1', 'platform:f28']),
frozenset(['foo:1', 'gtk:2', 'platform:f28'])
])),
({"gtk": ["1"], "foo": ["1"]},
{"platform": ["f28"], "gtk": ["1"], "foo": ["1"]}, False,
set([
frozenset(['foo:1:0:c2', 'gtk:1:0:c2', 'platform:f28:0:c10'])
]),
set([
frozenset(['foo:1', 'gtk:1', 'platform:f28'])
])),
({"gtk": ["1"], "foo": ["1"]},
{"gtk": ["1"], "foo": ["1"], "platform": ["f28"]}, False,
set([
frozenset(['foo:1:0:c2', 'gtk:1:0:c2', 'platform:f28:0:c10'])
]),
set([
frozenset(['foo:1', 'gtk:1', 'platform:f28'])
])),
({"gtk": ["-2"], "foo": ["-2"]},
{"platform": ["f28"], "gtk": ["-2"], "foo": ["-2"]}, True,
set([
frozenset(['foo:1:0:c2', 'gtk:1:0:c2', 'platform:f28:0:c10'])
]),
set([
frozenset(['foo:1', 'gtk:1', 'platform:f28'])
])),
({"gtk": ["1"], "foo": ["1"]},
{"platform": ["f28"], "gtk": ["-1", "1"], "foo": ["-2", "1"]}, False,
set([
frozenset(['foo:1:0:c2', 'gtk:1:0:c2', 'platform:f28:0:c10'])
]),
set([
frozenset(['foo:1', 'gtk:1', 'platform:f28'])
])),
({"gtk": ["1"], "foo": ["1"]},
{"platform": ["f28"], "gtk": ["1"]}, False,
set([
frozenset(['gtk:1:0:c2', 'platform:f28:0:c10'])
]),
set([
frozenset(['gtk:1', 'platform:f28'])
])),
({"gtk": []}, {"platform": ["f28"], "gtk": ["1"]}, True,
set([
frozenset(['gtk:1:0:c2', 'platform:f28:0:c10'])
]),
set([
frozenset(['gtk:1', 'platform:f28'])
])),
({}, {"platform": ["f29"], "app": ["1"]}, False,
set([
frozenset(['app:1:0:c6', 'platform:f29:0:c11'])
]),
set([
frozenset(['app:1', 'platform:f29'])
])),
])
"requires,build_requires,stream_ambigous,expected_xmd,expected_buildrequires",
[
(
{"gtk": ["1", "2"]},
{"platform": ["f28"], "gtk": ["1", "2"]},
True,
set(
[
frozenset(["platform:f28:0:c10", "gtk:2:0:c4"]),
frozenset(["platform:f28:0:c10", "gtk:1:0:c2"]),
]
),
set([frozenset(["gtk:1", "platform:f28"]), frozenset(["gtk:2", "platform:f28"])]),
),
(
{"foo": ["1"]},
{"platform": ["f28"], "foo": ["1"], "gtk": ["1", "2"]},
True,
set(
[
frozenset(["foo:1:0:c2", "gtk:1:0:c2", "platform:f28:0:c10"]),
frozenset(["foo:1:0:c2", "gtk:2:0:c4", "platform:f28:0:c10"]),
]
),
set(
[
frozenset(["foo:1", "gtk:1", "platform:f28"]),
frozenset(["foo:1", "gtk:2", "platform:f28"]),
]
),
),
(
{"gtk": ["1"], "foo": ["1"]},
{"platform": ["f28"], "gtk": ["1"], "foo": ["1"]},
False,
set([frozenset(["foo:1:0:c2", "gtk:1:0:c2", "platform:f28:0:c10"])]),
set([frozenset(["foo:1", "gtk:1", "platform:f28"])]),
),
(
{"gtk": ["1"], "foo": ["1"]},
{"gtk": ["1"], "foo": ["1"], "platform": ["f28"]},
False,
set([frozenset(["foo:1:0:c2", "gtk:1:0:c2", "platform:f28:0:c10"])]),
set([frozenset(["foo:1", "gtk:1", "platform:f28"])]),
),
(
{"gtk": ["-2"], "foo": ["-2"]},
{"platform": ["f28"], "gtk": ["-2"], "foo": ["-2"]},
True,
set([frozenset(["foo:1:0:c2", "gtk:1:0:c2", "platform:f28:0:c10"])]),
set([frozenset(["foo:1", "gtk:1", "platform:f28"])]),
),
(
{"gtk": ["1"], "foo": ["1"]},
{"platform": ["f28"], "gtk": ["-1", "1"], "foo": ["-2", "1"]},
False,
set([frozenset(["foo:1:0:c2", "gtk:1:0:c2", "platform:f28:0:c10"])]),
set([frozenset(["foo:1", "gtk:1", "platform:f28"])]),
),
(
{"gtk": ["1"], "foo": ["1"]},
{"platform": ["f28"], "gtk": ["1"]},
False,
set([frozenset(["gtk:1:0:c2", "platform:f28:0:c10"])]),
set([frozenset(["gtk:1", "platform:f28"])]),
),
(
{"gtk": []},
{"platform": ["f28"], "gtk": ["1"]},
True,
set([frozenset(["gtk:1:0:c2", "platform:f28:0:c10"])]),
set([frozenset(["gtk:1", "platform:f28"])]),
),
(
{},
{"platform": ["f29"], "app": ["1"]},
False,
set([frozenset(["app:1:0:c6", "platform:f29:0:c11"])]),
set([frozenset(["app:1", "platform:f29"])]),
),
],
)
def test_generate_expanded_mmds_buildrequires(
self, requires, build_requires, stream_ambigous, expected_xmd,
expected_buildrequires):
self, requires, build_requires, stream_ambigous, expected_xmd, expected_buildrequires
):
self._generate_default_modules()
module_build = make_module("app:1:0:c1", requires, build_requires)
@@ -184,20 +182,22 @@ class TestUtilsModuleStreamExpansion:
name, stream = ns.split(":")
default_streams[name] = stream
module_build_service.utils.generate_expanded_mmds(
db.session, module_build.mmd(), raise_if_stream_ambigous=True,
default_streams=default_streams)
db.session,
module_build.mmd(),
raise_if_stream_ambigous=True,
default_streams=default_streams,
)
mmds = module_build_service.utils.generate_expanded_mmds(
db.session, module_build.mmd())
mmds = module_build_service.utils.generate_expanded_mmds(db.session, module_build.mmd())
buildrequires_per_mmd_xmd = set()
buildrequires_per_mmd_buildrequires = set()
for mmd in mmds:
xmd = glib.from_variant_dict(mmd.get_xmd())
br_nsvcs = []
for name, detail in xmd['mbs']['buildrequires'].items():
br_nsvcs.append(":".join([
name, detail["stream"], detail["version"], detail["context"]]))
for name, detail in xmd["mbs"]["buildrequires"].items():
br_nsvcs.append(
":".join([name, detail["stream"], detail["version"], detail["context"]]))
buildrequires_per_mmd_xmd.add(frozenset(br_nsvcs))
assert len(mmd.get_dependencies()) == 1
@@ -212,47 +212,45 @@ class TestUtilsModuleStreamExpansion:
assert buildrequires_per_mmd_xmd == expected_xmd
assert buildrequires_per_mmd_buildrequires == expected_buildrequires
@pytest.mark.parametrize('requires,build_requires,expected', [
({"gtk": ["1", "2"]}, {"platform": [], "gtk": ["1", "2"]},
set([
frozenset(['gtk:1']),
frozenset(['gtk:2']),
])),
({"gtk": ["1", "2"]}, {"platform": [], "gtk": ["1"]},
set([
frozenset(['gtk:1', 'gtk:2']),
])),
({"gtk": ["1"], "foo": ["1"]},
{"platform": [], "gtk": ["1"], "foo": ["1"]},
set([
frozenset(['foo:1', 'gtk:1']),
])),
({"gtk": ["-2"], "foo": ["-2"]},
{"platform": [], "gtk": ["-2"], "foo": ["-2"]},
set([
frozenset(['foo:1', 'gtk:1']),
])),
({"gtk": ["-1", "1"], "foo": ["-2", "1"]},
{"platform": [], "gtk": ["-1", "1"], "foo": ["-2", "1"]},
set([
frozenset(['foo:1', 'gtk:1']),
])),
({"gtk": [], "foo": []}, {"platform": [], "gtk": ["1"], "foo": ["1"]},
set([
frozenset([]),
])),
])
@pytest.mark.parametrize(
"requires,build_requires,expected",
[
(
{"gtk": ["1", "2"]},
{"platform": [], "gtk": ["1", "2"]},
set([frozenset(["gtk:1"]), frozenset(["gtk:2"])]),
),
(
{"gtk": ["1", "2"]},
{"platform": [], "gtk": ["1"]},
set([frozenset(["gtk:1", "gtk:2"])]),
),
(
{"gtk": ["1"], "foo": ["1"]},
{"platform": [], "gtk": ["1"], "foo": ["1"]},
set([frozenset(["foo:1", "gtk:1"])]),
),
(
{"gtk": ["-2"], "foo": ["-2"]},
{"platform": [], "gtk": ["-2"], "foo": ["-2"]},
set([frozenset(["foo:1", "gtk:1"])]),
),
(
{"gtk": ["-1", "1"], "foo": ["-2", "1"]},
{"platform": [], "gtk": ["-1", "1"], "foo": ["-2", "1"]},
set([frozenset(["foo:1", "gtk:1"])]),
),
(
{"gtk": [], "foo": []},
{"platform": [], "gtk": ["1"], "foo": ["1"]},
set([frozenset([])]),
),
],
)
def test_generate_expanded_mmds_requires(self, requires, build_requires, expected):
self._generate_default_modules()
module_build = make_module("app:1:0:c1", requires, build_requires)
mmds = module_build_service.utils.generate_expanded_mmds(
db.session, module_build.mmd())
mmds = module_build_service.utils.generate_expanded_mmds(db.session, module_build.mmd())
requires_per_mmd = set()
for mmd in mmds:
@@ -266,33 +264,83 @@ class TestUtilsModuleStreamExpansion:
assert requires_per_mmd == expected
@pytest.mark.parametrize('requires,build_requires,expected', [
({}, {"platform": [], "gtk": ["1", "2"]},
['platform:f29:0:c11', 'gtk:2:0:c4', 'gtk:2:0:c5',
'platform:f28:0:c10', 'gtk:1:0:c2', 'gtk:1:0:c3']),
({}, {"platform": [], "gtk": ["1"], "foo": ["1"]},
['platform:f28:0:c10', 'gtk:1:0:c2', 'gtk:1:0:c3',
'foo:1:0:c2', 'foo:1:0:c3', 'platform:f29:0:c11']),
({}, {"gtk": ["1"], "foo": ["1"], "platform": ["f28"]},
['platform:f28:0:c10', 'gtk:1:0:c2',
'foo:1:0:c2']),
([{}, {}], [{"platform": [], "gtk": ["1"], "foo": ["1"]},
{"platform": [], "gtk": ["2"], "foo": ["2"]}],
['foo:1:0:c2', 'foo:1:0:c3', 'foo:2:0:c4', 'foo:2:0:c5',
'platform:f28:0:c10', 'platform:f29:0:c11', 'gtk:1:0:c2',
'gtk:1:0:c3', 'gtk:2:0:c4', 'gtk:2:0:c5']),
({}, {"platform": [], "gtk": ["-2"], "foo": ["-2"]},
['foo:1:0:c2', 'foo:1:0:c3', 'platform:f29:0:c11',
'platform:f28:0:c10', 'gtk:1:0:c2', 'gtk:1:0:c3']),
({}, {"platform": [], "gtk": ["-1", "1"], "foo": ["-2", "1"]},
['foo:1:0:c2', 'foo:1:0:c3', 'platform:f29:0:c11',
'platform:f28:0:c10', 'gtk:1:0:c2', 'gtk:1:0:c3']),
])
@pytest.mark.parametrize(
"requires,build_requires,expected",
[
(
{},
{"platform": [], "gtk": ["1", "2"]},
[
"platform:f29:0:c11",
"gtk:2:0:c4",
"gtk:2:0:c5",
"platform:f28:0:c10",
"gtk:1:0:c2",
"gtk:1:0:c3",
],
),
(
{},
{"platform": [], "gtk": ["1"], "foo": ["1"]},
[
"platform:f28:0:c10",
"gtk:1:0:c2",
"gtk:1:0:c3",
"foo:1:0:c2",
"foo:1:0:c3",
"platform:f29:0:c11",
],
),
(
{},
{"gtk": ["1"], "foo": ["1"], "platform": ["f28"]},
["platform:f28:0:c10", "gtk:1:0:c2", "foo:1:0:c2"],
),
(
[{}, {}],
[
{"platform": [], "gtk": ["1"], "foo": ["1"]},
{"platform": [], "gtk": ["2"], "foo": ["2"]},
],
[
"foo:1:0:c2",
"foo:1:0:c3",
"foo:2:0:c4",
"foo:2:0:c5",
"platform:f28:0:c10",
"platform:f29:0:c11",
"gtk:1:0:c2",
"gtk:1:0:c3",
"gtk:2:0:c4",
"gtk:2:0:c5",
],
),
(
{},
{"platform": [], "gtk": ["-2"], "foo": ["-2"]},
[
"foo:1:0:c2",
"foo:1:0:c3",
"platform:f29:0:c11",
"platform:f28:0:c10",
"gtk:1:0:c2",
"gtk:1:0:c3",
],
),
(
{},
{"platform": [], "gtk": ["-1", "1"], "foo": ["-2", "1"]},
[
"foo:1:0:c2",
"foo:1:0:c3",
"platform:f29:0:c11",
"platform:f28:0:c10",
"gtk:1:0:c2",
"gtk:1:0:c3",
],
),
],
)
def test_get_required_modules_simple(self, requires, build_requires, expected):
module_build = make_module("app:1:0:c1", requires, build_requires)
self._generate_default_modules()
@@ -316,15 +364,28 @@ class TestUtilsModuleStreamExpansion:
make_module("lorem:1:1:c2", {"base": ["f29"]}, {}, base_module)
make_module("base:f29:0:c3", {"platform": ["f29"]}, {}, base_module)
@pytest.mark.parametrize('requires,build_requires,expected', [
({}, {"platform": [], "gtk": ["1"]},
['foo:1:1:c2', 'base:f29:0:c3', 'platform:f29:0:c11',
'bar:1:1:c2', 'gtk:1:1:c2', 'lorem:1:1:c2']),
({}, {"platform": [], "foo": ["1"]},
['foo:1:1:c2', 'base:f29:0:c3', 'platform:f29:0:c11',
'bar:1:1:c2', 'lorem:1:1:c2']),
])
@pytest.mark.parametrize(
"requires,build_requires,expected",
[
(
{},
{"platform": [], "gtk": ["1"]},
[
"foo:1:1:c2",
"base:f29:0:c3",
"platform:f29:0:c11",
"bar:1:1:c2",
"gtk:1:1:c2",
"lorem:1:1:c2",
],
),
(
{},
{"platform": [], "foo": ["1"]},
["foo:1:1:c2", "base:f29:0:c3", "platform:f29:0:c11", "bar:1:1:c2", "lorem:1:1:c2"],
),
],
)
def test_get_required_modules_recursion(self, requires, build_requires, expected):
module_build = make_module("app:1:0:c1", requires, build_requires)
self._generate_default_modules_recursion()
@@ -345,10 +406,16 @@ class TestUtilsModuleStreamExpansion:
make_module("gtk:1:2:c2", {"platform": ["f29"]}, {}, f290100)
make_module("gtk:1:3:c2", {"platform": ["f29"]}, {}, f290200)
@pytest.mark.parametrize('requires,build_requires,expected', [
({}, {"platform": ["f29.1.0"], "gtk": ["1"]},
['platform:f29.0.0:0:c11', 'gtk:1:0:c2', 'gtk:1:2:c2', 'platform:f29.1.0:0:c11']),
])
@pytest.mark.parametrize(
"requires,build_requires,expected",
[
(
{},
{"platform": ["f29.1.0"], "gtk": ["1"]},
["platform:f29.0.0:0:c11", "gtk:1:0:c2", "gtk:1:2:c2", "platform:f29.1.0:0:c11"],
)
],
)
def test_get_required_modules_stream_versions(self, requires, build_requires, expected):
module_build = make_module("app:1:0:c1", requires, build_requires)
self._generate_default_modules_modules_multiple_stream_versions()
@@ -359,32 +426,32 @@ class TestUtilsModuleStreamExpansion:
"""Ensure the correct results are returned without duplicates."""
init_data(data_size=1, multiple_stream_versions=True)
mmd = module_build_service.utils.load_mmd_file(
os.path.join(base_dir, 'staged_data', 'testmodule_v2.yaml'))
os.path.join(base_dir, "staged_data", "testmodule_v2.yaml"))
deps = mmd.get_dependencies()
brs = deps[0].get_buildrequires()
brs['platform'].set(['f29.1.0', 'f29.2.0'])
brs["platform"].set(["f29.1.0", "f29.2.0"])
deps[0].set_buildrequires(brs)
mmd.set_dependencies(deps)
mmds = module_build_service.utils.mse._get_base_module_mmds(mmd)
expected = set(['platform:f29.0.0', 'platform:f29.1.0', 'platform:f29.2.0'])
expected = set(["platform:f29.0.0", "platform:f29.1.0", "platform:f29.2.0"])
# Verify no duplicates were returned before doing set operations
assert len(mmds) == len(expected)
# Verify the expected ones were returned
actual = set()
for mmd_ in mmds:
actual.add('{}:{}'.format(mmd_.get_name(), mmd_.get_stream()))
actual.add("{}:{}".format(mmd_.get_name(), mmd_.get_stream()))
assert actual == expected
@pytest.mark.parametrize('virtual_streams', (None, ["f29"], ["lp29"]))
@pytest.mark.parametrize("virtual_streams", (None, ["f29"], ["lp29"]))
def test__get_base_module_mmds_virtual_streams(self, virtual_streams):
"""Ensure the correct results are returned without duplicates."""
init_data(data_size=1, multiple_stream_versions=True)
mmd = module_build_service.utils.load_mmd_file(
os.path.join(base_dir, 'staged_data', 'testmodule_v2.yaml'))
os.path.join(base_dir, "staged_data", "testmodule_v2.yaml"))
deps = mmd.get_dependencies()
brs = deps[0].get_buildrequires()
brs['platform'].set(['f29.2.0'])
brs["platform"].set(["f29.2.0"])
deps[0].set_buildrequires(brs)
mmd.set_dependencies(deps)
@@ -392,14 +459,14 @@ class TestUtilsModuleStreamExpansion:
mmds = module_build_service.utils.mse._get_base_module_mmds(mmd)
if virtual_streams == ["f29"]:
expected = set(['platform:f29.0.0', 'platform:f29.1.0', 'platform:f29.2.0',
'platform:lp29.1.1'])
expected = set(
["platform:f29.0.0", "platform:f29.1.0", "platform:f29.2.0", "platform:lp29.1.1"])
else:
expected = set(['platform:f29.0.0', 'platform:f29.1.0', 'platform:f29.2.0'])
expected = set(["platform:f29.0.0", "platform:f29.1.0", "platform:f29.2.0"])
# Verify no duplicates were returned before doing set operations
assert len(mmds) == len(expected)
# Verify the expected ones were returned
actual = set()
for mmd_ in mmds:
actual.add('{}:{}'.format(mmd_.get_name(), mmd_.get_stream()))
actual.add("{}:{}".format(mmd_.get_name(), mmd_.get_stream()))
assert actual == expected