Skip to content

Commit

Permalink
Use set literal
Browse files Browse the repository at this point in the history
* CLOUDBLD-1034

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
  • Loading branch information
tkdchen authored and MartinBasti committed Jun 2, 2020
1 parent 4c881f9 commit 35851d7
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 146 deletions.
12 changes: 7 additions & 5 deletions atomic_reactor/plugins/build_orchestrate_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def get_clusters(self, platform, retry_contexts, all_clusters):
possible_cluster_info[cluster] = cluster_info
except OsbsException:
ctx.try_again_later(self.find_cluster_retry_delay)
candidates -= set([c for c in candidates if retry_contexts[c.name].failed])
candidates -= {c for c in candidates if retry_contexts[c.name].failed}

ret = sorted(possible_cluster_info.values(), key=lambda c: c.cluster.priority)
ret = sorted(ret, key=lambda c: c.load)
Expand Down Expand Up @@ -542,9 +542,11 @@ def _apply_repositories(self, annotations):
def _make_labels(self):
labels = {}
koji_build_id = None
ids = set([build_info.build.get_koji_build_id()
for build_info in self.worker_builds
if build_info.build])
ids = {
build_info.build.get_koji_build_id()
for build_info in self.worker_builds
if build_info.build
}
self.log.debug('all koji-build-ids: %s', ids)
if ids:
koji_build_id = ids.pop()
Expand Down Expand Up @@ -827,7 +829,7 @@ def set_build_image(self):

# orchestrator platform is same as platform on which we want to built on,
# so we can use the same image
if manifest_list_platforms == set([orchestrator_platform]):
if manifest_list_platforms == {orchestrator_platform}:
self.build_image_digests[orchestrator_platform] = current_buildimage
return

Expand Down
10 changes: 8 additions & 2 deletions atomic_reactor/plugins/exit_sendmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ class SendMailPlugin(ExitPlugin):
AUTO_CANCELED = 'auto_canceled'
DEFAULT_SUBMITTER = 'Unknown'

allowed_states = set([MANUAL_SUCCESS, MANUAL_FAIL, MANUAL_CANCELED,
AUTO_SUCCESS, AUTO_FAIL, AUTO_CANCELED])
allowed_states = {
MANUAL_SUCCESS,
MANUAL_FAIL,
MANUAL_CANCELED,
AUTO_SUCCESS,
AUTO_FAIL,
AUTO_CANCELED
}

def __init__(self, tasker, workflow,
smtp_host=None, from_address=None,
Expand Down
2 changes: 1 addition & 1 deletion atomic_reactor/plugins/exit_verify_media_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run(self):
media_types = set()

if expect_list_only:
expected_media_types = set([MEDIA_TYPE_DOCKER_V2_MANIFEST_LIST])
expected_media_types = {MEDIA_TYPE_DOCKER_V2_MANIFEST_LIST}

media_in_registry[registry_name] = {'expected': expected_media_types}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_inject_parent_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ def run_plugin_with_args(self, workflow, plugin_args=None, reactor_config_map=Fa
self.assert_images_to_remove(workflow)

def assert_images_to_remove(self, workflow):
expected = set([str(workflow.builder.base_image)])
expected = {str(workflow.builder.base_image)}
actual = workflow.plugin_workspace[GarbageCollectionPlugin.key]['images_to_remove']
assert actual == expected
90 changes: 32 additions & 58 deletions tests/plugins/test_koji_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def check_components(components):
assert len(components) > 0
for component_rpm in components:
assert isinstance(component_rpm, dict)
assert set(component_rpm.keys()) == set([
assert set(component_rpm.keys()) == {
'type',
'name',
'version',
Expand All @@ -935,7 +935,7 @@ def check_components(components):
'arch',
'sigmd5',
'signature',
])
}

assert component_rpm['type'] == 'rpm'
assert component_rpm['name']
Expand All @@ -952,22 +952,19 @@ def check_components(components):
def validate_buildroot(self, buildroot, source=False):
assert isinstance(buildroot, dict)

assert set(buildroot.keys()) == set([
assert set(buildroot.keys()) == {
'id',
'host',
'content_generator',
'container',
'tools',
'components',
'extra',
])
}

host = buildroot['host']
assert isinstance(host, dict)
assert set(host.keys()) == set([
'os',
'arch',
])
assert set(host.keys()) == {'os', 'arch'}

assert host['os']
assert is_string_type(host['os'])
Expand All @@ -977,10 +974,7 @@ def validate_buildroot(self, buildroot, source=False):

content_generator = buildroot['content_generator']
assert isinstance(content_generator, dict)
assert set(content_generator.keys()) == set([
'name',
'version',
])
assert set(content_generator.keys()) == {'name', 'version'}

assert content_generator['name']
assert is_string_type(content_generator['name'])
Expand All @@ -989,10 +983,7 @@ def validate_buildroot(self, buildroot, source=False):

container = buildroot['container']
assert isinstance(container, dict)
assert set(container.keys()) == set([
'type',
'arch',
])
assert set(container.keys()) == {'type', 'arch'}

assert container['type'] == 'docker'
assert container['arch']
Expand All @@ -1002,10 +993,7 @@ def validate_buildroot(self, buildroot, source=False):
assert len(buildroot['tools']) > 0
for tool in buildroot['tools']:
assert isinstance(tool, dict)
assert set(tool.keys()) == set([
'name',
'version',
])
assert set(tool.keys()) == {'name', 'version'}

assert tool['name']
assert is_string_type(tool['name'])
Expand All @@ -1019,18 +1007,12 @@ def validate_buildroot(self, buildroot, source=False):

extra = buildroot['extra']
assert isinstance(extra, dict)
assert set(extra.keys()) == set([
'osbs',
])
assert set(extra.keys()) == {'osbs'}

assert 'osbs' in extra
osbs = extra['osbs']
assert isinstance(osbs, dict)
assert set(osbs.keys()) == set([
'build_id',
'builder_image_id',
'koji',
])
assert set(osbs.keys()) == {'build_id', 'builder_image_id', 'koji'}

assert is_string_type(osbs['build_id'])
assert is_string_type(osbs['builder_image_id'])
Expand All @@ -1054,18 +1036,18 @@ def validate_output(self, output, has_config, source=False):
assert is_string_type(output['checksum_type'])
assert 'type' in output
if output['type'] == 'log':
assert set(output.keys()) == set([
assert set(output.keys()) == {
'buildroot_id',
'filename',
'filesize',
'arch',
'checksum',
'checksum_type',
'type',
])
}
assert output['arch'] == 'noarch'
else:
assert set(output.keys()) == set([
assert set(output.keys()) == {
'buildroot_id',
'filename',
'filesize',
Expand All @@ -1075,7 +1057,7 @@ def validate_output(self, output, has_config, source=False):
'type',
'components',
'extra',
])
}
assert output['type'] == 'docker-image'
assert is_string_type(output['arch'])
assert output['arch'] != 'noarch'
Expand All @@ -1087,39 +1069,34 @@ def validate_output(self, output, has_config, source=False):

extra = output['extra']
assert isinstance(extra, dict)
assert set(extra.keys()) == set([
'image',
'docker',
])
assert set(extra.keys()) == {'image', 'docker'}

image = extra['image']
assert isinstance(image, dict)
assert set(image.keys()) == set([
'arch',
])
assert set(image.keys()) == {'arch'}

assert image['arch'] == output['arch'] # what else?

assert 'docker' in extra
docker = extra['docker']
assert isinstance(docker, dict)
if source:
expected_keys_set = set([
expected_keys_set = {
'tags',
'digests',
'layer_sizes',
'repositories',
'id',
])
}
else:
expected_keys_set = set([
expected_keys_set = {
'parent_id',
'id',
'repositories',
'tags',
'floating_tags',
'unique_tags',
])
}
if has_config:
expected_keys_set.add('config')

Expand Down Expand Up @@ -1381,12 +1358,12 @@ def test_koji_import_success(self, tmpdir, blocksize, os_env, has_config, is_aut

data = session.metadata

assert set(data.keys()) == set([
assert set(data.keys()) == {
'metadata_version',
'build',
'buildroots',
'output',
])
}

assert data['metadata_version'] in ['0', 0]

Expand All @@ -1400,7 +1377,7 @@ def test_koji_import_success(self, tmpdir, blocksize, os_env, has_config, is_aut
output_files = data['output']
assert isinstance(output_files, list)

expected_keys = set([
expected_keys = {
'name',
'version',
'release',
Expand All @@ -1409,7 +1386,7 @@ def test_koji_import_success(self, tmpdir, blocksize, os_env, has_config, is_aut
'end_time',
'extra', # optional but always supplied
'owner',
])
}

if reserved_build:
expected_keys.add('build_id')
Expand Down Expand Up @@ -1477,10 +1454,7 @@ def test_koji_import_success(self, tmpdir, blocksize, os_env, has_config, is_aut
build_id = runner.plugins_results[KojiImportPlugin.key]
assert build_id == "123"

assert set(session.uploaded_files.keys()) == set([
'orchestrator.log',
'x86_64.log',
])
assert set(session.uploaded_files.keys()) == {'orchestrator.log', 'x86_64.log'}
orchestrator_log = session.uploaded_files['orchestrator.log']
assert orchestrator_log == b'orchestrator\n'
x86_64_log = session.uploaded_files['x86_64.log']
Expand Down Expand Up @@ -1559,7 +1533,7 @@ def test_koji_import_pullspec(self, tmpdir, os_env, reactor_config_map):
reg = set(ImageName.parse(repo).registry
for repo in docker_output['extra']['docker']['repositories'])
assert len(reg) == 1
assert reg == set(['docker-registry.example.com:8888'])
assert reg == {'docker-registry.example.com:8888'}

def test_koji_import_without_build_info(self, tmpdir, os_env, reactor_config_map): # noqa

Expand Down Expand Up @@ -2316,12 +2290,12 @@ def test_koji_import_success_source(self, tmpdir, blocksize, os_env, has_config,

data = session.metadata

assert set(data.keys()) == set([
assert set(data.keys()) == {
'metadata_version',
'build',
'buildroots',
'output',
])
}

assert data['metadata_version'] in ['0', 0]

Expand All @@ -2335,7 +2309,7 @@ def test_koji_import_success_source(self, tmpdir, blocksize, os_env, has_config,
output_files = data['output']
assert isinstance(output_files, list)

expected_keys = set([
expected_keys = {
'name',
'version',
'release',
Expand All @@ -2344,7 +2318,7 @@ def test_koji_import_success_source(self, tmpdir, blocksize, os_env, has_config,
'end_time',
'extra', # optional but always supplied
'owner',
])
}

if reserved_build:
expected_keys.add('build_id')
Expand Down Expand Up @@ -2406,10 +2380,10 @@ def test_koji_import_success_source(self, tmpdir, blocksize, os_env, has_config,
assert build_id == "123"

uploaded_oic_file = 'oci-image-{}.{}.tar.xz'.format(expect_id, os.uname()[4])
assert set(session.uploaded_files.keys()) == set([
assert set(session.uploaded_files.keys()) == {
'orchestrator.log',
uploaded_oic_file,
])
}
orchestrator_log = session.uploaded_files['orchestrator.log']
assert orchestrator_log == b'orchestrator\n'

Expand Down
Loading

0 comments on commit 35851d7

Please sign in to comment.